Skip to content

test(habits): cover pagination arithmetic, validator boundaries, and bulk-size limits#380

Merged
thomasluizon merged 1 commit into
mainfrom
test/validators-pagination-edges
Jul 13, 2026
Merged

test(habits): cover pagination arithmetic, validator boundaries, and bulk-size limits#380
thomasluizon merged 1 commit into
mainfrom
test/validators-pagination-edges

Conversation

@thomasluizon

Copy link
Copy Markdown
Owner

Closes the remaining /prod-readiness tests-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)

  • Negative Page → single failure on Page, code GreaterThanOrEqualValidator, attempted value asserted.
  • PageSize above MaxPageSize and PageSize = 0 → single failure on PageSize, code InclusiveBetweenValidator, attempted value asserted.
  • PageSize at MaxPageSize and Page at minimum (1) → no error (passing boundary).

GetHabitScheduleQueryHandler (pagination correctness)

  • totalCount = 0 → TotalPages = 0, Page = 1, empty items.
  • totalCount exactly divisible by PageSize → exact TotalPages.
  • totalCount with +1 remainder → TotalPages rounds up and the last page holds the remainder.
  • A page far beyond the last clamps to the last page (with its remainder item) and correct metadata — not an error, not empty.
  • Search + frequency-unit filter combined with pagination returns the correctly filtered+paged subset with correct 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.Tests suite green (2772 passed).

Refs thomasluizon/orbit-ui-mobile#243

…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>
@sonarqubecloud

Copy link
Copy Markdown

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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/delete
  • tests/Orbit.Application.Tests/Validators/BulkLogHabitsCommandValidatorTests.cs — over-max error message test
  • tests/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 — confirmed totalPages = (int)Math.Ceiling((double)totalCount / request.PageSize) and page = Math.Max(1, Math.Min(request.Page, Math.Max(1, totalPages))) match all 4 new pagination-boundary tests, including the Page: 999 clamp-to-last-page case.
  • src/Orbit.Application/Habits/Validators/GetHabitScheduleQueryValidator.cs:31-35 — confirmed RuleFor(q => q.Page).GreaterThanOrEqualTo(1) and RuleFor(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.

@thomasluizon
thomasluizon merged commit c692ef1 into main Jul 13, 2026
19 checks passed
@thomasluizon
thomasluizon deleted the test/validators-pagination-edges branch July 13, 2026 06:31
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.

1 participant