import { describe, it, expect } from 'vitest'; import Ajv, { type ErrorObject } from 'ajv'; import addFormats from 'ajv-formats'; import fs from 'node:fs'; import path from 'node:path'; import { fileURLToPath } from 'node:url'; 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 }); addFormats(ajv); 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); }); });