|
| 1 | +import { describe, expect, it } from 'vite-plus/test'; |
| 2 | + |
| 3 | +import { |
| 4 | + BuildMetadataSchema, |
| 5 | + FrontmatterSchema, |
| 6 | + PackageMetadataSchema, |
| 7 | + parseBuildMetadata, |
| 8 | + parseFrontmatter, |
| 9 | + parsePackageMetadata, |
| 10 | +} from '../core/data-schemas.js'; |
| 11 | +import { parseFrontmatter as parseMarkdownFrontmatter } from '../core/markdown.js'; |
| 12 | + |
| 13 | +const validBuildMetadata = { |
| 14 | + version: '1.2.3', |
| 15 | + organization: 'NextDNS Skills', |
| 16 | + date: '2026-08-18', |
| 17 | + abstract: 'Build metadata for the generated skills package.', |
| 18 | + references: [{ title: 'NextDNS API', url: 'https://api.nextdns.io' }], |
| 19 | +}; |
| 20 | + |
| 21 | +describe('data schemas', () => { |
| 22 | + describe('FrontmatterSchema', () => { |
| 23 | + it('accepts scalar and string-array frontmatter values', () => { |
| 24 | + const frontmatter = parseFrontmatter({ |
| 25 | + title: 'Authentication', |
| 26 | + tags: ['api', 'security'], |
| 27 | + }); |
| 28 | + |
| 29 | + expect(frontmatter).toEqual({ title: 'Authentication', tags: ['api', 'security'] }); |
| 30 | + }); |
| 31 | + |
| 32 | + it('rejects non-string frontmatter values', () => { |
| 33 | + expect(() => parseFrontmatter({ tags: ['api', 1] })).toThrow(); |
| 34 | + expect(() => parseFrontmatter({ count: 2 })).toThrow(); |
| 35 | + }); |
| 36 | + |
| 37 | + it('validates frontmatter produced by the markdown parser', () => { |
| 38 | + const frontmatter = parseMarkdownFrontmatter(`--- |
| 39 | +title: 'Authentication' |
| 40 | +tags: |
| 41 | + - api |
| 42 | + - security |
| 43 | +--- |
| 44 | +
|
| 45 | +# Authentication |
| 46 | +`); |
| 47 | + |
| 48 | + expect(FrontmatterSchema).toBeDefined(); |
| 49 | + expect(frontmatter).toEqual({ title: 'Authentication', tags: ['api', 'security'] }); |
| 50 | + }); |
| 51 | + }); |
| 52 | + |
| 53 | + describe('BuildMetadataSchema', () => { |
| 54 | + it('accepts complete build metadata with references', () => { |
| 55 | + const metadata = parseBuildMetadata(validBuildMetadata); |
| 56 | + |
| 57 | + expect(metadata.version).toBe('1.2.3'); |
| 58 | + expect(metadata.references?.[0]?.url).toBe('https://api.nextdns.io'); |
| 59 | + }); |
| 60 | + |
| 61 | + it('accepts build metadata without optional references', () => { |
| 62 | + const { references, ...withoutReferences } = validBuildMetadata; |
| 63 | + |
| 64 | + expect(references).toBeDefined(); |
| 65 | + expect(parseBuildMetadata(withoutReferences).organization).toBe('NextDNS Skills'); |
| 66 | + }); |
| 67 | + |
| 68 | + it('rejects missing required metadata fields', () => { |
| 69 | + const { abstract, ...withoutAbstract } = validBuildMetadata; |
| 70 | + |
| 71 | + expect(abstract).toBeDefined(); |
| 72 | + expect(() => parseBuildMetadata(withoutAbstract)).toThrow(); |
| 73 | + }); |
| 74 | + |
| 75 | + it('rejects malformed metadata fields and references', () => { |
| 76 | + expect(() => parseBuildMetadata({ ...validBuildMetadata, version: 1 })).toThrow(); |
| 77 | + expect(() => |
| 78 | + parseBuildMetadata({ |
| 79 | + ...validBuildMetadata, |
| 80 | + references: [{ title: 'NextDNS API', url: '' }], |
| 81 | + }) |
| 82 | + ).toThrow(); |
| 83 | + }); |
| 84 | + }); |
| 85 | + |
| 86 | + describe('PackageMetadataSchema', () => { |
| 87 | + it('accepts package metadata with or without a version', () => { |
| 88 | + expect(parsePackageMetadata({ version: '0.4.0' }).version).toBe('0.4.0'); |
| 89 | + expect(parsePackageMetadata({})).toEqual({}); |
| 90 | + }); |
| 91 | + |
| 92 | + it('rejects malformed package metadata', () => { |
| 93 | + expect(() => parsePackageMetadata(null)).toThrow(); |
| 94 | + expect(() => parsePackageMetadata({ version: 4 })).toThrow(); |
| 95 | + }); |
| 96 | + |
| 97 | + it('exposes the schema for runtime composition', () => { |
| 98 | + expect(BuildMetadataSchema).toBeDefined(); |
| 99 | + expect(PackageMetadataSchema).toBeDefined(); |
| 100 | + }); |
| 101 | + }); |
| 102 | +}); |
0 commit comments