This commit is contained in:
2025-09-18 11:08:49 -06:00
parent 12305887f8
commit f27ef4f341
5 changed files with 76 additions and 2 deletions

View File

@@ -0,0 +1,42 @@
import { describe, it, expect } from 'vitest';
import Ajv, { type ErrorObject } from 'ajv';
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
// Implementation placeholder import; will fail until implemented per tasks T016, T018
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error - module not implemented yet
import { exportToJson } from '../../src/export';
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
const repoRoot = path.resolve(__dirname, '../../../../');
const schemaPath = path.join(
repoRoot,
'specs/001-glowtrack-a-mood/contracts/export.schema.json'
);
describe('Contract: export JSON schema (T009)', () => {
it('exportToJson() output should validate against export.schema.json', async () => {
const schemaJson = JSON.parse(fs.readFileSync(schemaPath, 'utf-8'));
const ajv = new Ajv({ allErrors: true, strict: true });
const validate = ajv.compile(schemaJson);
// Minimal call; actual implementation will read from DB/models
// For now, call without args or with undefined to get full export
const data = await exportToJson();
const valid = validate(data);
if (!valid) {
// Show helpful aggregated errors
const errors = (validate.errors || [])
.map((e: ErrorObject) => `${e.instancePath || '/'} ${e.message}`)
.join('\n');
// Intentionally using expect(...).toBe(true) so test fails until impl is ready
expect({ valid, errors }).toEqual({ valid: true, errors: '' });
}
expect(valid).toBe(true);
});
});