Skip to content

711 add boundary to map on the check tool playback page#719

Merged
DilwoarH merged 2 commits into
mainfrom
711-add-boundary-to-map-on-the-check-tool-playback-page
Dec 10, 2024
Merged

711 add boundary to map on the check tool playback page#719
DilwoarH merged 2 commits into
mainfrom
711-add-boundary-to-map-on-the-check-tool-playback-page

Conversation

@DilwoarH
Copy link
Copy Markdown
Contributor

@DilwoarH DilwoarH commented Dec 5, 2024

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

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

Description

Add boundary to check tool.

Related Tickets & Documents

QA Instructions, Screenshots, Recordings

Before

Screenshot 2024-12-05 at 22 43 54

After

Screenshot 2024-12-05 at 22 44 55

Added/updated tests?

We encourage you to keep the code coverage percentage at 80% and above.

  • Yes
  • No, and this is why: Please replace this line with details on why tests have not been included
  • I need help with writing tests

QA sign off

  • Code has been checked and approved
  • Design has been checked and approved
  • Product and business logic has been checked and proved

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

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

Summary by CodeRabbit

Release Notes

  • New Features

    • Introduced a new query parameter, orgId, for enhanced deep link handling and validation.
    • Updated deep link URLs to include the orgId, improving the context conveyed in links.
    • Added a dynamic boundaryGeoJsonUrl to the context for geographical data retrieval based on orgId.
  • Bug Fixes

    • Enhanced error handling for invalid query parameters, ensuring users are redirected appropriately.
  • Tests

    • Adjusted test cases to validate the inclusion of the new orgId parameter in relevant functionalities.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Dec 5, 2024

Walkthrough

The changes in this pull request introduce an additional query parameter, orgId, to the DeepLinkController and related components. The QueryParams validation schema is updated to include orgId, which is now part of the destructured parameters in the get method. The checkToolDeepLink function is modified to include orgId in the generated deep link URL. Additionally, the HTML templates for error handling and no errors are updated to include a dynamic boundaryGeoJsonUrl based on orgId. Corresponding test cases are also adjusted to reflect these changes.

Changes

File Change Summary
src/controllers/deepLinkController.js Added orgId: NonEmptyString to QueryParams, updated get method to include orgId.
src/filters/checkToolDeepLink.js Updated checkToolDeepLink function to include orgId in the returned deep link URL.
src/views/check/results/errors.html Added conditional inclusion of boundaryGeoJsonUrl based on options.deepLink.orgId.
src/views/check/results/no-errors.html Added conditional inclusion of boundaryGeoJsonUrl based on options.deepLink.orgId, minor formatting adjustments.
test/unit/deepLinkController.test.js Updated test cases for DeepLinkController to include orgId in the session data assertions.
test/unit/views/organisations/dataset-overview.test.js Updated expected URL in test to include orgId in the dataset actions link.

Assessment against linked issues

Objective Addressed Explanation
Add boundary to map on the check tool playback page (#711)

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • GeorgeGoodall-GovUk

🐇 In the land where data hops and plays,
A new ID joins in joyful ways.
With boundaries drawn and links so neat,
The deep links now are quite the treat!
So let us cheer, with a thump and a bound,
For the changes made, let joy abound! 🎉


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Experiment)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Dec 5, 2024

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 70.52% 5184 / 7351
🔵 Statements 70.52% 5184 / 7351
🔵 Functions 69.18% 211 / 305
🔵 Branches 83.13% 685 / 824
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/controllers/deepLinkController.js 85.54% 71.42% 100% 85.54% 23-34
src/filters/checkToolDeepLink.js 100% 100% 100% 100%
Generated in workflow #448 for commit 46f5d7b by the Vitest Coverage Report Action

@DilwoarH DilwoarH force-pushed the 711-add-boundary-to-map-on-the-check-tool-playback-page branch from ea9d6ab to 123bb8d Compare December 5, 2024 22:54
@DilwoarH
Copy link
Copy Markdown
Contributor Author

DilwoarH commented Dec 5, 2024

