Tests for hashing, RoPA logging, opt-out detection, and Article 14 notification. Spread across three files; all use a hand-rolled mock pg pool (makeMockPool) — no live DB.
Files
| File | Lines | Subject |
|---|---|---|
src/compliance.test.ts | 59 | src/compliance.ts — hash_contact, initComplianceTables, logRoPA |
src/integration.test.ts | 197 | src/db/schema.ts, src/scraping/middleware.ts, queues, schema.sql |
src/enrichmentEngine.v7.test.ts (Article 14 section, lines 254–339) | (subset) | src/lib/article14Notification.ts |
src/compliance.test.ts
hash_contact('test@example.com')returns 64-char lowercase hex (HMAC-SHA256)- Same input always returns the same hash within a test run
initComplianceTables(pool)issues queries that include bothOptOut_HashesandRoPA_Logtable nameslogRoPA(pool, 'users', 'INSERT', '42', 'test entry')issues exactly oneINSERT INTO RoPA_Logwith parameters['users', 'INSERT', '42', 'test entry']
Note
The “same input → same hash” test (lines 36–43) carries a comment warning that
HASH_SALTis captured at import time, so changingprocess.env.HASH_SALTmid-test is a no-op. ThebeforeEachdelete process.env.HASH_SALTis therefore cosmetic.
src/integration.test.ts
Smoke tests for the broader compliance + queue surface using a mock pg pool.
createTables(pool)emits SQL containingOptOut_Hashes,RoPA_Log,companies,Article14_NotificationsisOptedOut(pool, contact):- returns
falsewhen SELECT returns 0 rows - returns
truewhen SELECT returns a row - parameterises the query with
hash_contact(contact)(verifies hashing happens before the lookup) — see Opt-Out Hashes
- returns
Update_Job handler logic: a private mirror of the worker handler issues exactly two queries —INSERT INTO companies ... ON CONFLICT ... DO UPDATEfollowed byINSERT INTO RoPA_Logwith operationUPSERTand the org_nr — see PipelineEnrich_Job opted-out path: whenisOptedOutreturnstrue, noINSERT INTO companiesis issuedQueue exportssmoke:src/queues/index.tsexportsscrapeQueue,enrichQueue,updateQueue,closeQueues. Relies on BullMQQueuebeing lazy (no Redis dial on construction) — if that changes, this test will start hitting Redisschema.sqlstatic check: readsschema.sqlviaBun.fileand asserts it containsOptOut_Hashes,RoPA_Log,companies
Warning
The Update_Job test is a parallel implementation of the worker, not a test of the actual worker code. If
src/queues/workers.tsorsrc/workers/updateWorker.tsdrifts from the SQL inrunUpdateHandler(lines 107–132), this test will still pass while the real worker breaks.
Article 14 section (in src/enrichmentEngine.v7.test.ts)
Tests notifyDataSubject and notifyDataSubjects from src/lib/article14Notification.ts — see Article 14.
NO_EMAILreturned when contact has no emailalreadySent: truewhen SELECT against the notifications table returns a row- New notification: at least one INSERT issued to record the attempt
- RoPA_Log entry written on every notification attempt
- Bulk: contacts without emails are dropped silently; contacts with emails are processed
Gaps
See Test Coverage Gaps — src/compliance/reklamsparre.ts (the SCB advertising-block check) has no test, despite being the P0 gap flagged in Pipeline and Known Issues. No test exists for the actual src/queues/workers.ts or any file under src/workers/.
See also
Test Strategy, Opt-Out Hashes, RoPA Log, Article 14, Reklamspärr, Test Coverage Gaps.