Assessor_2.0/tests/features/results-browser-work-record...

32 lines
2.0 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import type { ImportedDataset } from '../../src/domain/dataset';
import type { UnifiedResultProjection } from '../../src/domain/unified-result';
import { workRecordIdsForResult } from '../../src/features/results-browser/work-record-lookup';
function dataset(records: Array<{ id: string; findingOccurrenceId?: string }>): ImportedDataset {
return { sheets: [{ analysis: { records } }] } as unknown as ImportedDataset;
}
describe('Result DB original lookup in Work', () => {
it('finds the Work record of a scanner row by its finding occurrence', () => {
const row = { sourceKind: 'scanner-finding', sourceResultId: 'occurrence-7' } as UnifiedResultProjection;
expect(workRecordIdsForResult(dataset([{ id: 'record-a', findingOccurrenceId: 'occurrence-7' },
{ id: 'record-b', findingOccurrenceId: 'occurrence-8' }]), row)).toEqual(['record-a']);
});
it('finds the Work setting of a GPO comparison by scope and technical setting identity', () => {
const key = (scope: string, identity: string) =>
`gpo-work-setting:${encodeURIComponent(JSON.stringify(['project', 'aggregation', scope, identity]))}`;
const row = { sourceKind: 'policy-evaluation', policyScope: 'machine', sourceRuleId: 'registry:machine:software\\x:y' } as unknown as UnifiedResultProjection;
expect(workRecordIdsForResult(dataset([{ id: key('machine', 'registry:machine:software\\x:y') },
{ id: key('user', 'registry:machine:software\\x:y') }, { id: 'gpo-work-setting:%7Bbroken' }]), row))
.toEqual([key('machine', 'registry:machine:software\\x:y')]);
});
it('returns nothing without a loaded Work dataset or for environment rows', () => {
expect(workRecordIdsForResult(null, { sourceKind: 'scanner-finding', sourceResultId: 'x' } as UnifiedResultProjection)).toEqual([]);
expect(workRecordIdsForResult(dataset([{ id: 'r', findingOccurrenceId: 'x' }]),
{ sourceKind: 'environment-observation', sourceResultId: 'x' } as UnifiedResultProjection)).toEqual([]);
});
});