pelagia-portal/App/tests/unit
Hardik d1af1e6b12
All checks were successful
PR checks / checks (pull_request) Successful in 49s
PR checks / integration (pull_request) Successful in 31s
fix(pdf): let PdfService reach the PO export route past auth middleware
"Email PO to vendor" (issue #14) relies on PdfService fetching
/api/po/<id>/export?...&svc=<token> WITHOUT a user session, authenticating
with a `svc` token that matches PDF_SERVICE_TOKEN. The route handler validates
that token, but the auth middleware runs first and its matcher doesn't exempt
the export route — so every unauthenticated fetch was redirected to /login
(307) and the svc bypass never executed. Net effect: the feature could never
render a real PDF on any deployed env, even with the service configured.

Fix: middleware now lets exactly `/api/po/<id>/export` through when its `svc`
query param matches `process.env.PDF_SERVICE_TOKEN` (the route handler still
re-validates it — defense in depth). Everything else stays auth-gated. The
match lives in a dependency-free, edge-safe, unit-tested helper
(lib/pdf-export-auth.ts); middleware already reads server env at runtime via
auth()/NEXTAUTH_SECRET, so reading PDF_SERVICE_TOKEN there is consistent.

Verified on a running build: correct svc + real PO -> 200, correct svc + bogus
PO -> 404 (handler ran), wrong/no svc -> 307 (still gated). 324 unit tests
green; tsc clean.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-24 14:55:40 +05:30
..
application-pipeline.test.ts feat(crewing): Phase 3b — recruitment pipeline (flagged) 2026-06-22 18:49:12 +05:30
appraisal-state-machine.test.ts feat(crewing): Phase 5b — appraisal (flagged) 2026-06-22 22:09:32 +05:30
attachments.test.ts fix(po): show all attachments grouped by type on PO details 2026-06-19 04:43:44 +05:30
cancel-po-controls.test.tsx fix(po): make cancel buttons red & visible (use defined danger tokens) 2026-06-21 12:59:20 +05:30
crew-pii.test.ts fix(crewing): mask Aadhaar/PAN document numbers server-side 2026-06-22 23:29:11 +05:30
image-size.test.ts fix(po): size XLSX export images by pixels (aspect preserved) 2026-06-21 13:27:15 +05:30
pagination.test.ts feat(history): paginate PO history with items-per-page control 2026-06-24 03:26:47 +05:30
pdf-export-auth.test.ts fix(pdf): let PdfService reach the PO export route past auth middleware 2026-06-24 14:55:40 +05:30
permissions-crewing.test.ts feat(crewing): admin crew management — direct placement, CRUD, strength config 2026-06-22 21:23:31 +05:30
permissions.test.ts feat(po): submitter view-all of POs + History + export (feature-flagged) 2026-06-22 04:57:11 +05:30
po-export-layout.test.ts fix(po): keep the export stamp clear of the signature (no overlap) 2026-06-21 15:35:09 +05:30
po-import-parser.test.ts test+ci: green the test baseline and make type-check + unit tests hard gates 2026-06-19 13:03:54 +05:30
po-line-items-editor.test.tsx feat(po): add week, month, year to line-item unit options 2026-06-21 00:32:39 +05:30
po-state-machine.test.ts chore: restructure repo — flatten App/pelagia-portal to App, rename Prototype→Wireframe and Spec→Design 2026-05-18 23:18:58 +05:30
po-status-badge.test.tsx chore: restructure repo — flatten App/pelagia-portal to App, rename Prototype→Wireframe and Spec→Design 2026-05-18 23:18:58 +05:30
reports.test.ts feat(reports): weekly granularity, custom compare, line-item allocation 2026-06-24 11:25:05 +05:30
requisition-state-machine.test.ts feat(crewing): Phase 2 — requisitions + relief requests (flagged) 2026-06-22 18:22:59 +05:30
sidebar.test.tsx feat(reports): Purchasing spend analytics (Cost Centres + Accounting Codes) 2026-06-24 07:52:23 +05:30
storage-keys.test.ts feat(po): per-company logo, stamp & brand bar on exported POs 2026-06-21 01:17:23 +05:30
unsaved-changes-guard.test.tsx feat(po): prompt to save as draft when leaving with unsaved changes 2026-06-24 06:37:33 +05:30
utils.test.ts feat(dashboard): compact INR formatting for Total Approved Spend card 2026-06-21 02:02:41 +05:30
validations.test.ts feat(po): allow submitter to set an optional PO date 2026-06-16 13:06:12 +05:30
vendor-form-captcha.test.tsx fix(vendors): move GSTIN CAPTCHA into a popup 2026-06-24 06:37:29 +05:30
vendor-select.test.tsx feat(po): make vendor field a searchable combobox 2026-06-24 05:16:57 +05:30
vendors-table.test.tsx refactor(routes): move /inventory/{items,vendors} → /catalogue/{items,vendors} 2026-06-24 05:04:29 +05:30