Skip to content

Commit

Permalink
test: add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cngonzalez committed Aug 20, 2024
1 parent 26dd321 commit 0b7aac3
Showing 1 changed file with 40 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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)
})
})

0 comments on commit 0b7aac3

Please sign in to comment.