@coderabbitai review

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Dec 5, 2024

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Outside diff range and nitpick comments (3)
src/controllers/deepLinkController.js (2)

11-12: Consider stricter validation for orgId

The NonEmptyString validation might be too permissive for orgId. Consider implementing a more specific validation pattern that matches your LPA ID format.

const OrgIdPattern = v.string([
  v.regex(/^[a-zA-Z0-9-_]+$/), // adjust regex to match your LPA ID format
  v.message('Organisation ID must contain only alphanumeric characters, hyphens, and underscores')
])

const QueryParams = v.object({
  dataset: NonEmptyString,
  orgName: NonEmptyString,
  orgId: OrgIdPattern
})

Line range hint 48-54: Enhance error logging for validation failures

The current error logging doesn't specify which parameter failed validation. Consider adding more detailed error information.

-    logger.info('DeepLinkController.get(): invalid params for deep link, redirecting to start page',
-      { type: types.App, query: req.query })
+    logger.info('DeepLinkController.get(): invalid params for deep link, redirecting to start page',
+      { 
+        type: types.App, 
+        query: req.query,
+        validationErrors: validationResult.issues?.map(issue => ({
+          path: issue.path?.map(p => p.key).join('.'),
+          message: issue.message
+        }))
+      })
test/unit/views/organisations/dataset-overview.test.js (1)

182-182: LGTM! Consider additional test coverage

The test correctly verifies the updated URL format with the orgId parameter.

Consider adding these test cases:

  • Verify the URL when orgId is undefined
  • Test the URL encoding of special characters in orgId
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 03713cc and 123bb8d.

📒 Files selected for processing (6)
  • src/controllers/deepLinkController.js (3 hunks)
  • src/filters/checkToolDeepLink.js (1 hunks)
  • src/views/check/results/errors.html (1 hunks)
  • src/views/check/results/no-errors.html (1 hunks)
  • test/unit/deepLinkController.test.js (1 hunks)
  • test/unit/views/organisations/dataset-overview.test.js (1 hunks)
🧰 Additional context used
📓 Learnings (1)
test/unit/views/organisations/dataset-overview.test.js (1)
Learnt from: GeorgeGoodall-GovUk
PR: digital-land/submit#510
File: test/unit/views/organisations/dataset-overview.test.js:3-3
Timestamp: 2024-11-12T10:13:49.419Z
Learning: Ensure to verify import paths in all relevant test files before flagging inconsistencies.
🔇 Additional comments (4)
src/filters/checkToolDeepLink.js (1)

10-10: Verify the organisation object structure

The code assumes organisation.organisation exists for the orgId parameter. Let's verify this assumption across the codebase.

✅ Verification successful

The organisation.organisation field is consistently used across the codebase

The verification shows that the organisation object structure with both name and organisation fields is well-established throughout the codebase:

  • It's formally defined in src/routes/schemas.js as OrgField = v.strictObject({ name: NonEmptyString, organisation: NonEmptyString, ... })
  • The structure is consistently used across tests and middleware components
  • The field is properly used in database queries and URL parameters
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for patterns where organisation object is constructed or passed
rg -A 2 "organisation\s*[:=]" --type js

Length of output: 15306

src/controllers/deepLinkController.js (1)

59-59: Verify session data structure compatibility

The modified session data structure now includes orgId. Let's verify that all consumers of this session data can handle this addition.

✅ Verification successful

Let me gather more information about how this session data is used in templates and views.


Based on the evidence gathered, I can now provide the final response:

The addition of orgId to the session data structure is safe and compatible

The codebase inspection shows that:

  • The test suite already expects and validates the orgId field in the session data
  • The templates correctly consume the orgId field for boundary URL generation
  • No direct property access patterns that could break with the addition of orgId
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for usage of checkToolDeepLinkSessionKey in the codebase
rg "checkToolDeepLinkSessionKey" --type js -A 5

Length of output: 1820


Script:

#!/bin/bash
# Search for usage of deepLink in template files
rg "deepLink" --type html -A 5

# Search for any direct access to session data structure
rg "deepLink\." --type js -A 2

Length of output: 2422

src/views/check/results/errors.html (1)

