follow-up-sla-fixture.test.ts1.3 KBView on GitHub /**
* Guards the authored Follow-up SLA report: every ```dashboard fence in
* apps/mail/docs/follow-up-sla.md must be valid JSON and pass the dashboard
* spec schema. Catches authoring typos (trailing commas, unknown block types,
* missing required fields) before the doc is seeded.
*/
import { readFileSync } from 'node:fs';
import { join } from 'node:path';
import { parseDashboardSpec } from '@/modules/dashboards/types/dashboard';
const DOC_PATH = join(__dirname, '../../../docs/follow-up-sla.md');
const FENCE_RE = /```dashboard\s*\n([\s\S]*?)\n```/g;
function extractFences(md: string): string[] {
const fences: string[] = [];
let match: RegExpExecArray | null;
while ((match = FENCE_RE.exec(md)) !== null) fences.push(match[1]);
return fences;
}
describe('follow-up-sla.md dashboard fences', () => {
const md = readFileSync(DOC_PATH, 'utf8');
const fences = extractFences(md);
it('contains every authored section', () => {
// 6 dashboard fences: standard, why, per-rep (with inline per-rep
// timelines), breakers, distribution, breaching.
expect(fences.length).toBe(6);
});
it.each(fences.map((f, i) => [i, f] as const))(
'fence %i is valid JSON and a valid dashboard spec',
(_i: number, fence: string) => {
const parsed = JSON.parse(fence);
expect(parseDashboardSpec(parsed)).not.toBeNull();
},
);
});