test: add unit tests for template rendering logic #80

Merged
pook merged 1 commit from feature/template-rendering-tests into main 2026-04-09 06:13:39 -04:00
Owner

Summary

  • Adds 80 unit tests covering template registry, clause structure validation, placeholder correctness, input validation, clause selection logic, and disclaimer wrapping
  • Adds MissingFieldError + validateQuestionnaire() so missing required fields (businessName, businessType, jurisdiction) throw clear errors
  • Exports buildBusinessInfo, selectClauses, expandJurisdictions for testability
  • Adds npm test script to root package.json

Test plan

  • Tests for each document type (privacy, ToS, cookie) template structure
  • Tests for valid input producing interpolated values with no raw placeholders
  • Tests for missing required fields producing MissingFieldError
  • Tests for jurisdiction-specific clause selection (US/CCPA, EU/GDPR, CA/PIPEDA)
  • All 80 tests pass via npm test

Closes #38 (partial — template rendering subset)

🤖 Generated with Claude Code

## Summary - Adds 80 unit tests covering template registry, clause structure validation, placeholder correctness, input validation, clause selection logic, and disclaimer wrapping - Adds `MissingFieldError` + `validateQuestionnaire()` so missing required fields (businessName, businessType, jurisdiction) throw clear errors - Exports `buildBusinessInfo`, `selectClauses`, `expandJurisdictions` for testability - Adds `npm test` script to root package.json ## Test plan - [x] Tests for each document type (privacy, ToS, cookie) template structure - [x] Tests for valid input producing interpolated values with no raw placeholders - [x] Tests for missing required fields producing MissingFieldError - [x] Tests for jurisdiction-specific clause selection (US/CCPA, EU/GDPR, CA/PIPEDA) - [x] All 80 tests pass via `npm test` Closes #38 (partial — template rendering subset) 🤖 Generated with [Claude Code](https://claude.com/claude-code)
test: add unit tests for template rendering and clause selection logic
Some checks failed
agent-worker/pr-tests Tests failed (exit 1)
51b9adfb92
Adds 80 unit tests covering template registry, clause structure validation,
placeholder correctness, input validation, clause selection, and disclaimer
wrapping. Also adds input validation (MissingFieldError) for required
questionnaire fields and exports helper functions for testability.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Author
Owner

Tests Failed

Commit: 51b9adfb | Command: bun test | Duration: 0.5s

Failure details
bun test v1.3.11 (af24e281)


packages/api/tests/e2e/export.test.ts:
============================================================
Bun v1.3.11 (af24e281) Linux x64 (baseline)
Linux Kernel v6.12.74 | glibc v2.41
Args: "bun" "test"
Features: fetch jsc no_avx2 no_avx tsconfig(3) tsconfig_paths(3) 
Builtins: "bun:test" 
Elapsed: 7ms | User: 8ms | Sys: 4ms
RSS: 1.11GB | Peak: 39.31MB | Commit: 1.11GB | Faults: 2 | Machine: 8.33GB

CPU lacks AVX support. Please consider upgrading to a newer CPU.
panic(main thread): Segmentation fault at address 0x0
oh no: Bun has crashed. This indicates a bug in Bun, not your code.

To send a redacted crash report to Bun's team,
please file a GitHub issue using the link below:

 https://bun.report/1.3.11/Bt1af24e28gGggogigD4ktn4E+++P2rg8sDghu+2D0tr92D_ijr1iEijr1iEijr1iEijr1iEm80tiEsi4jrF482jqEmlmgtDm+tgtDqxvgtDmxt4oDwggqpDms+5jD4wxlqEA2AA
## ❌ Tests Failed **Commit:** `51b9adfb` | **Command:** `bun test` | **Duration:** 0.5s <details><summary>Failure details</summary> ``` bun test v1.3.11 (af24e281) packages/api/tests/e2e/export.test.ts: ============================================================ Bun v1.3.11 (af24e281) Linux x64 (baseline) Linux Kernel v6.12.74 | glibc v2.41 Args: "bun" "test" Features: fetch jsc no_avx2 no_avx tsconfig(3) tsconfig_paths(3) Builtins: "bun:test" Elapsed: 7ms | User: 8ms | Sys: 4ms RSS: 1.11GB | Peak: 39.31MB | Commit: 1.11GB | Faults: 2 | Machine: 8.33GB CPU lacks AVX support. Please consider upgrading to a newer CPU. panic(main thread): Segmentation fault at address 0x0 oh no: Bun has crashed. This indicates a bug in Bun, not your code. To send a redacted crash report to Bun's team, please file a GitHub issue using the link below: https://bun.report/1.3.11/Bt1af24e28gGggogigD4ktn4E+++P2rg8sDghu+2D0tr92D_ijr1iEijr1iEijr1iEijr1iEm80tiEsi4jrF482jqEmlmgtDm+tgtDqxvgtDmxt4oDwggqpDms+5jD4wxlqEA2AA ``` </details>
Author
Owner

Review notes (agent-bot):

  • Issue link: Closes #38 is present. ✓
  • 80 tests across template rendering logic is solid coverage.
  • Note: PR says "Closes #38 (partial)" — if this only covers a subset of #38, consider whether the issue should stay open until full coverage lands. If template rendering was the whole scope, drop the "partial" qualifier so the issue auto-closes on merge.
  • The document-generator.ts changes export internals for testability — acceptable, but watch for leaking implementation details into the public API surface.
**Review notes (agent-bot):** - Issue link: Closes #38 is present. ✓ - 80 tests across template rendering logic is solid coverage. - Note: PR says "Closes #38 (partial)" — if this only covers a subset of #38, consider whether the issue should stay open until full coverage lands. If template rendering was the whole scope, drop the "partial" qualifier so the issue auto-closes on merge. - The `document-generator.ts` changes export internals for testability — acceptable, but watch for leaking implementation details into the public API surface.
pook merged commit d41b0d4465 into main 2026-04-09 06:13:35 -04:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
pook/compliancebot!80
No description provided.