test(integration): pagination edge cases (prd-003-prices-pagination)
This commit is contained in:
@@ -304,6 +304,102 @@ public sealed class ProductPricesControllerTests : IAsyncLifetime
|
||||
paged!.Page.Should().Be(1, "page=0 must be clamped to 1");
|
||||
}
|
||||
|
||||
/// <summary>§P.4 boundary — pageSize=100 exacto → no clamping, boundary inclusivo.</summary>
|
||||
[Fact]
|
||||
public async Task GetPrices_PageSize100_Exact_Returns200()
|
||||
{
|
||||
var productId = await SeedProductAsync();
|
||||
// Seed 3 prices — all but the last have explicit PVT
|
||||
for (var i = 1; i <= 3; i++)
|
||||
{
|
||||
var pvt = i < 3 ? (DateOnly?)new DateOnly(2026, 1, i) : null;
|
||||
await SeedPriceDirectAsync(productId, i * 10m, new DateOnly(2026, 1, i), pvt);
|
||||
}
|
||||
|
||||
var token = GetAdminToken();
|
||||
using var req = BuildRequest(
|
||||
HttpMethod.Get, $"/api/v1/products/{productId}/prices?pageSize=100", token: token);
|
||||
var resp = await _client.SendAsync(req);
|
||||
|
||||
resp.StatusCode.Should().Be(HttpStatusCode.OK);
|
||||
var paged = await resp.Content.ReadFromJsonAsync<PagedResult<ProductPriceDto>>();
|
||||
paged.Should().NotBeNull();
|
||||
paged!.PageSize.Should().Be(100, "pageSize=100 is the upper boundary — must NOT be clamped further");
|
||||
paged.Items.Should().HaveCount(3);
|
||||
}
|
||||
|
||||
/// <summary>§P.4 boundary — pageSize=101 → clamp to 100.</summary>
|
||||
[Fact]
|
||||
public async Task GetPrices_PageSize101_ClampsTo100()
|
||||
{
|
||||
var productId = await SeedProductAsync();
|
||||
await SeedPriceDirectAsync(productId, 50m, new DateOnly(2026, 2, 1), null);
|
||||
|
||||
var token = GetAdminToken();
|
||||
using var req = BuildRequest(
|
||||
HttpMethod.Get, $"/api/v1/products/{productId}/prices?pageSize=101", token: token);
|
||||
var resp = await _client.SendAsync(req);
|
||||
|
||||
resp.StatusCode.Should().Be(HttpStatusCode.OK);
|
||||
var paged = await resp.Content.ReadFromJsonAsync<PagedResult<ProductPriceDto>>();
|
||||
paged.Should().NotBeNull();
|
||||
paged!.PageSize.Should().Be(100, "pageSize=101 must be clamped to 100");
|
||||
}
|
||||
|
||||
/// <summary>§P.4 boundary — pageSize=1000 → clamp to 100.</summary>
|
||||
[Fact]
|
||||
public async Task GetPrices_PageSize1000_ClampsTo100()
|
||||
{
|
||||
var productId = await SeedProductAsync();
|
||||
await SeedPriceDirectAsync(productId, 75m, new DateOnly(2026, 3, 1), null);
|
||||
|
||||
var token = GetAdminToken();
|
||||
using var req = BuildRequest(
|
||||
HttpMethod.Get, $"/api/v1/products/{productId}/prices?pageSize=1000", token: token);
|
||||
var resp = await _client.SendAsync(req);
|
||||
|
||||
resp.StatusCode.Should().Be(HttpStatusCode.OK);
|
||||
var paged = await resp.Content.ReadFromJsonAsync<PagedResult<ProductPriceDto>>();
|
||||
paged.Should().NotBeNull();
|
||||
paged!.PageSize.Should().Be(100, "pageSize=1000 must be clamped to max 100");
|
||||
}
|
||||
|
||||
/// <summary>§P.5 boundary — page=-5 → clamp to 1.</summary>
|
||||
[Fact]
|
||||
public async Task GetPrices_PageNegative_ClampsToOne()
|
||||
{
|
||||
var productId = await SeedProductAsync();
|
||||
await SeedPriceDirectAsync(productId, 120m, new DateOnly(2026, 4, 1), null);
|
||||
|
||||
var token = GetAdminToken();
|
||||
using var req = BuildRequest(
|
||||
HttpMethod.Get, $"/api/v1/products/{productId}/prices?page=-5", token: token);
|
||||
var resp = await _client.SendAsync(req);
|
||||
|
||||
resp.StatusCode.Should().Be(HttpStatusCode.OK);
|
||||
var paged = await resp.Content.ReadFromJsonAsync<PagedResult<ProductPriceDto>>();
|
||||
paged.Should().NotBeNull();
|
||||
paged!.Page.Should().Be(1, "page=-5 must be clamped to 1");
|
||||
}
|
||||
|
||||
/// <summary>§P.4 boundary — pageSize=0 → clamp to 1 (minimum).</summary>
|
||||
[Fact]
|
||||
public async Task GetPrices_PageSizeZero_ClampsToOne()
|
||||
{
|
||||
var productId = await SeedProductAsync();
|
||||
await SeedPriceDirectAsync(productId, 90m, new DateOnly(2026, 5, 1), null);
|
||||
|
||||
var token = GetAdminToken();
|
||||
using var req = BuildRequest(
|
||||
HttpMethod.Get, $"/api/v1/products/{productId}/prices?pageSize=0", token: token);
|
||||
var resp = await _client.SendAsync(req);
|
||||
|
||||
resp.StatusCode.Should().Be(HttpStatusCode.OK);
|
||||
var paged = await resp.Content.ReadFromJsonAsync<PagedResult<ProductPriceDto>>();
|
||||
paged.Should().NotBeNull();
|
||||
paged!.PageSize.Should().Be(1, "pageSize=0 must be clamped to minimum 1");
|
||||
}
|
||||
|
||||
/// <summary>§P.7 — Producto inexistente → 404.</summary>
|
||||
[Fact]
|
||||
public async Task GetPrices_ProductNotFound_Returns404()
|
||||
|
||||
Reference in New Issue
Block a user