UNPKG

altair-graphql-core

Version:

Several of the core logic for altair graphql client

36 lines 1.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const vitest_1 = require("vitest"); const v4_1 = require("zod/v4"); const schema_1 = require("./schema"); (0, vitest_1.describe)('stripDefaults', () => { (0, vitest_1.it)('should strip default values from a Zod object schema', () => { const schema = v4_1.z.object({ a: v4_1.z.string().default('defaultA'), b: v4_1.z.number(), c: v4_1.z.boolean().default(true), }); const strippedSchema = (0, schema_1.stripDefaults)(schema); const parsed = schema.parse({ b: 42 }); (0, vitest_1.expect)(parsed).toEqual({ a: 'defaultA', b: 42, c: true }); (0, vitest_1.expect)(() => strippedSchema.parse({ b: 42 })).toThrow(); }); (0, vitest_1.it)('should handle schemas without defaults', () => { const schema = v4_1.z.object({ x: v4_1.z.string(), y: v4_1.z.number(), }); const strippedSchema = (0, schema_1.stripDefaults)(schema); const parsed = strippedSchema.parse({ x: 'test', y: 10 }); (0, vitest_1.expect)(parsed).toEqual({ x: 'test', y: 10 }); }); (0, vitest_1.it)('should throw an error for invalid data', () => { const schema = v4_1.z.object({ a: v4_1.z.string().default('defaultA'), b: v4_1.z.number(), }); const strippedSchema = (0, schema_1.stripDefaults)(schema); (0, vitest_1.expect)(() => strippedSchema.parse({ a: 'test' })).toThrow(); }); }); //# sourceMappingURL=schema.spec.js.map