Assessor_2.0/tests/features/datahub-open-readiness.test.ts

20 lines
1.4 KiB
TypeScript

import { describe, expect, it, vi } from 'vitest';
import { loadTimeslotOpenReadiness } from '../../src/features/project-import/datahub-open-readiness';
import { groupProjectImportFiles } from '../../src/features/project-import/datahub-import-groups';
const groups = groupProjectImportFiles([], [{ id: 'slot', projectId: 'client', name: 'Synthetic',
effectiveAt: '2026-09-06T00:00:00Z', createdAt: '2026-09-06T00:00:00Z', updatedAt: '2026-09-06T00:00:00Z' }], []);
describe('result-backed Open availability', () => {
it('keeps zero-result and unavailable timeslots disabled', async () => {
for (const read of [vi.fn().mockResolvedValue({ total: 0, facets: [] }), vi.fn().mockRejectedValue(new Error('offline'))]) {
expect((await loadTimeslotOpenReadiness(read, 'client', groups))[groups[0].id]).toEqual({ canOpen: false, hasPolicyResults: false });
}
});
it('enables a GPO-only timeslot only with persisted policy results', async () => {
const read = vi.fn().mockResolvedValue({ total: 3, facets: [{ id: 'sourceKind', values: [{ value: 'policy-observation', count: 3 }] }] });
expect((await loadTimeslotOpenReadiness(read, 'client', groups))[groups[0].id]).toEqual({ canOpen: true, hasPolicyResults: true });
expect(read).toHaveBeenCalledWith({ audience: 'internal-analysis', projectId: 'client', assessmentIds: ['slot'], sourceKind: ['scanner-finding', 'policy-observation'] });
});
});