From 0b7aac3b378d2eeb4eed6419cd5554f16a649864 Mon Sep 17 00:00:00 2001 From: Carolina Gonzalez Date: Tue, 20 Aug 2024 16:04:23 -0400 Subject: [PATCH] test: add unit tests --- .../util/__tests__/shouldAutoUpdate.test.ts | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 packages/sanity/src/_internal/cli/util/__tests__/shouldAutoUpdate.test.ts diff --git a/packages/sanity/src/_internal/cli/util/__tests__/shouldAutoUpdate.test.ts b/packages/sanity/src/_internal/cli/util/__tests__/shouldAutoUpdate.test.ts new file mode 100644 index 00000000000..5084ab44953 --- /dev/null +++ b/packages/sanity/src/_internal/cli/util/__tests__/shouldAutoUpdate.test.ts @@ -0,0 +1,40 @@ +import {describe, expect, it} from '@jest/globals' +import {type CliConfig} from '@sanity/cli' + +import {type BuildSanityStudioCommandFlags} from '../../actions/build/buildAction' +import {shouldAutoUpdate} from '../shouldAutoUpdate' + +describe('shouldAutoUpdate', () => { + it('should return true when flags["auto-updates"] is true', () => { + const flags: BuildSanityStudioCommandFlags = {'auto-updates': true} + expect(shouldAutoUpdate({flags})).toBe(true) + }) + + it('should return false when flags["auto-updates"] is false', () => { + const flags: BuildSanityStudioCommandFlags = {'auto-updates': false} + expect(shouldAutoUpdate({flags})).toBe(false) + }) + + it('should return true when cliConfig.autoUpdates is true and flags["auto-updates"] is not set', () => { + const flags: BuildSanityStudioCommandFlags = {} + const cliConfig: CliConfig = {autoUpdates: true} + expect(shouldAutoUpdate({flags, cliConfig})).toBe(true) + }) + + it('should return false when cliConfig.autoUpdates is false and flags["auto-updates"] is not set', () => { + const flags: BuildSanityStudioCommandFlags = {} + const cliConfig: CliConfig = {autoUpdates: false} + expect(shouldAutoUpdate({flags, cliConfig})).toBe(false) + }) + + it('should return false when both flags["auto-updates"] and cliConfig.autoUpdates are not set', () => { + const flags: BuildSanityStudioCommandFlags = {} + expect(shouldAutoUpdate({flags})).toBe(false) + }) + + it('should prioritize flags over cliConfig when both are set', () => { + const flags: BuildSanityStudioCommandFlags = {'auto-updates': false} + const cliConfig: CliConfig = {autoUpdates: true} + expect(shouldAutoUpdate({flags, cliConfig})).toBe(false) + }) +})