UNPKG

hey-api-builders

Version:

A custom plugin for @hey-api/openapi-ts that generates mock data builders with a lightweight custom runtime, Zod integration, or static mock generation.

84 lines 4.66 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const vitest_1 = require("vitest"); const schema_validators_1 = require("./schema-validators"); (0, vitest_1.describe)('Schema Validators', () => { (0, vitest_1.describe)('isEnum', () => { (0, vitest_1.it)('returns true for schema with enum property', () => { const schema = { enum: ['value1', 'value2', 'value3'], }; (0, vitest_1.expect)((0, schema_validators_1.isEnum)(schema)).toBe(true); }); (0, vitest_1.it)('returns true for schema with type enum', () => { const schema = { type: 'enum', items: [{ const: 'value1' }, { const: 'value2' }], }; (0, vitest_1.expect)((0, schema_validators_1.isEnum)(schema)).toBe(true); }); (0, vitest_1.it)('returns true for schema with items array of const values', () => { const schema = { items: [{ const: 'value1' }, { const: 'value2' }], }; (0, vitest_1.expect)((0, schema_validators_1.isEnum)(schema)).toBe(true); }); (0, vitest_1.it)('returns false for non-enum schema', () => { const schema = { type: 'string', }; (0, vitest_1.expect)((0, schema_validators_1.isEnum)(schema)).toBe(false); }); (0, vitest_1.it)('returns false for null or undefined', () => { (0, vitest_1.expect)((0, schema_validators_1.isEnum)(null)).toBe(false); (0, vitest_1.expect)((0, schema_validators_1.isEnum)(undefined)).toBe(false); }); }); (0, vitest_1.describe)('isJsonValue', () => { (0, vitest_1.it)('returns true for null', () => { (0, vitest_1.expect)((0, schema_validators_1.isJsonValue)(null)).toBe(true); }); (0, vitest_1.it)('returns true for primitives', () => { (0, vitest_1.expect)((0, schema_validators_1.isJsonValue)('string')).toBe(true); (0, vitest_1.expect)((0, schema_validators_1.isJsonValue)(123)).toBe(true); (0, vitest_1.expect)((0, schema_validators_1.isJsonValue)(true)).toBe(true); (0, vitest_1.expect)((0, schema_validators_1.isJsonValue)(false)).toBe(true); }); (0, vitest_1.it)('returns true for arrays of JSON values', () => { (0, vitest_1.expect)((0, schema_validators_1.isJsonValue)([1, 2, 3])).toBe(true); (0, vitest_1.expect)((0, schema_validators_1.isJsonValue)(['a', 'b', 'c'])).toBe(true); (0, vitest_1.expect)((0, schema_validators_1.isJsonValue)([true, false])).toBe(true); }); (0, vitest_1.it)('returns true for objects with JSON values', () => { (0, vitest_1.expect)((0, schema_validators_1.isJsonValue)({ a: 1, b: 'test' })).toBe(true); (0, vitest_1.expect)((0, schema_validators_1.isJsonValue)({ nested: { value: 123 } })).toBe(true); }); (0, vitest_1.it)('returns false for functions', () => { (0, vitest_1.expect)((0, schema_validators_1.isJsonValue)(() => { })).toBe(false); }); (0, vitest_1.it)('returns false for symbols', () => { (0, vitest_1.expect)((0, schema_validators_1.isJsonValue)(Symbol('test'))).toBe(false); }); (0, vitest_1.it)('returns false for undefined', () => { (0, vitest_1.expect)((0, schema_validators_1.isJsonValue)(undefined)).toBe(false); }); }); (0, vitest_1.describe)('isObjectType', () => { (0, vitest_1.it)('returns true for "object" type', () => { (0, vitest_1.expect)((0, schema_validators_1.isObjectType)('object')).toBe(true); }); (0, vitest_1.it)('returns true for array containing "object"', () => { (0, vitest_1.expect)((0, schema_validators_1.isObjectType)(['object', 'null'])).toBe(true); (0, vitest_1.expect)((0, schema_validators_1.isObjectType)(['string', 'object'])).toBe(true); }); (0, vitest_1.it)('returns false for other types', () => { (0, vitest_1.expect)((0, schema_validators_1.isObjectType)('string')).toBe(false); (0, vitest_1.expect)((0, schema_validators_1.isObjectType)('number')).toBe(false); (0, vitest_1.expect)((0, schema_validators_1.isObjectType)(['string', 'number'])).toBe(false); }); (0, vitest_1.it)('returns false for undefined', () => { (0, vitest_1.expect)((0, schema_validators_1.isObjectType)(undefined)).toBe(false); }); }); }); //# sourceMappingURL=schema-validators.test.js.map