74 lines
3.0 KiB
TypeScript
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');
|
|
});
|
|
});
|