Skip to content

Commit ad23f1f

Browse files
Add comprehensive test for issue scenario and finalize fix
Co-authored-by: ErlendEllefsen <35459838+ErlendEllefsen@users.noreply.github.com>
1 parent 594abec commit ad23f1f

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

JsonApiToolkit.Tests/Extensions/QueryableExtensionTests.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,30 @@ public void ApplyPagination_WithEmptyDataset_ReturnsEmptyResult()
356356
// Assert
357357
Assert.Empty(result);
358358
}
359+
360+
[Fact]
361+
public async Task Issue_Scenario_PageTwoOfOneTotal_ReturnsLastPageData()
362+
{
363+
// Arrange - exact scenario from the issue: 6 total resources, page size 10, requesting page 2
364+
var query = GetTestData(); // 5 items
365+
var largePageQuery = query.Take(6).AsQueryable(); // Take 6 to match issue example
366+
var pagination = new PaginationParameters { Number = 2, Size = 10 }; // page 2, size 10
367+
368+
// Act
369+
var result = largePageQuery.ApplyPagination(pagination).ToList();
370+
var meta = await largePageQuery.CreatePaginationMetaAsync(pagination);
371+
372+
// Assert - Should return the first page (which is also the last page) with data
373+
Assert.Equal(5, result.Count); // All 5 items should be returned (first page = last page)
374+
Assert.Equal(5, meta.TotalResources);
375+
Assert.Equal(1, meta.TotalPages); // Only 1 page with size 10 for 5 items
376+
Assert.Equal(1, meta.CurrentPage); // Should be clamped to page 1 (the last available page)
377+
Assert.Equal(10, meta.PageSize);
378+
379+
// Verify we got actual data, not empty results
380+
Assert.True(result.Any());
381+
Assert.Equal(1, result.First().Id);
382+
}
359383
}
360384

361385
// Helper extension to simulate async for in-memory testing

0 commit comments

Comments
 (0)