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

FileLinesSubject
src/compliance.test.ts59src/compliance.tshash_contact, initComplianceTables, logRoPA
src/integration.test.ts197src/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 both OptOut_Hashes and RoPA_Log table names
  • logRoPA(pool, 'users', 'INSERT', '42', 'test entry') issues exactly one INSERT INTO RoPA_Log with parameters ['users', 'INSERT', '42', 'test entry']

Note

The “same input → same hash” test (lines 36–43) carries a comment warning that HASH_SALT is captured at import time, so changing process.env.HASH_SALT mid-test is a no-op. The beforeEach delete process.env.HASH_SALT is therefore cosmetic.

src/integration.test.ts

Smoke tests for the broader compliance + queue surface using a mock pg pool.

  • createTables(pool) emits SQL containing OptOut_Hashes, RoPA_Log, companies, Article14_Notifications
  • isOptedOut(pool, contact):
    • returns false when SELECT returns 0 rows
    • returns true when SELECT returns a row
    • parameterises the query with hash_contact(contact) (verifies hashing happens before the lookup) — see Opt-Out Hashes
  • Update_Job handler logic: a private mirror of the worker handler issues exactly two queries — INSERT INTO companies ... ON CONFLICT ... DO UPDATE followed by INSERT INTO RoPA_Log with operation UPSERT and the org_nr — see Pipeline
  • Enrich_Job opted-out path: when isOptedOut returns true, no INSERT INTO companies is issued
  • Queue exports smoke: src/queues/index.ts exports scrapeQueue, enrichQueue, updateQueue, closeQueues. Relies on BullMQ Queue being lazy (no Redis dial on construction) — if that changes, this test will start hitting Redis
  • schema.sql static check: reads schema.sql via Bun.file and asserts it contains OptOut_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.ts or src/workers/updateWorker.ts drifts from the SQL in runUpdateHandler (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_EMAIL returned when contact has no email
  • alreadySent: true when 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 Gapssrc/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.

See also