100 lines
2.8 KiB
TypeScript
100 lines
2.8 KiB
TypeScript
import { describe, expect, test } from "bun:test"
|
|
import { ZodError } from "zod/v4"
|
|
import { BackgroundTaskConfigSchema } from "./background-task"
|
|
|
|
describe("BackgroundTaskConfigSchema", () => {
|
|
describe("maxDepth", () => {
|
|
describe("#given valid maxDepth (3)", () => {
|
|
test("#when parsed #then returns correct value", () => {
|
|
const result = BackgroundTaskConfigSchema.parse({ maxDepth: 3 })
|
|
|
|
expect(result.maxDepth).toBe(3)
|
|
})
|
|
})
|
|
|
|
describe("#given maxDepth below minimum (0)", () => {
|
|
test("#when parsed #then throws ZodError", () => {
|
|
let thrownError: unknown
|
|
|
|
try {
|
|
BackgroundTaskConfigSchema.parse({ maxDepth: 0 })
|
|
} catch (error) {
|
|
thrownError = error
|
|
}
|
|
|
|
expect(thrownError).toBeInstanceOf(ZodError)
|
|
})
|
|
})
|
|
})
|
|
|
|
describe("maxDescendants", () => {
|
|
describe("#given valid maxDescendants (50)", () => {
|
|
test("#when parsed #then returns correct value", () => {
|
|
const result = BackgroundTaskConfigSchema.parse({ maxDescendants: 50 })
|
|
|
|
expect(result.maxDescendants).toBe(50)
|
|
})
|
|
})
|
|
|
|
describe("#given maxDescendants below minimum (0)", () => {
|
|
test("#when parsed #then throws ZodError", () => {
|
|
let thrownError: unknown
|
|
|
|
try {
|
|
BackgroundTaskConfigSchema.parse({ maxDescendants: 0 })
|
|
} catch (error) {
|
|
thrownError = error
|
|
}
|
|
|
|
expect(thrownError).toBeInstanceOf(ZodError)
|
|
})
|
|
})
|
|
})
|
|
|
|
describe("syncPollTimeoutMs", () => {
|
|
describe("#given valid syncPollTimeoutMs (120000)", () => {
|
|
test("#when parsed #then returns correct value", () => {
|
|
const result = BackgroundTaskConfigSchema.parse({ syncPollTimeoutMs: 120000 })
|
|
|
|
expect(result.syncPollTimeoutMs).toBe(120000)
|
|
})
|
|
})
|
|
|
|
describe("#given syncPollTimeoutMs below minimum (59999)", () => {
|
|
test("#when parsed #then throws ZodError", () => {
|
|
let thrownError: unknown
|
|
|
|
try {
|
|
BackgroundTaskConfigSchema.parse({ syncPollTimeoutMs: 59999 })
|
|
} catch (error) {
|
|
thrownError = error
|
|
}
|
|
|
|
expect(thrownError).toBeInstanceOf(ZodError)
|
|
})
|
|
})
|
|
|
|
describe("#given syncPollTimeoutMs not provided", () => {
|
|
test("#when parsed #then field is undefined", () => {
|
|
const result = BackgroundTaskConfigSchema.parse({})
|
|
|
|
expect(result.syncPollTimeoutMs).toBeUndefined()
|
|
})
|
|
})
|
|
|
|
describe('#given syncPollTimeoutMs is non-number ("abc")', () => {
|
|
test("#when parsed #then throws ZodError", () => {
|
|
let thrownError: unknown
|
|
|
|
try {
|
|
BackgroundTaskConfigSchema.parse({ syncPollTimeoutMs: "abc" })
|
|
} catch (error) {
|
|
thrownError = error
|
|
}
|
|
|
|
expect(thrownError).toBeInstanceOf(ZodError)
|
|
})
|
|
})
|
|
})
|
|
})
|