From 34acabae49a222755cbdae6533e871b91d7a8e4c Mon Sep 17 00:00:00 2001 From: Akanksha Trehun Date: Wed, 9 Sep 2026 16:49:17 +0530 Subject: [PATCH] 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 --- .../apps/console/src/lib/backup-utils.test.ts | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 packages/system/dashboard/images/console/apps/console/src/lib/backup-utils.test.ts diff --git a/packages/system/dashboard/images/console/apps/console/src/lib/backup-utils.test.ts b/packages/system/dashboard/images/console/apps/console/src/lib/backup-utils.test.ts new file mode 100644 index 000000000..1ed6ce573 --- /dev/null +++ b/packages/system/dashboard/images/console/apps/console/src/lib/backup-utils.test.ts @@ -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"]) + }) +})