Two files, two scopes. Don’t conflate them.

Files

FileLinesSubject
src/lib/validation.test.ts180Generic input validators in src/lib/validation.ts
src/validationEngine.test.ts32The four-layer enrichment validation in src/validationEngine.ts

src/lib/validation.test.ts

Pure unit tests for HTTP-input validation primitives:

  • isValidUUID / UUID_REGEX: accepts canonical and uppercase UUIDs; rejects too-short, invalid chars, empty
  • isValidEmail / EMAIL_REGEX: accepts plus-tag and multi-dot TLDs; rejects bare @example.com, user@, empty
  • isValidOrgNr: rejects too-short and non-numeric
    • Note: '556000-0000' is rejected (expect(isValidOrgNr('556000-0000')).toBe(false)) because it fails the Luhn check — the test comment acknowledges that “actual valid Swedish org numbers would pass” but does not provide one
  • validatePassword: requires length ≥ 8, lowercase, uppercase, digit, and rejects common patterns (Password123 flagged as common)
  • sanitizeString: trims, removes null bytes, caps at 10000 chars
  • validateSearchQuery: rejects single chars and empty/null; truncates to 100 chars
  • validatePagination: defaults limit=20, offset=0; caps at the third argument (default 100); accepts string inputs; clamps negative values to limit≥1, offset≥0
  • isValidURL: accepts http/https; rejects ftp://, plain text, empty

src/validationEngine.test.ts

Two thin tests against validateCompany() from src/validationEngine.ts:

  • Returns an object with boolean isHeltValiderad and a defined confidenceScore
  • isHeltValiderad === (confidenceScore >= 0.7)

Warning

This file is a smoke test, not a real test of validation behaviour. It does not exercise individual validation layers (src/validation/layers/registryLayer.ts, newsLayer.ts), does not assert specific score values, and depends on the mock layers (src/mocks/) producing semi-deterministic output. Compare with the depth of Lead Scoring — which is largely untested at the engine level.

Gaps

  • src/validation/layers/registryLayer.ts and newsLayer.ts have no direct tests
  • src/api/validation.ts (the request-shape validators distinct from src/lib/validation.ts) is partially exercised through tests/api/structure.test.ts and the API CRUD tests, but has no dedicated unit suite

See also

Test Strategy, Lead Scoring, Test Coverage Gaps.

See also