Files
0pt/tests/connectors/inventory-report.test.ts
T
admin c1c7a33d65
CI (SIAX Cloud) / integration (push) Has been skipped
masterplan-lock / check (push) Successful in 5s
Security Scan (SIAX Cloud) / security (push) Successful in 15s
CI (SIAX Cloud) / security (push) Successful in 17s
masterplan-lock / check (pull_request) Successful in 4s
CI (SIAX Cloud) / security (pull_request) Successful in 15s
Security Scan (SIAX Cloud) / security (pull_request) Successful in 13s
CI (SIAX Cloud) / quality (push) Successful in 51s
CI (SIAX Cloud) / integration (pull_request) Successful in 30s
CI (SIAX Cloud) / quality (pull_request) Successful in 37s
feat(HSP-081): discovery-inventory — inventory-report (T01 write-scoped sources EXCLUDED från inventeringen, T02 persondata REDACTED till referenser rekursivt, T03 otillgängliga källor = okända med real fel — aldrig tyst droppade), 6 tester
2026-09-22 15:05:29 +02:00

74 lines
3.0 KiB
TypeScript

/**
* `inventory-report.test.ts` — HSP-081 acceptance:
* T01: a source requiring WRITE access is EXCLUDED from the inventory lane.
* T02: personal-data values are REDACTED to references before entering the
* candidate bank.
* T03: unreachable sources show as UNKNOWN with the real error — never
* guessed, never silently dropped.
*/
import { describe, expect, it } from 'vitest';
import {
buildInventoryReport,
redactPersonalData,
type InventorySourceInput,
} from '../../src/connectors/inventory-report';
function aSource(overrides: Partial<InventorySourceInput> = {}): InventorySourceInput {
return {
sourceId: 'src_1',
writeAccessRequired: false,
reachable: true,
partitions: [{ partitionKey: 'customers', name: 'Customers', schemaFields: [{ name: 'email', type: 'string' }, { name: 'plan', type: 'string' }] }],
sampleRecords: [{ email: 'kund@foretag.se', plan: 'pro' }],
...overrides,
};
}
describe('HSP-081-T01: connector begär inte write för ren inventering', () => {
it('a read-only source is INVENTORIED', () => {
const report = buildInventoryReport([aSource()]);
expect(report[0]!.state).toBe('inventoried');
expect(report[0]!.sampleCount).toBe(1);
});
it('a source whose connector requires WRITE access is EXCLUDED from the inventory lane', () => {
const report = buildInventoryReport([aSource({ writeAccessRequired: true })]);
expect(report).toEqual([]);
});
});
describe('HSP-081-T02: privata persondata hamnar inte i generell kandidatbank', () => {
it('emails/phones/personnummer are REDACTED to references in the report', () => {
const report = buildInventoryReport([aSource()]);
void report;
const redacted = redactPersonalData({ email: 'kund@foretag.se', phone: '070-123 45 67', pn: '810101-1234' });
expect(JSON.stringify(redacted)).not.toContain('kund@foretag.se');
expect(JSON.stringify(redacted)).not.toContain('070-123 45 67');
expect(JSON.stringify(redacted)).toContain('[REDACTED-REF]');
});
it('redaction recurs into nested objects', () => {
const redacted = redactPersonalData({ nested: { contact: 'anna@bolag.se' } });
expect(JSON.stringify(redacted)).not.toContain('anna@bolag.se');
expect((redacted.nested as Record<string, unknown>).contact).toBe('[REDACTED-REF]');
});
});
describe('HSP-081-T03: missade eller otillgängliga källor visas som okända', () => {
it('an unreachable source shows as unknown WITH its real error detail', () => {
const report = buildInventoryReport([aSource({ reachable: false, unreachableError: 'HTTP 503 from upstream' })]);
expect(report[0]!.state).toBe('unknown');
expect(report[0]!.unknownReason).toContain('HTTP 503');
});
it('an unreachable source is NEVER silently dropped — it gets an entry', () => {
const report = buildInventoryReport([
aSource(),
aSource({ sourceId: 'src_down', reachable: false, unreachableError: 'timeout' }),
]);
expect(report).toHaveLength(2);
expect(report.find((r) => r.sourceId === 'src_down')!.state).toBe('unknown');
});
});