LEGLINK-807: Implement Measure Mappings Functionality - #1807
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
📝 WalkthroughWalkthroughMeasure mappings now store measure, DQM, and frequency values. Search supports sanitized filters and paging. Create and update validate DQMs and duplicate mappings. A delete-all endpoint and tenant migration were added. ChangesMeasure mapping lifecycle
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant Client
participant MeasureMappingsController
participant MeasureEval
participant MeasureMappingManager
participant TenantDatabase
Client->>MeasureMappingsController: Submit mapping
MeasureMappingsController->>MeasureEval: Validate DQM
MeasureEval-->>MeasureMappingsController: Return validation status
MeasureMappingsController->>MeasureMappingManager: Save mapping
MeasureMappingManager->>TenantDatabase: Persist mapping
TenantDatabase-->>MeasureMappingManager: Return save result
MeasureMappingManager-->>MeasureMappingsController: Return mapping or duplicate error
MeasureMappingsController-->>Client: Return API response
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 6
🧹 Nitpick comments (3)
DotNet/DMRP/Business/Managers/MeasureMappingManager.cs (2)
18-19: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd XUnit coverage for
DeleteAllAsyncbranches.
IMeasureMappingManagerhas one concrete implementation, and it already providesDeleteAllAsync. Add small focused tests for the success path,OperationCanceledExceptionpropagation, and the generic/DbUpdateExceptionerror paths.🤖 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 `@DotNet/DMRP/Business/Managers/MeasureMappingManager.cs` around lines 18 - 19, Add focused xUnit coverage for DeleteAllAsync in the concrete IMeasureMappingManager implementation, covering successful completion, propagation of OperationCanceledException, generic exception handling, and DbUpdateException handling. Reuse the existing test setup and assertions for manager error behavior, keeping each branch test small and isolated.
53-72: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd focused XUnit coverage for the new branches.
MeasureMappingManagerTests.csdoes not cover the SQLite 2067 and SQL Server 2601/2627 unique-failure branches introduced byIsUniqueIndexViolation(), nor the non-unique commit failure branches forCreateAsyncandUpdateAsync. Add focused repository-mock tests forCreateAsync,UpdateAsync, andDeleteAllAsync(records, empty set, cancellation, and repository save failure). Do not use a network database.Applies to: 53-72, 97-102, 139-162
🤖 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 `@DotNet/DMRP/Business/Managers/MeasureMappingManager.cs` around lines 53 - 72, Expand MeasureMappingManagerTests with focused XUnit repository-mock coverage for CreateAsync, UpdateAsync, and DeleteAllAsync, including records, empty results, cancellation, and save failures. Add CreateAsync tests that trigger IsUniqueIndexViolation for SQLite error 2067 and SQL Server errors 2601/2627, plus non-unique commit failures for both CreateAsync and UpdateAsync; assert the expected exception and activity behavior without using a network database.Source: Path instructions
DotNet/DMRP/Models/SearchMeasureMappingDto.cs (1)
21-29: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick winAdd focused XUnit tests for each normalization branch.
Add tests for
PageSizebelow 1, above 100, and within range. Add tests forPageNumberbelow 1 and within range. Also verify the new string-filter sanitization.As per path instructions, "If/Else or Switch/Case blocks are introduced or modified — ensure each branch has a corresponding unit test."
🤖 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 `@DotNet/DMRP/Models/SearchMeasureMappingDto.cs` around lines 21 - 29, Add focused xUnit tests for the normalization logic in SearchMeasureMappingDto, covering PageSize below 1, above 100, and within the valid range, plus PageNumber below 1 and within range. Add assertions for the string-filter sanitization introduced alongside this logic, with each conditional branch exercised independently.Source: Path instructions
🤖 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.
Inline comments:
In `@DotNet/DMRP/Controllers/MeasureMappingsController.cs`:
- Around line 247-250: Update DqmExistsAsync in
DotNet/DMRP/Controllers/MeasureMappingsController.cs (lines 247-250) to
distinguish a 404 from other MeasureEval failures, propagating non-404 errors so
they are not reported as missing DQMs. Update the endpoints at lines 101-104 and
153-156 to return RFC Problem Details with a standard 502 or 503 for those
upstream failures. Extend
DotNet/ServiceTests/IntegrationTests/DMRP/MeasureMappingsControllerTests.cs
lines 33-41 with mocked 5xx responses and assertions for the gateway status and
problem-details response.
- Around line 216-217: Apply the existing ValidateAntiForgeryOrBearerToken
validation attribute to the DeleteAllMeasureMappings action, matching the
protection already used by the create and update endpoints while leaving its
deletion behavior unchanged.
- Around line 48-49: Update MeasureMappingsController.GetMeasureMappings to bind
SearchMeasureMappingDto from the query string by adding the appropriate
query-binding annotation, while preserving the existing GET route and
cancellation token behavior.
In `@DotNet/DMRP/Models/SearchMeasureMappingDto.cs`:
- Around line 17-20: Update SearchMeasureMappingDto.Sanitize() to sanitize the
Measure and DQM string query parameters as well as SortBy, using
HtmlInputSanitizer.Sanitize() or SanitizeAndRemove() as appropriate before the
values reach MeasureMappingQueries.
In `@DotNet/Shared/Application/Models/Integration/DMRP/DMRPApiModels.cs`:
- Around line 15-19: Add the StringLength validation attribute with a
255-character limit to both the Measure and DQM properties in the DMRP API
model, preserving their existing Required attributes so oversized requests are
rejected at the API boundary.
In `@DotNet/Tenant/Migrations/20260806183143_AddMeasureMappingFields.cs`:
- Around line 13-40: Update the migration’s Up method to stage the new
MeasureMappings fields: preflight existing rows and fail with a clear error when
legacy mappings cannot be mapped safely, then backfill valid unique Measure and
DQM values plus Frequency = "Adhoc" before enforcing non-null constraints and
creating IX_MeasureMappings_Measure_DQM; do not apply empty defaults that create
duplicate index keys.
---
Nitpick comments:
In `@DotNet/DMRP/Business/Managers/MeasureMappingManager.cs`:
- Around line 18-19: Add focused xUnit coverage for DeleteAllAsync in the
concrete IMeasureMappingManager implementation, covering successful completion,
propagation of OperationCanceledException, generic exception handling, and
DbUpdateException handling. Reuse the existing test setup and assertions for
manager error behavior, keeping each branch test small and isolated.
- Around line 53-72: Expand MeasureMappingManagerTests with focused XUnit
repository-mock coverage for CreateAsync, UpdateAsync, and DeleteAllAsync,
including records, empty results, cancellation, and save failures. Add
CreateAsync tests that trigger IsUniqueIndexViolation for SQLite error 2067 and
SQL Server errors 2601/2627, plus non-unique commit failures for both
CreateAsync and UpdateAsync; assert the expected exception and activity behavior
without using a network database.
In `@DotNet/DMRP/Models/SearchMeasureMappingDto.cs`:
- Around line 21-29: Add focused xUnit tests for the normalization logic in
SearchMeasureMappingDto, covering PageSize below 1, above 100, and within the
valid range, plus PageNumber below 1 and within range. Add assertions for the
string-filter sanitization introduced alongside this logic, with each
conditional branch exercised independently.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: cf6a6faa-043b-4555-bd34-a1d50e20076f
📒 Files selected for processing (17)
DotNet/DMRP/Business/Managers/MeasureMappingManager.csDotNet/DMRP/Business/Queries/MeasureMappingQueries.csDotNet/DMRP/Controllers/MeasureMappingsController.csDotNet/DMRP/DMRP.csprojDotNet/DMRP/Data/Entities/MeasureMapping.csDotNet/DMRP/Data/Repository/Mappings/MeasureMappingConfigMap.csDotNet/DMRP/Models/SearchMeasureMappingDto.csDotNet/DMRP/packages.lock.jsonDotNet/ServiceTests/IntegrationTests/DMRP/MeasureMappingsControllerTests.csDotNet/ServiceTests/UnitTests/DMRP/MeasureMappingQueriesTests.csDotNet/ServiceTests/packages.lock.jsonDotNet/Shared/Application/Models/Integration/DMRP/DMRPApiModels.csDotNet/Tenant/Migrations/20260806183143_AddMeasureMappingFields.Designer.csDotNet/Tenant/Migrations/20260806183143_AddMeasureMappingFields.csDotNet/Tenant/Migrations/TenantDbContextModelSnapshot.csDotNet/Tenant/packages.lock.jsonTests/BackendE2ETests/packages.lock.json
🛠️ Description of Changes
Add a Measure Mappings API.
🧪 Testing Performed
Tested with Postman.
🧑🔬 Unit Testing
📓 Documentation Updated
Please update any relevant sections in the project documentation that were impacted by the changes in the PR.
Summary by CodeRabbit