shoc-backend/SeaHaven.Services.Tests/PagedResultTests.cs
Arthur Bassi 620a36af54
feat(work-orders): enrich board search overdue filters and 0-based paging (#23)
* feat(work-orders): enrich board search overdue filters and 0-based paging

* fix(work-orders): align stacked services with CI build

* fix(tests): pass userDataService in comment service unit test

* fix(work-orders): use dedicated overdue query flag

Stop treating WorkOrderType.Other as an overdue sentinel. Board and advanced search now accept overdue=true while types=Other filters real Other rows; combining both uses OR.

* test(work-orders): cover overdue date/status boundary and Other type-filter

Lock the PR #23 overdue regression boundary through the public advanced
search service. Prove overdue filtering is driven by past-due date plus
non-terminal status, not by the WorkOrderType.Other sentinel:
- Other + future/not-completed excluded from overdue
- past-due + Scheduled included; past-due + Completed/Canceled excluded
- types=[PM, Other] keeps real Other rows and does not pull past-due rows
- assert 0-based paging (Page=0) is preserved alongside overdue/type filters

---------

Co-authored-by: Arthur Bassi <arthur.winiarski.ranger@outlook.com>
Co-authored-by: Alexandre Brandizzi <alex_brandizzi@hotmail.com>
2026-07-24 21:12:03 +00:00

51 lines
1.8 KiB
C#

using FluentAssertions;
using SeaHaven.Services.DTOs;
using Xunit;
namespace SeaHaven.Services.Tests;
public class PagedResultTests
{
[Theory]
[InlineData(0, 10, 0)]
[InlineData(1, 10, 1)]
[InlineData(10, 10, 1)]
[InlineData(11, 10, 2)]
[InlineData(100, 25, 4)]
public void TotalPages_IsCeilingOfCountOverPageSize(int totalCount, int pageSize, int expectedPages)
{
var result = new PagedResult<string> { TotalCount = totalCount, PageSize = pageSize, Page = 1 };
result.TotalPages.Should().Be(expectedPages);
}
[Fact]
public void HasPrevious_IsFalseOnFirstPage_TrueAfterward_OneBased()
{
new PagedResult<string> { Page = 1, PageSize = 10, TotalCount = 30 }.HasPrevious.Should().BeFalse();
new PagedResult<string> { Page = 2, PageSize = 10, TotalCount = 30 }.HasPrevious.Should().BeTrue();
}
[Fact]
public void HasNext_IsTrueBeforeLastPage_FalseOnLastPage_OneBased()
{
new PagedResult<string> { Page = 2, PageSize = 10, TotalCount = 30 }.HasNext.Should().BeTrue();
new PagedResult<string> { Page = 3, PageSize = 10, TotalCount = 30 }.HasNext.Should().BeFalse();
}
[Fact]
public void HasPrevious_And_HasNext_ZeroBased_WhenPageBaseIsZero()
{
var first = new PagedResult<string> { Page = 0, PageSize = 10, TotalCount = 30, PageBase = 0 };
first.HasPrevious.Should().BeFalse();
first.HasNext.Should().BeTrue();
var middle = new PagedResult<string> { Page = 1, PageSize = 10, TotalCount = 30, PageBase = 0 };
middle.HasPrevious.Should().BeTrue();
middle.HasNext.Should().BeTrue();
var last = new PagedResult<string> { Page = 2, PageSize = 10, TotalCount = 30, PageBase = 0 };
last.HasPrevious.Should().BeTrue();
last.HasNext.Should().BeFalse();
}
}