#535 - Align plan version history and PDF dates - #537
Conversation
There was a problem hiding this comment.
Pull request overview
This PR addresses issue #535 by making plan version submission/approval dates render consistently in PDFs using an explicit America/Vancouver timezone, and adds safeguards to reduce the risk of tests or scripts accidentally targeting the development database.
Changes:
- Add BC/Pacific timezone formatting for plan version dates before PDF generation.
- Extend the dayjs shim with
utc+timezoneplugins and add UTC-midnight regression coverage. - Require
POSTGRESQL_DATABASE_TESTin test environments and adjust test runnerNODE_ENV.
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
src/router/helpers/PDFHelper.ts |
Adds helpers to format plan version dates into YYYY-MM-DD in America/Vancouver. |
src/router/controllers_v1/PDFGeneration.ts |
Applies plan version date formatting before calling CDOGS. |
src/libs/db2/migrate.ts |
Adjusts test DB selection logic (but still needs a hard-fail to fully protect dev DB). |
src/libs/bcgov-shim.ts |
Enables dayjs UTC + timezone support used by the PDF formatting helpers. |
src/config/index.ts |
Enforces POSTGRESQL_DATABASE_TEST for `NODE_ENV=test |
package.json |
Changes test scripts to use NODE_ENV=test. |
__tests__/unit/PDFHelper.planVersionDates.spec.js |
Adds UTC-midnight boundary test for the new formatting logic (recommended to mock DB-coupled imports). |
__tests__/unit/dayjs.spec.js |
Adds coverage that dayjs timezone formatting works as expected. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "test": "cross-env NODE_ENV=test vitest run --coverage", | ||
| "test:watch": "cross-env NODE_ENV=test vitest", |
| process.env.POSTGRESQL_DATABASE_TEST | ||
| ? process.env.POSTGRESQL_DATABASE_TEST | ||
| : process.env.POSTGRESQL_DATABASE, | ||
| user: process.env.POSTGRESQL_USER, |
|
Addressed the migration safety finding in commit 90ffcbf:
The isolated test passes and the API build passes. No database-backed migration or test command was run. |
|
Addressed the package/test-convention finding in commit 4963450:
Verification: 19 targeted unit tests passed, API build passed, and formatting/lint checks passed. |
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
4963450 to
27aa089
Compare
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.
Suppressed comments (2)
src/router/controllers_v1/PDFGeneration.ts:8
formatPlanVersionDatesreturns a (possibly modified) plan object, but the current call ignores the return value. This makes it unclear to future readers whether the helper is intended to be pure or mutative, and increases the chance of accidentally using the unformatted object later in this function.
export const generatePlanPDF = async (plan) => {
formatPlanVersionDates(plan);
const templateFile = Agreement.isGrazingSchedule(plan.agreement)
tests/unit/PDFHelper.planVersionDates.spec.js:7
- This test imports
PDFHelper.tsdirectly, but most tests import source modules using the runtime.jsspecifier (e.g.__tests__/unit/bcgov-shim.spec.js,__tests__/db2/migration.spec.js). Importing the.jspath here helps ensure the test exercises the same module resolution path as production.
const { formatPlanVersionDates } = await import('../../src/router/helpers/PDFHelper.ts');
Summary
Verification
Depends on #536. After #536 merges, retarget this PR to
dev.Closes #535