Skip to content

Add location data, Provenance to Lists and fix bug - #140

Merged
junaidiqbalmoj merged 4 commits into
masterfrom
add-location-data-other-fixes
Nov 27, 2025
Merged

Add location data, Provenance to Lists and fix bug#140
junaidiqbalmoj merged 4 commits into
masterfrom
add-location-data-other-fixes

Conversation

@junaidiqbalmoj

@junaidiqbalmoj junaidiqbalmoj commented Nov 27, 2025

Copy link
Copy Markdown
Contributor

Change description

Add location data, Provenance to Lists and fix bug

Summary by CodeRabbit

  • Chores

    • Development startup now runs a new database seeding script; dev:up updated to invoke it.
    • CI test workflow now generates the Prisma client before cache setup.
    • Added a package resolution for node-forge.
    • Data records now include provenance metadata.
  • Style

    • Adjusted CSV import style (no runtime behavior change).
  • Tests

    • Added comprehensive tests covering seeding logic, gating scenarios, data operations, and logging.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai

coderabbitai Bot commented Nov 27, 2025

Copy link
Copy Markdown
Contributor

Walkthrough

Added a provenance field to mock list types, gated location seeding with environment and table-empty checks and added tests, changed papaparse import style, added a db seeding script and updated dev startup scripts, and added a CI step to generate the Prisma client.

Changes

Cohort / File(s) Summary
Mock List Types Configuration
libs/list-types/common/src/mock-list-types.ts
Added provenance: string to the ListType interface and set provenance: "CFT_IDAM" on all mock entries.
Location Seeding Logic
libs/location/src/seed-data.ts
Added internal shouldSeed() to skip seeding in production/CI or when key tables are non-empty; seedLocationData() logs a pre-check and returns early when appropriate.
Location Seeding Tests
libs/location/src/seed-data.test.ts
Added comprehensive tests that mock Prisma, environment variables, and location-data inputs to validate shouldSeed branches and full seeding flow (upserts, deletes, createMany, and log ordering).
Import Style Update
libs/system-admin-pages/src/reference-data-upload/services/download-service.ts
Switched papaparse import from a namespace import to a default import; runtime usage remains Papa.unparse.
NPM Scripts & Resolutions
package.json
Added script "db:seed": "tsx libs/location/src/seed-data.ts"; updated "dev:up" to run yarn db:seed after migrations; added resolutions entry node-forge: "1.3.2".
CI Workflow
.github/workflows/test.yml
Added a "Generate Prisma client" step that runs yarn db:generate before Turbo cache setup in the Test Changed Packages job.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

  • Inspect propagation/consumption of ListType.provenance across code that serializes or validates list types.
  • Verify shouldSeed() environment checks and table-empty logic align with CI/prod expectations.
  • Review new tests for realistic Prisma mocks and correct assertions of DB calls and log ordering.
  • Confirm papaparse default import works in build/runtime environments.
  • Validate the new db:seed script and updated dev:up ordering for local/dev flows and CI side-effects.

Possibly related PRs

Suggested reviewers

  • KianKwa

Poem

🐇 I hopped through mocks and left a trail,
"CFT_IDAM" stitched into every tale.
I sniffed the soil, then chose to wait,
Only seed where fields are slate.
Small script, bright hop — ready to deploy with a cheerful shake!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
Title check ❓ Inconclusive The title 'Add location data, Provenance to Lists and fix bug' is vague about the specific bug being fixed and reads like a loose list of changes rather than a focused description of the primary change. Consider rephrasing to be more specific about the main objective (e.g., 'Add location seeding and provenance field to list types' or similar) and clarify the nature of the bug fix.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch add-location-data-other-fixes

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ccba81c and 41e8bf8.