103-103: LGTM! Verify API endpoint availability

The addition of the boundary URL is well-implemented with proper conditional rendering.

Let's verify the API endpoint exists:

✅ Verification successful

API endpoint is properly implemented and well-tested

The /api/get-lpa-boundary/:boundaryId endpoint is fully implemented with:

  • Proper route handling in src/routes/api.js
  • Robust boundary service implementation in src/services/boundaryService.js
  • Comprehensive test coverage including error cases
  • Proper error handling for invalid inputs and failed requests
🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify the LPA boundary API endpoint exists
# Expected: Should find the API endpoint implementation

ast-grep --pattern 'app.$_(["\']/api/get-lpa-boundary/:$_["\'], $_)'

Length of output: 116


Script:

#!/bin/bash
# Search for API route definitions with variations of the LPA boundary endpoint
rg -l "app\.(get|post)\s*\(['\"]\/api\/get-lpa-boundary" 

# Search for any file containing the endpoint path
rg -l "\/api\/get-lpa-boundary"

# Look for route handlers or controller files
fd -t f "(routes|controller|api)" -x rg -l "get-lpa-boundary"

Length of output: 404


Script:

#!/bin/bash
# Check the API route implementation in the found file
cat src/routes/api.js

# Search for any related boundary endpoint implementations
rg -A 5 "get-lpa-boundary" src/routes/api.js

Length of output: 836


Script:

#!/bin/bash
# Check the boundary service implementation
cat src/services/boundaryService.js

# Look for any tests related to the boundary service
fd -t f "boundary.*test" -x cat {}

Length of output: 3583

src/views/check/results/no-errors.html (1)

107-109: LGTM! Consistent implementation

The boundary URL implementation matches the errors template, ensuring consistent behaviour across both success and error states.

Comment on lines +38 to +46
const query = { dataset: 'conservation-area', orgName: 'Some Org', orgId: 'some-org' }
const { req, res, next } = mockMiddlewareArgs({ query })

deepLinkController.get(req, res, next)

