veritas/legacy/test/schema.test.ts
caelum0x dd069746b9 chore(repo): flatten project to repository root
The whole project lived under a redundant veritas/ subdirectory with only a
stub README.md at the repo root, so GitHub showed caelum0x/veritas as
veritas/<everything>. Move all files up to the root and drop the stub.
History is preserved (git detects renames). Build unaffected: 0 type errors
across packages + all 31 apps, 49 tests passing from the new root.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-29 15:05:43 +03:00

44 lines
1.5 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import { VerificationRequestSchema } from '../src/verify/schema.js';
import { parseRequest } from '../src/croo/provider.js';
describe('VerificationRequestSchema', () => {
it('accepts a claims array', () => {
const r = VerificationRequestSchema.safeParse({ claims: ['a', 'b'] });
expect(r.success).toBe(true);
});
it('accepts a text block', () => {
const r = VerificationRequestSchema.safeParse({ text: 'some generated output' });
expect(r.success).toBe(true);
});
it('rejects an empty request', () => {
expect(VerificationRequestSchema.safeParse({}).success).toBe(false);
expect(VerificationRequestSchema.safeParse({ claims: [] }).success).toBe(false);
});
it('rejects unknown top-level keys (strict)', () => {
const r = VerificationRequestSchema.safeParse({ claims: ['a'], evil: true });
expect(r.success).toBe(false);
});
});
describe('parseRequest', () => {
it('parses valid JSON requirements', () => {
const out = parseRequest(JSON.stringify({ claims: ['a'] }));
expect(out.ok).toBe(true);
});
it('reports invalid JSON', () => {
const out = parseRequest('not json');
expect(out).toEqual({ ok: false, error: 'requirements must be valid JSON' });
});
it('reports schema violations with a readable message', () => {
const out = parseRequest(JSON.stringify({}));
expect(out.ok).toBe(false);
if (!out.ok) expect(out.error).toContain('invalid requirements');
});
});