📒 Files selected for processing (1)
  • .github/workflows/test.yml (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: SonarQube Analysis
  • GitHub Check: E2E Tests
🔇 Additional comments (1)
.github/workflows/test.yml (1)

94-95: The yarn db:generate script is properly defined and the step placement is correct.

Verification confirms:

  • Script exists in package.json (line 38): "db:generate": "yarn workspace @hmcts/postgres run generate"
  • Step placement in test.yml (lines 94-95) is optimal: after dependencies install but before Turbo cache setup, ensuring the Prisma client exists before tests run
  • Intentional that only the test job includes this step; the lint job doesn't require a generated Prisma client
  • Consistent with other workflows (e2e.yml, jira-ticket-sync.yml) which also include the same step

No issues found with the implementation.


Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 0

🧹 Nitpick comments (2)
libs/list-types/common/src/mock-list-types.ts (1)

1-75: Provenance addition looks good; consider tightening type / avoiding duplicated literals

Making provenance required on ListType and populating it for all mock entries is consistent and will surface missing data at compile time. Two optional improvements to consider:

  • If the set of provenances is small and known, introduce a type Provenance = "CFT_IDAM" | ...; and use provenance: Provenance to prevent typos and make future additions explicit.
  • Alternatively (or additionally), extract "CFT_IDAM" to a const PROVENANCE_CFT_IDAM = "CFT_IDAM" as const; and reuse it across entries to avoid repeated string literals.

Also, please double‑check other ListType constructions in the codebase still compile now that provenance is mandatory.

libs/location/src/seed-data.ts (1)

4-39: Seeding guard is sensible; confirm “all tables empty” invariant and consider module ordering

The shouldSeed() guard is a good safety net: it prevents seeding in production/CI and avoids re-running against non-empty tables. A couple of points to double‑check:

  • The logic only seeds when all of region, jurisdiction, and location tables are empty. In any partially-populated state (e.g. regions/jurisdictions present but locations missing), seeding will be skipped entirely. If your migrations/flows guarantee “all-or-nothing” population, this is fine; otherwise you may want a strategy for repairing partially-seeded environments.
  • Skipping in CI via process.env.CI === "true" assumes your CI sets that exact string; worth confirming for all CI providers you use.

From a style perspective, project guidelines say exported functions should come before internal helpers. You could move shouldSeed below export async function seedLocationData() (function declarations are hoisted, so behavior won’t change) to match that convention.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between ed072f9 and 264c81a.

📒 Files selected for processing (4)
  • libs/list-types/common/src/mock-list-types.ts (2 hunks)
  • libs/location/src/seed-data.ts (1 hunks)
  • libs/system-admin-pages/src/reference-data-upload/services/download-service.ts (1 hunks)
  • package.json (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx}: TypeScript variables must use camelCase (e.g., userId, caseDetails, documentId). Booleans should use is/has/can prefix (e.g., isActive, hasAccess, canEdit).
Classes and Interfaces must use PascalCase (e.g., UserService, CaseRepository). Do NOT use I prefix for interfaces (use UserRepository not IUserRepository).
Constants must use SCREAMING_SNAKE_CASE (e.g., MAX_FILE_SIZE, DEFAULT_TIMEOUT).
Module ordering: consts outside function scope at top, exported functions next, other functions ordered by usage, interfaces and types at bottom.
TypeScript must use strict mode enabled with no any without justification. Use workspace aliases (@hmcts/*) for imports.
Always add .js extension to relative imports (e.g., import { foo } from "./bar.js"). This is required for ESM with Node.js "nodenext" module resolution, even when importing TypeScript files.
All input endpoints must validate inputs. Use parameterized database queries with Prisma. Never include sensitive data in logs.
Only export functions that are intended to be used outside the module. Don't export functions solely for testing purposes.
Only add comments when they are meaningful. Explain why something is done, not what is done.
Favor functional style with simple functional approaches. Don't use a class unless you have shared state.
Data should be immutable by default. Use const and avoid mutations to ensure predictable state.
Functions should have no side effects. Avoid modifying external state or relying on mutable data.
Use Express version 5.x with proper async/await error handling in middleware and route handlers.

Files:

  • libs/list-types/common/src/mock-list-types.ts
  • libs/location/src/seed-data.ts
  • libs/system-admin-pages/src/reference-data-upload/services/download-service.ts
**/*.ts

📄 CodeRabbit inference engine (CLAUDE.md)

API endpoints must use plural for collections (/api/cases, /api/users), singular for specific resources (/api/case/:id), and singular for creation (POST /api/case).

Files:

  • libs/list-types/common/src/mock-list-types.ts
  • libs/location/src/seed-data.ts
  • libs/system-admin-pages/src/reference-data-upload/services/download-service.ts
**/package.json

📄 CodeRabbit inference engine (CLAUDE.md)

**/package.json: Package names must use @hmcts scope (e.g., @hmcts/auth, @hmcts/case-management).
All package.json files must use "type": "module" to enforce ES modules. Never use CommonJS require() or module.exports. Use import/export only.
Express version 5.x only must be used ("express": "5.1.0"). Pin all dependencies to specific versions except peer dependencies.
Build scripts must include build:nunjucks if the module contains Nunjucks templates in the pages/ directory to copy .njk files to dist.

Files:

  • package.json
🧠 Learnings (1)
📚 Learning: 2025-11-25T06:40:24.099Z
Learnt from: CR
Repo: hmcts/cath-service PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T06:40:24.099Z
Learning: Always run commands from the root directory (e.g., `yarn test`, `yarn dev`).

Applied to files:

  • package.json
🧬 Code graph analysis (1)
libs/location/src/seed-data.ts (1)
libs/location/src/index.ts (1)
  • seedLocationData (21-21)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: E2E Tests
🔇 Additional comments (2)
libs/system-admin-pages/src/reference-data-upload/services/download-service.ts (1)

2-2: Confirm papaparse default import matches your TS/bundler config

Switching from a namespace import to import Papa from "papaparse"; is fine as long as your toolchain treats papaparse as having a default export (typically via esModuleInterop/allowSyntheticDefaultImports). Please verify that builds/tests still pass across all environments (Node, bundler, tests), as misconfigured interop would surface as a runtime undefined for Papa.

package.json (1)

33-37: Seeding script integration into dev:up looks appropriate; verify behavior across envs

Hooking db:seed into dev:up after db:migrate:dev makes local setup simpler, and the new shouldSeed() guard keeps this safe to run repeatedly and in CI/production contexts. This also respects the preference to run commands from the repo root (yarn db:seed). Based on learnings, this matches the intended workflow.

Please just confirm:

  • yarn db:seed runs successfully via tsx on your local environment.
  • CI does not rely on dev:up for DB lifecycle, or, if it does, that CI is set so seeding is skipped as expected.

@coderabbitai coderabbitai Bot 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.

Actionable comments posted: 0

🧹 Nitpick comments (1)
libs/location/src/seed-data.test.ts (1)

91-95: Add vi.resetModules() for reliable environment variable testing.

Tests use dynamic imports with varying process.env values, but vi.clearAllMocks() only resets mock call history, not the module cache. If the imported module caches any env-dependent state at load time, subsequent tests could receive stale behavior.

  beforeEach(() => {
    originalEnv = { ...process.env };
    consoleLogSpy = vi.spyOn(console, "log").mockImplementation(() => {});
+   vi.resetModules();
    vi.clearAllMocks();
  });
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 556d3cf and ccba81c.

📒 Files selected for processing (1)
  • libs/location/src/seed-data.test.ts (1 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

**/*.{ts,tsx}: TypeScript variables must use camelCase (e.g., userId, caseDetails, documentId). Booleans should use is/has/can prefix (e.g., isActive, hasAccess, canEdit).
Classes and Interfaces must use PascalCase (e.g., UserService, CaseRepository). Do NOT use I prefix for interfaces (use UserRepository not IUserRepository).
Constants must use SCREAMING_SNAKE_CASE (e.g., MAX_FILE_SIZE, DEFAULT_TIMEOUT).
Module ordering: consts outside function scope at top, exported functions next, other functions ordered by usage, interfaces and types at bottom.
TypeScript must use strict mode enabled with no any without justification. Use workspace aliases (@hmcts/*) for imports.
Always add .js extension to relative imports (e.g., import { foo } from "./bar.js"). This is required for ESM with Node.js "nodenext" module resolution, even when importing TypeScript files.
All input endpoints must validate inputs. Use parameterized database queries with Prisma. Never include sensitive data in logs.
Only export functions that are intended to be used outside the module. Don't export functions solely for testing purposes.
Only add comments when they are meaningful. Explain why something is done, not what is done.
Favor functional style with simple functional approaches. Don't use a class unless you have shared state.
Data should be immutable by default. Use const and avoid mutations to ensure predictable state.
Functions should have no side effects. Avoid modifying external state or relying on mutable data.
Use Express version 5.x with proper async/await error handling in middleware and route handlers.

Files:

  • libs/location/src/seed-data.test.ts
**/*.ts

📄 CodeRabbit inference engine (CLAUDE.md)

API endpoints must use plural for collections (/api/cases, /api/users), singular for specific resources (/api/case/:id), and singular for creation (POST /api/case).

Files:

  • libs/location/src/seed-data.test.ts
**/*.test.ts

📄 CodeRabbit inference engine (CLAUDE.md)

All packages must use "test": "vitest run" as the test script. Unit and integration tests must be co-located with source code as *.test.ts files.

Files:

  • libs/location/src/seed-data.test.ts
🧠 Learnings (1)
📚 Learning: 2025-11-25T06:40:24.099Z
Learnt from: CR
Repo: hmcts/cath-service PR: 0
File: CLAUDE.md:0-0
Timestamp: 2025-11-25T06:40:24.099Z
Learning: Applies to **/*.test.ts : All packages must use `"test": "vitest run"` as the test script. Unit and integration tests must be co-located with source code as `*.test.ts` files.

Applied to files:

  • libs/location/src/seed-data.test.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: E2E Tests
🔇 Additional comments (2)
libs/location/src/seed-data.test.ts (2)

102-190: Well-structured guard condition tests.

The shouldSeed tests comprehensively cover all early exit conditions: production environment, CI environment, and non-empty tables for each entity type. The assertions correctly verify both logging output and that database operations are skipped.


192-370: Thorough seeding workflow tests with good assertion patterns.

The seedLocationData tests provide excellent coverage:

  • Upsert payloads verified for each entity type
  • Junction record delete-then-create pattern validated
  • Empty array handling for location 3 tested explicitly
  • Workflow ordering verified via log message sequence

The approach of deriving expected counts from mock data (e.g., line 308: mockLocationData.locations.filter((l) => l.regions.length > 0)) makes tests resilient to mock data changes.

@github-actions

github-actions Bot commented Nov 27, 2025

Copy link
Copy Markdown
Contributor

🎭 Playwright E2E Test Results

361 tests   361 ✅  30m 43s ⏱️
 20 suites    0 💤
  1 files      0 ❌

Results for commit 41e8bf8.

♻️ This comment has been updated with latest results.

The build was failing because the Prisma client wasn't generated
before running tests. This resulted in TypeScript errors where
the location, jurisdiction, region, and other models didn't exist
on the PrismaClient type.

Added a step to run 'yarn db:generate' before running tests to
ensure the Prisma client is generated from the collated schemas.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@sonarqubecloud

Copy link
Copy Markdown

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.

2 participants