mirror of
https://github.com/cozystack/cozystack.git
synced 2026-11-22 04:33:36 +09:00
test(console): add coverage for enrichSchemaWithEnums
backup-utils.ts had no test file despite sibling lib files establishing that convention. Covers the non-object passthrough, no-match case, a top-level enum attach, a nested one, and that the caller's path array is not mutated. Signed-off-by: Akanksha Trehun <akankshatrehun@gmail.com>
This commit is contained in:
1 parent
41ef4a6437
commit
34acabae49
1 file changed
+45
@@ -0,0 +1,45 @@
|
||||
import { describe, it, expect } from "vitest"
|
||||
import { enrichSchemaWithEnums } from "./backup-utils.ts"
|
||||
|
||||
describe("enrichSchemaWithEnums", () => {
|
||||
it("returns non-object schemas unchanged", () => {
|
||||
expect(enrichSchemaWithEnums(null, [], {})).toBeNull()
|
||||
expect(enrichSchemaWithEnums("string", [], {})).toBe("string")
|
||||
})
|
||||
|
||||
it("leaves the schema untouched when no path matches the enum map", () => {
|
||||
const schema = { type: "string" }
|
||||
expect(enrichSchemaWithEnums(schema, ["foo"], { bar: ["a", "b"] })).toEqual({
|
||||
type: "string",
|
||||
})
|
||||
})
|
||||
|
||||
it("attaches enum values at a top-level path", () => {
|
||||
const schema = { type: "string" }
|
||||
expect(enrichSchemaWithEnums(schema, ["mode"], { mode: ["a", "b"] })).toEqual({
|
||||
type: "string",
|
||||
enum: ["a", "b"],
|
||||
})
|
||||
})
|
||||
|
||||
it("attaches enum values at a nested path", () => {
|
||||
const schema = {
|
||||
type: "object",
|
||||
properties: { mode: { type: "string" } },
|
||||
}
|
||||
const result = enrichSchemaWithEnums(schema, ["spec"], {
|
||||
"spec.mode": ["a", "b"],
|
||||
})
|
||||
expect(result.properties.mode).toEqual({ type: "string", enum: ["a", "b"] })
|
||||
})
|
||||
|
||||
it("does not mutate the caller's path array", () => {
|
||||
const path = ["spec"]
|
||||
enrichSchemaWithEnums(
|
||||
{ properties: { mode: { type: "string" } } },
|
||||
path,
|
||||
{ "spec.mode": ["a", "b"] },
|
||||
)
|
||||
expect(path).toEqual(["spec"])
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user