Skip to content

refactor: improve column mapping request handling and add tests for m… - #1235

Merged
gibahjoe merged 2 commits into
mainfrom
2763-sentry-organisation-of-object-null-as-it-is-null
Jul 23, 2026
Merged

refactor: improve column mapping request handling and add tests for m…#1235
gibahjoe merged 2 commits into
mainfrom
2763-sentry-organisation-of-object-null-as-it-is-null

Conversation

@gibahjoe

@gibahjoe gibahjoe commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this? (check all applicable)

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Description

Fixes column mapping request handling when async request params are missing. The column mapping route now returns a shared 404 “Page not found” error when organisationName or dataset is unavailable, and isStatutoryDataset is defensive against null or missing params.

Related Tickets & Documents

  • Ticket Link
  • Related Issue #
  • Closes #

QA Instructions, Screenshots, Recordings

Run the focused unit tests and lint checks:

npx vitest run test/unit/columnMappingController.test.js test/unit/redisLoader.test.js
npx standard src/controllers/columnMappingController.js src/utils/redisLoader.js test/unit/columnMappingController.test.js test/unit/redisLoader.test.js

Also manually verify that /check/column-mapping/:id returns the shared “Page not found” page when the completed request data does not include both organisationName and dataset.

No UI screenshots required.

Added/updated tests?

We encourage you to keep the code coverage percentage at 80% and above. Please refer to the [Digital Land Testing Guidance](https://digital-land.github.io/technical-documentation/development/testing-guidance/) for more information.

  • Yes
  • No, and this is why:
  • I need help with writing tests

[optional] Are there any post deployment tasks we need to perform?

None.

[optional] Are there any dependencies on other PRs or Work?

None.

Summary by CodeRabbit

  • Bug Fixes

    • Improved handling of unavailable column-mapping requests.
    • Requests with missing details or statutory datasets now return a clear 404 response.
    • Improved resilience when checking dataset information with incomplete request data.
  • Tests

    • Added coverage for missing request parameters and invalid dataset checks.
    • Confirmed that incomplete requests do not trigger unnecessary data queries.

@coderabbitai

coderabbitai Bot commented Jul 22, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@gibahjoe, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 53 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 379a56e8-b018-4950-a99a-2b7a8e9dd2e4

📥 Commits

Reviewing files that changed from the base of the PR and between 2023726 and dcbe120.

📒 Files selected for processing (1)
  • test/unit/columnMappingController.test.js

Walkthrough

The column-mapping controller now uses shared middleware to validate request parameters and reject unavailable statutory datasets with 404 errors. isStatutoryDataset safely handles missing input, with unit tests covering both behaviours.

Changes

Column mapping availability

Layer / File(s) Summary
Defensive statutory dataset check
src/utils/redisLoader.js, test/unit/redisLoader.test.js
isStatutoryDataset tolerates missing parameters and avoids Datasette queries when required values are absent.
Unavailable mapping middleware
src/controllers/columnMappingController.js, test/unit/columnMappingController.test.js
The controller registers exported middleware that validates request parameters, checks statutory datasets, and forwards 404 MiddlewareError instances; tests cover missing parameters.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

Suggested labels: enhancement

Suggested reviewers: eveleighoj, pooleycodes

Poem

I’m a rabbit guarding mappings neat,
With 404s for paths incomplete.
Statutory datasets hop away,
Safe checks keep queries at bay.
Tests twitch their noses: all clear!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title is clearly related to the PR’s column mapping request handling changes and added tests, even if slightly truncated.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 2763-sentry-organisation-of-object-null-as-it-is-null

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

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

@github-actions

github-actions Bot commented Jul 22, 2026

Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 71.17% 2558 / 3594
🔵 Statements 70.38% 2700 / 3836
🔵 Functions 64.52% 511 / 792
🔵 Branches 64.21% 1267 / 1973
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/controllers/columnMappingController.js 57.19% 63.43% 68.42% 56.95% 16-113, 127-212, 239, 267-275, 284, 383, 413, 421-436, 450, 454, 505, 512, 519
src/utils/redisLoader.js 66.66% 72.72% 86.66% 67.04% 24-26, 32-34, 48, 54, 62, 67, 104, 117, 129, 138-142, 153, 161-188
Generated in workflow #1563 for commit dcbe120 by the Vitest Coverage Report Action

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

🧹 Nitpick comments (1)
test/unit/columnMappingController.test.js (1)

18-45: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Cover an absent requestData object.

Add a { locals: {} } case asserting the same 404 error. This directly protects the nullish requestData?.getParams?.() path introduced for unavailable asynchronous request data.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@test/unit/columnMappingController.test.js` around lines 18 - 45, Add a third
invocation in the test for handleUnavailableColumnMappingRequest using { locals:
{} }, then assert that next receives a MiddlewareError with statusCode 404,
matching the existing missing-parameter cases and covering the optional
requestData path.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@test/unit/columnMappingController.test.js`:
- Around line 18-45: Add a third invocation in the test for
handleUnavailableColumnMappingRequest using { locals: {} }, then assert that
next receives a MiddlewareError with statusCode 404, matching the existing
missing-parameter cases and covering the optional requestData path.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 1ac10455-782a-4f73-a410-8a3a64c4663f

📥 Commits

Reviewing files that changed from the base of the PR and between b2ef655 and 2023726.

📒 Files selected for processing (4)
  • src/controllers/columnMappingController.js
  • src/utils/redisLoader.js
  • test/unit/columnMappingController.test.js
  • test/unit/redisLoader.test.js

@pooleycodes pooleycodes 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.

LGTM

@gibahjoe
gibahjoe merged commit 9becdbd into main Jul 23, 2026
7 of 8 checks passed
@gibahjoe
gibahjoe deleted the 2763-sentry-organisation-of-object-null-as-it-is-null branch July 23, 2026 12:43
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.

Sentry: 'organisation' of 'object null' as it is null.

2 participants