45 lines
1.6 KiB
TypeScript
45 lines
1.6 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { defaultReview } from '../../src/domain/review';
|
|
import { makeSheet } from '../../src/importers/sheet-factory';
|
|
import { createSnapshot, parseSnapshot } from '../../src/persistence/snapshot-store';
|
|
|
|
const dataset = {
|
|
fileName: 'synthetic.csv',
|
|
fileSize: 42,
|
|
lastModified: 1234,
|
|
format: 'CSV',
|
|
rawText: 'Name;Severity\nA;High',
|
|
sheets: [makeSheet('CSV', [['Name', 'Severity'], ['A', 'High']], 'Name;Severity\nA;High', 'synthetic.csv')],
|
|
profileId: 'generic',
|
|
scanTool: 'Tabular Data'
|
|
};
|
|
|
|
describe('snapshot store', () => {
|
|
it('round-trips a version 2 snapshot', () => {
|
|
const snapshot = createSnapshot(dataset, { finding1: { ...defaultReview(), include: true } }, {
|
|
now: () => new Date('2026-07-17T10:00:00.000Z')
|
|
});
|
|
expect(snapshot.createdAt).toBe('2026-07-17T10:00:00.000Z');
|
|
expect(parseSnapshot(JSON.stringify(snapshot))).toEqual(snapshot);
|
|
});
|
|
|
|
it('imports legacy exxTableReader snapshots and normalizes the app name', () => {
|
|
const snapshot = createSnapshot(dataset, {});
|
|
expect(parseSnapshot(JSON.stringify({ ...snapshot, app: 'exxTableReader' }))?.app).toBe('ASSESSOR');
|
|
});
|
|
|
|
it('rejects unsupported snapshot versions', () => {
|
|
const snapshot = createSnapshot(dataset, {});
|
|
expect(parseSnapshot(JSON.stringify({ ...snapshot, version: 1 }))).toBeNull();
|
|
});
|
|
|
|
it('rejects structurally incomplete snapshot data', () => {
|
|
expect(parseSnapshot(JSON.stringify({
|
|
app: 'ASSESSOR',
|
|
kind: 'snapshot',
|
|
version: 2,
|
|
dataset: { fileName: 'broken', profileId: 'generic', sheets: [] }
|
|
}))).toBeNull();
|
|
});
|
|
});
|