expect(req.sessionModel.get(deepLinkController.checkToolDeepLinkSessionKey)).toStrictEqual({
'data-subject': 'conservation-area',
orgName: 'Some Org',
orgId: 'some-org',
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.

🛠️ Refactor suggestion

Enhance test coverage with edge cases

The test suite would benefit from additional test cases:

  • Invalid orgId format
  • Missing orgId
  • Special characters in orgId

Here's a suggested addition:

it('should handle special characters in orgId', async () => {
  const query = { 
    dataset: 'conservation-area', 
    orgName: 'Some Org', 
    orgId: 'org/with@special&chars' 
  }
  const { req, res, next } = mockMiddlewareArgs({ query })
  
  deepLinkController.get(req, res, next)
  
  expect(req.sessionModel.get(deepLinkController.checkToolDeepLinkSessionKey))
    .toHaveProperty('orgId', 'org/with@special&chars')
})

it('should redirect to check when orgId is missing', async () => {
  const query = { 
    dataset: 'conservation-area', 
    orgName: 'Some Org'
  }
  const { req, res, next } = mockMiddlewareArgs({ query })
  
  deepLinkController.get(req, res, next)
  
  expect(res.redirect).toHaveBeenCalledWith('/check')
})

@DilwoarH
Copy link
Copy Markdown
Contributor Author

DilwoarH commented Dec 6, 2024

Needs #718 merged in first

rosado
rosado previously approved these changes Dec 9, 2024
@DilwoarH DilwoarH force-pushed the 699-change-the-way-we-get-boundary-geojson branch 3 times, most recently from e29f9d7 to a48dab7 Compare December 10, 2024 11:59
@DilwoarH DilwoarH changed the base branch from 699-change-the-way-we-get-boundary-geojson to main December 10, 2024 16:31
@DilwoarH DilwoarH dismissed rosado’s stale review December 10, 2024 16:31

The base branch was changed.

@DilwoarH DilwoarH force-pushed the 711-add-boundary-to-map-on-the-check-tool-playback-page branch from 123bb8d to 46f5d7b Compare December 10, 2024 16:35
@DilwoarH DilwoarH linked an issue Dec 10, 2024 that may be closed by this pull request
@DilwoarH DilwoarH temporarily deployed to submit-pr-719 December 10, 2024 16:35 Inactive
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Outside diff range and nitpick comments (1)
src/controllers/deepLinkController.js (1)

48-48: Add JSDoc for the new orgId parameter

Consider updating the method's JSDoc to document the new orgId query parameter.

/**
 * Handles deep links in the Check Tool.
 *
 * It is meant to extract required params from query params
 * and partially pre-populate the session with them,
 * then redirect the user to the "next" page in the wizard
+ * @param {Object} req.query
+ * @param {string} req.query.dataset - The dataset identifier
+ * @param {string} req.query.orgName - The organisation name
+ * @param {string} req.query.orgId - The organisation ID
 */
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between 123bb8d and 46f5d7b.

📒 Files selected for processing (6)
  • src/controllers/deepLinkController.js (3 hunks)
  • src/filters/checkToolDeepLink.js (1 hunks)
  • src/views/check/results/errors.html (1 hunks)
  • src/views/check/results/no-errors.html (1 hunks)
  • test/unit/deepLinkController.test.js (1 hunks)
  • test/unit/views/organisations/dataset-overview.test.js (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • src/filters/checkToolDeepLink.js
  • test/unit/deepLinkController.test.js
  • src/views/check/results/errors.html
  • src/views/check/results/no-errors.html
  • test/unit/views/organisations/dataset-overview.test.js
🔇 Additional comments (2)
src/controllers/deepLinkController.js (2)

59-59: LGTM! Clean implementation of session data update

The changes correctly integrate the new orgId parameter into the session data, maintaining consistency with the existing pattern.


11-12: Verify handling of existing deep links without orgId

The addition of orgId as a required parameter could potentially break existing deep links that don't include this parameter. Whilst the validation will redirect users to '/check', we should verify if there are any existing deep links in production that need updating.

✅ Verification successful

Deep link changes are safely handled with graceful fallback

Based on the test file evidence, the deep link controller already implements proper handling for invalid parameters:

  • It redirects to '/check' when parameters are invalid
  • The test suite includes verification for both invalid cases and the new required orgId parameter
  • The session update logic is properly tested with the new orgId parameter

The implementation ensures a graceful fallback to the check tool start page when deep links are invalid, making this a safe change that won't disrupt user experience.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for existing deep link URL construction or usage
rg -A 2 "\/check\?" 

Length of output: 97


Script:

#!/bin/bash
# Search for deep link URL construction or usage with proper escaping
rg -A 2 "/check\?"

# Also search for potential URL construction patterns
rg -A 2 "createDeepLink|generateDeepLink|buildDeepLink"

# Look for test files that might contain deep link examples
fd -e test.js -e spec.js -X rg -A 2 "check\?"

Length of output: 126


Script:

#!/bin/bash
# Search for URL-related functions in the controller
ast-grep --pattern 'function $FUNC($$$) {
  $$$
  url $$$
  $$$
}'

# Look for any URL generation or redirection logic
rg -l "url|redirect|location" src/controllers/deepLinkController.js

# Check for tests specific to deep linking
fd "deepLink.*test|deepLink.*spec"

# Look for route definitions that might use this controller
rg -A 2 "router.(get|post).*deepLink"

Length of output: 290


Script:

#!/bin/bash
# Check the test file for existing deep link test cases
cat test/unit/deepLinkController.test.js

# Look for validation schema history in git
git log -p -- src/controllers/deepLinkController.js | rg -A 5 -B 5 "NonEmptyString"

# Check for any documentation about deep linking
fd -e md -X rg -l "deep.?link"

Length of output: 1781

@DilwoarH DilwoarH merged commit 4cb0618 into main Dec 10, 2024
@DilwoarH DilwoarH deleted the 711-add-boundary-to-map-on-the-check-tool-playback-page branch December 10, 2024 16:53
@coderabbitai coderabbitai Bot mentioned this pull request Mar 21, 2025
8 tasks
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.

Add boundary to map on the check tool playback page

3 participants