test(habits): cover pagination arithmetic, validator boundaries, and bulk-size limits#380
Merged
Merged
Conversation
…bulk-size limits (#243) Close the remaining tests-audit gaps for the habit-schedule query and bulk habit validators with behavior + edge + boundary assertions: - GetHabitScheduleQueryValidator: negative Page and zero/over-max PageSize now assert the exact ValidationFailure (property, error code, attempted value); the max PageSize and minimum Page boundaries assert no error. - GetHabitScheduleQueryHandler: totalPages arithmetic (zero, exactly divisible, +1 remainder), a far-beyond-last page clamping to the last page with its remainder item, and search+frequency filters combined with pagination returning the correctly filtered+paged subset with metadata. - BulkCreate/BulkDelete/BulkLog validators: a near-limit (max) payload validates and an over-limit payload is rejected with the configured-max message, asserting the boundary at MaxBulkOperationSize. Refs thomasluizon/orbit-ui-mobile#243 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
|
There was a problem hiding this comment.
PR Review: #380 — test(habits): cover pagination arithmetic, validator boundaries, and bulk-size limits
Recommendation: APPROVE
| Severity | Count |
|---|---|
| Critical | 0 |
| High | 0 |
| Medium | 0 |
| Low / Info | 0 |
Scope
Test-only diff, 4 files, 215 insertions, no src/ changes:
tests/Orbit.Application.Tests/Queries/Habits/GetHabitScheduleQueryHandlerTests.cs— 5 new tests covering pagination arithmetic (zero total, exact-divisible page count, remainder rounding, page-beyond-last clamping, combined search+frequency-filter+pagination)tests/Orbit.Application.Tests/Validators/BulkCommandValidatorTests.cs— exact-max/over-max boundary tests for bulk create/deletetests/Orbit.Application.Tests/Validators/BulkLogHabitsCommandValidatorTests.cs— over-max error message testtests/Orbit.Application.Tests/Validators/GetHabitScheduleQueryValidatorTests.cs— error-code/attempted-value assertions for Page/PageSize boundaries
Verification performed
Independently traced every new assertion against the production code it exercises:
src/Orbit.Application/Habits/Queries/GetHabitScheduleQuery.cs:165-166,220-221,320-321— confirmedtotalPages = (int)Math.Ceiling((double)totalCount / request.PageSize)andpage = Math.Max(1, Math.Min(request.Page, Math.Max(1, totalPages)))match all 4 new pagination-boundary tests, including thePage: 999clamp-to-last-page case.src/Orbit.Application/Habits/Validators/GetHabitScheduleQueryValidator.cs:31-35— confirmedRuleFor(q => q.Page).GreaterThanOrEqualTo(1)andRuleFor(q => q.PageSize).InclusiveBetween(1, AppConstants.MaxPageSize)produce exactly the"GreaterThanOrEqualValidator"/"InclusiveBetweenValidator"FluentValidation error codes asserted in the new tests.src/Orbit.Application/Habits/Validators/BulkCreateHabitsCommandValidator.cs:17-18,BulkDeleteHabitsCommandValidator.cs:17-18,BulkLogHabitsCommandValidator.cs:19-20— confirmed the exact error message strings ("Cannot create more than {N} habits at once","Cannot delete more than {N} habits at once","Bulk log cannot exceed {N} items") match the new test assertions verbatim.AppConstants.MaxBulkOperationSize = 100,AppConstants.MaxPageSize = 200— confirmed values are referenced (not hardcoded) in all new boundary tests, so tests stay correct if the constants change.
No dead code, no comment-policy violations, no security surface touched (no src/ changes), no DTO/contract surface touched, no i18n/FEATURES.md/DESIGN.md surface touched. Cross-repo dimensions (contract-aligner, mobile parity) are N/A — this PR adds only backend unit tests.
Deferred
dotnet build/dotnet test— not run in this session per the CI-adaptation note (Build/Unit Tests/SonarCloud run as separate required checks on this PR). Substituted with a manual line-by-line trace of the pagination arithmetic and validator rules against the actual source, detailed above.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Closes the remaining
/prod-readinesstests-audit gaps for the habit-schedule query and the bulk-habit validators (Batch 7, api tests part 2). Tests only — no source change was required to make these testable.GetHabitScheduleQueryValidator (edges, exact ValidationFailure)
Page→ single failure onPage, codeGreaterThanOrEqualValidator, attempted value asserted.PageSizeaboveMaxPageSizeandPageSize= 0 → single failure onPageSize, codeInclusiveBetweenValidator, attempted value asserted.PageSizeatMaxPageSizeandPageat minimum (1) → no error (passing boundary).GetHabitScheduleQueryHandler (pagination correctness)
totalCount= 0 →TotalPages= 0,Page= 1, empty items.totalCountexactly divisible byPageSize→ exactTotalPages.totalCountwith +1 remainder →TotalPagesrounds up and the last page holds the remainder.TotalCount/TotalPages/Page.Bulk validators (boundary at configured max)
BulkCreate/BulkDelete/BulkLog: a near-limit (MaxBulkOperationSize) payload validates; an over-limit payload is rejected with the exact configured-max message.All assertions can fail if the behavior breaks (no rubber-stamps). Full
Orbit.Application.Testssuite green (2772 passed).Refs thomasluizon/orbit-ui-mobile#243