Skip to content

#535 - Align plan version history and PDF dates - #537

Merged
brijesh-amin merged 5 commits into
devfrom
fix/535-align-plan-version-pdf-dates
Aug 7, 2026
Merged

#535 - Align plan version history and PDF dates#537
brijesh-amin merged 5 commits into
devfrom
fix/535-align-plan-version-pdf-dates

Conversation

@brijesh-amin

Copy link
Copy Markdown
Collaborator

Summary

  • format plan version dates consistently in the America/Vancouver timezone
  • protect the development database from test runs by requiring POSTGRESQL_DATABASE_TEST
  • add UTC-boundary regression coverage

Verification

  • API focused tests pass
  • API build passes
  • API lint passes with existing warnings

Depends on #536. After #536 merges, retarget this PR to dev.

Closes #535

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 + timezone plugins and add UTC-midnight regression coverage.
  • Require POSTGRESQL_DATABASE_TEST in test environments and adjust test runner NODE_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.

Comment thread __tests__/unit/PDFHelper.planVersionDates.spec.js Outdated
Comment thread src/config/index.ts
Comment thread package.json Outdated
Comment on lines +53 to +54
"test": "cross-env NODE_ENV=test vitest run --coverage",
"test:watch": "cross-env NODE_ENV=test vitest",
Comment thread src/libs/db2/migrate.ts Outdated
Comment on lines 72 to 82
process.env.POSTGRESQL_DATABASE_TEST
? process.env.POSTGRESQL_DATABASE_TEST
: process.env.POSTGRESQL_DATABASE,
user: process.env.POSTGRESQL_USER,
Base automatically changed from fix/534-restore-version-foreign-keys to dev August 7, 2026 19:50
@brijesh-amin

Copy link
Copy Markdown
Collaborator Author

Addressed the migration safety finding in commit 90ffcbf:

  • createDb() now hard-fails in test and unit_test when POSTGRESQL_DATABASE_TEST is missing.
  • Test coverage verifies both environments fail before creating a database connection.

The isolated test passes and the API build passes. No database-backed migration or test command was run.

@brijesh-amin

Copy link
Copy Markdown
Collaborator Author

Addressed the package/test-convention finding in commit 4963450:

  • Restored NODE_ENV=unit_test in the test and test:watch scripts, matching the existing unit-test convention and config test expectations.
  • Updated the config fixture to set POSTGRESQL_DATABASE_TEST.
  • The fail-closed guards remain active for both test and unit_test.

Verification: 19 targeted unit tests passed, API build passed, and formatting/lint checks passed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

  • formatPlanVersionDates returns 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.ts directly, but most tests import source modules using the runtime .js specifier (e.g. __tests__/unit/bcgov-shim.spec.js, __tests__/db2/migration.spec.js). Importing the .js path here helps ensure the test exercises the same module resolution path as production.
    const { formatPlanVersionDates } = await import('../../src/router/helpers/PDFHelper.ts');

@brijesh-amin
brijesh-amin merged commit 78a9e50 into dev Aug 7, 2026
4 of 5 checks passed
@brijesh-amin
brijesh-amin deleted the fix/535-align-plan-version-pdf-dates branch August 7, 2026 20:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Align plan version history and PDF dates across timezones

2 participants