Skip to content

check tool: use only the transformed_row to get geometry data#963

Merged
DilwoarH merged 7 commits into
mainfrom
rosado/961-map-geometry
Mar 17, 2025
Merged

check tool: use only the transformed_row to get geometry data#963
DilwoarH merged 7 commits into
mainfrom
rosado/961-map-geometry

Conversation

@rosado
Copy link
Copy Markdown
Contributor

@rosado rosado commented Mar 13, 2025

Preview Link

https://submit-pr-963.herokuapp.com/

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

  • Bug Fix

Description

As in the title.

Related Tickets & Documents

QA Instructions, Screenshots, Recordings

Submitting the above URLs to the check tool should work (note: the preview instance only accepts URLs, upload doesn't work).

Added/updated tests?

  • Yes

QA sign off

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

Summary by CodeRabbit

  • New Features
    • Enhanced API responses with an additional field providing explicit polygon geometry details.
    • Introduced updated request simulation configurations for improved endpoint response handling.
  • Refactor
    • Simplified the logic for extracting geometry data, ensuring more consistent data representation.
  • Tests
    • Updated test cases to include the new geometry field, ensuring robust data verification.

@rosado rosado added the bug Something isn't working label Mar 13, 2025
@rosado rosado self-assigned this Mar 13, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 13, 2025

Walkthrough

The changes add a new field, transformed_row, to multiple JSON structures, enhancing the representation of geometry data. Two JSON files used for request completions are updated, and several new WireMock mapping files are introduced for handling GET and POST requests. The ResponseDetails class has been refactored to extract geometry information from the new field, and the associated tests have been updated accordingly.

Changes

File(s) Change Summary
docker/request-api-stub/wiremock/__files/check_file/article-4/request-complete-details.json
docker/request-api-stub/wiremock/__files/check_file/article-4/request-complete.json
Added a new transformed_row field with polygon geometry data for entries 1 and 2, and an empty array for entry 3.
docker/request-api-stub/wiremock/mappings/...*.json (all new mapping files) Introduced new WireMock mapping files defining HTTP request/response scenarios (GET/POST) for the /requests endpoint, with status codes, JSON bodies, headers, and scenario management fields.
src/models/responseDetails.js Refactored the #makeGeometryGetter method to directly use transformed_row for retrieving geometry, removing prior conditional mappings and logging.
test/unit/responseDetails.test.js Updated tests to include the new transformed_row field and adjusted the import statement to append the .js extension.

Sequence Diagram(s)

sequenceDiagram
    participant Client
    participant WireMock
    Client->>WireMock: Send GET/POST request to /requests endpoint
    WireMock-->>Client: Return JSON response (status, headers, body)
Loading
sequenceDiagram
    participant App
    participant ResponseDetails
    participant DataItem
    App->>ResponseDetails: Invoke #makeGeometryGetter(item)
    ResponseDetails->>DataItem: Access item.transformed_row
    alt Field 'geometry' or 'point' found
        DataItem-->>ResponseDetails: Return corresponding geometry value
    else Field not found
        DataItem-->>ResponseDetails: Return undefined
    end
    ResponseDetails-->>App: Return extracted geometry value or undefined
Loading

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • GeorgeGoodall-GovUk

Poem

I hopped through code, light on my feet,
Adding fields that now complete,
Geometry flows in transformed rows,
A mapping tale the server knows.
With every test and every line,
This bunny sings a joyful rhyme! 🐇💻

Tip

⚡🧪 Multi-step agentic review comment chat (experimental)
  • We're introducing multi-step agentic chat in review comments. This experimental feature enhances review discussions with the CodeRabbit agentic chat by enabling advanced interactions, including the ability to create pull requests directly from comments.
    - To enable this feature, set early_access to true under in the settings.
✨ Finishing Touches
  • 📝 Generate Docstrings

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
🪧 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.
  • @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 Mar 13, 2025

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 67.44% 5601 / 8304
🔵 Statements 67.44% 5601 / 8304
🔵 Functions 64.03% 235 / 367
🔵 Branches 79.86% 734 / 919
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/models/responseDetails.js 96.06% 87.93% 100% 96.06% 101, 167-168, 195-200, 285
Generated in workflow #968 for commit db4e9d9 by the Vitest Coverage Report Action

@DilwoarH DilwoarH marked this pull request as ready for review March 14, 2025 11:08
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

🧹 Nitpick comments (1)
src/models/responseDetails.js (1)

275-286: Implementation properly leverages transformed_row for geometry data

The refactoring improves on the previous implementation by directly using transformed_row to extract geometry data, which aligns with the PR objective. The code now specifically checks for fields named 'geometry' or 'point', and uses optional chaining to safely handle undefined values.

A few observations:

  1. The implementation only checks for 'geometry' and 'point' fields, which may be more restrictive than the previous implementation that also handled 'wkt' and 'geox'. Ensure this won't miss valid geometry data in your application.

  2. The method now returns undefined earlier without logging, which might make debugging harder. Consider adding debug logging before returning undefined to maintain visibility.

  3. Consider adding a comment explaining the expected structure of transformed_row (objects with 'field' and 'value' properties) to help future developers understand the data structure this code relies on.

 #makeGeometryGetter (item) {
   /*
     The api seems to sometimes respond with weird casing, it can be camal case, all lower or all upper
     I'll implement a fix here, but hopefully infa will be addressing it on the backend to
   */
   const trow = item.transformed_row
   if (trow) {
     const key = trow.find(obj => obj.field === 'geometry' || obj.field === 'point')?.field
     const getter = (row) => {
       const geometry = row.transformed_row?.find(obj => obj.field === key)
       return geometry?.value
     }
     return getter
   }

+  // No valid geometry field found in transformed_row
+  logger.debug('No valid geometry field found in transformed_row', {
+    type: types.App,
+    requestId: this.id
+  })
   return undefined
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 477b05e and e03275d.

📒 Files selected for processing (10)
  • docker/request-api-stub/wiremock/__files/check_file/article-4/request-complete-details.json (3 hunks)
  • docker/request-api-stub/wiremock/__files/check_file/article-4/request-complete.json (3 hunks)
  • docker/request-api-stub/wiremock/mappings/requests-fe547850-a713-43a8-8474-446631ab544b.json (1 hunks)
  • docker/request-api-stub/wiremock/mappings/requests_bbw7ebivop3leg7ue9vka4-259eb311-bc53-46c4-80cc-17ff203d6fed.json (1 hunks)
  • docker/request-api-stub/wiremock/mappings/requests_bbw7ebivop3leg7ue9vka4-31b3b282-b265-4f7c-ac66-db61e3f81be2.json (1 hunks)
  • docker/request-api-stub/wiremock/mappings/requests_bbw7ebivop3leg7ue9vka4-6257849e-1550-4530-9e2e-5d7f45e1abdc.json (1 hunks)
  • docker/request-api-stub/wiremock/mappings/requests_bbw7ebivop3leg7ue9vka4-7ffceaf2-278c-46d3-9b8e-f403a36bd93f.json (1 hunks)
  • docker/request-api-stub/wiremock/mappings/requests_bbw7ebivop3leg7ue9vka4-b6a3aed5-d09a-4d22-b04f-8372db46df90.json (1 hunks)
  • src/models/responseDetails.js (1 hunks)
  • test/unit/responseDetails.test.js (3 hunks)
🔇 Additional comments (16)
docker/request-api-stub/wiremock/mappings/requests_bbw7ebivop3leg7ue9vka4-6257849e-1550-4530-9e2e-5d7f45e1abdc.json (1)

1-23: Mapping File Structure is Clear and Consistent
The JSON file is well structured and clearly defines the request and response for the check URL endpoint. The usage of scenario management fields (e.g. requiredScenarioState and newScenarioState) and the inclusion of a detailed response body aligns with standard WireMock mapping practices. Please ensure that the naming and timestamp differences across similar mappings are intentional.

docker/request-api-stub/wiremock/mappings/requests_bbw7ebivop3leg7ue9vka4-259eb311-bc53-46c4-80cc-17ff203d6fed.json (1)

1-23: Consistent Mapping with Appropriate Scenario Fields
This mapping mirrors the structure of other similar mappings. The request details, response body and scenario management fields are defined consistently. Double-check that the slight differences (for example, the Date header timestamp) are in line with the intended test scenarios.

docker/request-api-stub/wiremock/mappings/requests_bbw7ebivop3leg7ue9vka4-7ffceaf2-278c-46d3-9b8e-f403a36bd93f.json (1)

1-23: Mapping Reflecting Completed State
The mapping correctly reflects a “COMPLETE” status in the response body as opposed to “PROCESSING” in other mappings. This variation is likely to facilitate different test conditions. Kindly verify that this completed status is the intended outcome for this particular endpoint mapping.

docker/request-api-stub/wiremock/mappings/requests_bbw7ebivop3leg7ue9vka4-31b3b282-b265-4f7c-ac66-db61e3f81be2.json (1)

1-22: Ordering and Scenario State are Appropriately Managed
This mapping is consistent with the other GET mappings for the same endpoint and utilises a distinct insertion index to ensure the correct order within scenarios. Please verify that the ordering (insertionIndex) correctly reflects the desired workflow.

docker/request-api-stub/wiremock/__files/check_file/article-4/request-complete.json (3)

59-67: Addition of the transformed_row Field in Entry 1
The introduction of the transformed_row field containing geometry data in entry 1 is in line with the PR objective. The inclusion of a polygon in Well-Known Text (WKT) format allows the application to retrieve geometry data solely from this field. Please ensure that the provided WKT string is valid and correctly represents the intended geometry.


80-88: Inclusion of transformed_row for Entry 2 is Consistent
The addition of the transformed_row field for entry 2 similarly captures the geometry data as intended. The WKT string provided appears consistent with the format used in entry 1. It is advisable to verify that both the transformed and converted row fields remain in sync or that the application uses only the transformed data as per the new logic.


101-104: Handling of Empty transformed_row in Entry 3 and Data Anomalies
For entry 3, the deliberate assignment of an empty array to transformed_row is appropriate if no geometry data is available. However, please review the test data for consistency; for example, the start-date in the converted_row is set to "40/04/2024", which does not conform to recognised date formats. Kindly verify whether this is intentional as part of the test fixture or requires correction.

docker/request-api-stub/wiremock/mappings/requests_bbw7ebivop3leg7ue9vka4-b6a3aed5-d09a-4d22-b04f-8372db46df90.json (1)

1-23: New WireMock mapping for GET request simulation looks good

This is a well-structured WireMock mapping that simulates a GET request to /requests/bBw7eBivoP3LEg7UE9VKA4 endpoint. The mapping is properly configured with scenario states to simulate sequential API interactions during testing.

The mapping returns a request in "PROCESSING" status with appropriate metadata for checking a conservation area GeoJSON URL, which aligns with the PR objective of fixing the geometry data retrieval process.

docker/request-api-stub/wiremock/mappings/requests-fe547850-a713-43a8-8474-446631ab544b.json (1)

1-26: New WireMock mapping for POST request simulation looks good

This WireMock mapping correctly handles the creation of new requests via POST to the /requests endpoint. The mapping is properly configured to match requests with the specified payload structure while ignoring array order and extra elements for flexibility.

The stub returns a 202 Accepted response with appropriate headers and response body structure, which aligns with the expected API behaviour for initiating a URL check request in the workflow.

docker/request-api-stub/wiremock/__files/check_file/article-4/request-complete-details.json (3)

5-10: Well-structured implementation of transformed_row for geometry data

This addition of the transformed_row field for entry 1 properly encapsulates the geometry data in a standardised format, with a clear field identifier and WKT value. This structure makes geometry data retrieval more explicit and reliable, addressing the bug described in issue #961.


26-31: Consistent implementation of transformed_row for entry 2

The implementation of transformed_row for entry 2 follows the same pattern as entry 1, maintaining consistency in how geometry data is structured. This is good practice for ensuring uniform data access patterns.


47-47: Empty transformed_row for entry without geometry

Appropriately initializing transformed_row as an empty array for entry 3 that doesn't have geometry data. This consistency ensures that code accessing this property won't encounter undefined errors, even when no geometry is available.

test/unit/responseDetails.test.js (4)

1-1: File extension added to import statement

Adding the .js extension to the import statement ensures compatibility with ES modules and prevents potential import resolution issues, especially in environments that enforce strict module resolution.


28-30: Added transformed_row to test mock data for entry 1

The mock data has been properly updated to include the transformed_row field for the first test entry, ensuring the tests accurately reflect the new data structure used in the application.


46-48: Added transformed_row to test mock data for entry 2

The mock data has been properly updated to include the transformed_row field for the second test entry, ensuring consistency across all test data.


54-60: Updated mockResponsWithGeoXGeoY mapping function

The function that generates mock data with GeoX and GeoY coordinates has been properly updated to include the transformed_row field in its output, ensuring that all test data consistently includes this field for geometry retrieval tests.

@DilwoarH DilwoarH temporarily deployed to submit-pr-963 March 17, 2025 10:36 Inactive
@DilwoarH DilwoarH merged commit 21d0db2 into main Mar 17, 2025
@DilwoarH DilwoarH deleted the rosado/961-map-geometry branch March 17, 2025 11:14
@github-project-automation github-project-automation Bot moved this from Refined to Ready for release in Providers team (BACKLOG) Mar 17, 2025
@DilwoarH DilwoarH moved this from Ready for release to Done in Providers team (BACKLOG) Mar 18, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Mar 21, 2025
8 tasks
@coderabbitai coderabbitai Bot mentioned this pull request Apr 4, 2025
6 tasks
@neilfwar neilfwar moved this from Done to Done Archived in Providers team (BACKLOG) Apr 8, 2025
@coderabbitai coderabbitai Bot mentioned this pull request Apr 15, 2025
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

No open projects
Status: Done Archived

Development

Successfully merging this pull request may close these issues.

Incorrect geometry value being used on check results page

4 participants