From a1eb343b7924253b090ea4ce2fbf8f31b327381e Mon Sep 17 00:00:00 2001 From: Ola Hungerford Date: Fri, 28 Feb 2025 06:26:04 -0700 Subject: [PATCH] Remove unused function plus tests --- .../src/utils/__tests__/schemaUtils.test.ts | 41 ------------------- client/src/utils/schemaUtils.ts | 38 ----------------- 2 files changed, 79 deletions(-) diff --git a/client/src/utils/__tests__/schemaUtils.test.ts b/client/src/utils/__tests__/schemaUtils.test.ts index 4eba268..20e7832 100644 --- a/client/src/utils/__tests__/schemaUtils.test.ts +++ b/client/src/utils/__tests__/schemaUtils.test.ts @@ -1,7 +1,6 @@ import { generateDefaultValue, formatFieldLabel, - validateValueAgainstSchema, } from "../schemaUtils"; import { JsonSchemaType } from "../../components/DynamicJsonForm"; @@ -111,43 +110,3 @@ describe("formatFieldLabel", () => { expect(formatFieldLabel("")).toBe(""); }); }); - -describe("validateValueAgainstSchema", () => { - test("validates string type", () => { - expect(validateValueAgainstSchema("test", { type: "string" })).toBe(true); - expect(validateValueAgainstSchema(123, { type: "string" })).toBe(false); - }); - - test("validates number type", () => { - expect(validateValueAgainstSchema(123, { type: "number" })).toBe(true); - expect(validateValueAgainstSchema("test", { type: "number" })).toBe(false); - }); - - test("validates integer type", () => { - expect(validateValueAgainstSchema(123, { type: "integer" })).toBe(true); - expect(validateValueAgainstSchema("test", { type: "integer" })).toBe(false); - }); - - test("validates boolean type", () => { - expect(validateValueAgainstSchema(true, { type: "boolean" })).toBe(true); - expect(validateValueAgainstSchema("test", { type: "boolean" })).toBe(false); - }); - - test("validates array type", () => { - expect(validateValueAgainstSchema([], { type: "array" })).toBe(true); - expect(validateValueAgainstSchema({}, { type: "array" })).toBe(false); - }); - - test("validates object type", () => { - expect(validateValueAgainstSchema({}, { type: "object" })).toBe(true); - expect(validateValueAgainstSchema([], { type: "object" })).toBe(false); - expect(validateValueAgainstSchema("test", { type: "object" })).toBe(false); - }); - - test("returns true for unknown types", () => { - expect( - // @ts-expect-error Testing with invalid type - validateValueAgainstSchema("anything", { type: "unknown" }), - ).toBe(true); - }); -}); diff --git a/client/src/utils/schemaUtils.ts b/client/src/utils/schemaUtils.ts index ab4c920..88a9b53 100644 --- a/client/src/utils/schemaUtils.ts +++ b/client/src/utils/schemaUtils.ts @@ -54,41 +54,3 @@ export function formatFieldLabel(key: string): string { .replace(/_/g, " ") // Replace underscores with spaces .replace(/^\w/, (c) => c.toUpperCase()); // Capitalize first letter } - -/** - * Validates if a value conforms to a JSON schema - * @param value The value to validate - * @param schema The JSON schema to validate against - * @returns True if valid, false otherwise - */ -export function validateValueAgainstSchema( - value: JsonValue, - schema: JsonSchemaType, -): boolean { - // Handle undefined values for non-required fields - if (value === undefined && !schema.required) { - return true; - } - - // Basic type validation - switch (schema.type) { - case "string": - return typeof value === "string"; - case "number": - return typeof value === "number"; - case "integer": - return typeof value === "number" && Number.isInteger(value); - case "boolean": - return typeof value === "boolean"; - case "array": - return Array.isArray(value); - case "object": - return ( - typeof value === "object" && value !== null && !Array.isArray(value) - ); - case "null": - return value === null; - default: - return true; - } -}