Build ErsatzTV Image / CI image pin matches docker/ci (pull_request) Successful in 5s
Build ErsatzTV Image / Docs update reminder (pull_request) Successful in 9s
Build ErsatzTV Image / decisions.md append-only (pull_request) Successful in 7s
Build ErsatzTV Image / Build & test (.NET) (pull_request) Successful in 7m10s
Build ErsatzTV Image / Functional E2E (curl contracts) (pull_request) Successful in 5m12s
Build ErsatzTV Image / EF migration integrity (SQLite + MySql) (pull_request) Successful in 14m53s
Build ErsatzTV Image / Build & push image (amd64) (pull_request) Has been skipped
Build ErsatzTV Image / API docs in sync (OpenAPI + endpoint index) (pull_request) Successful in 12m39s
Build ErsatzTV Image / Formatting (changed .cs conform to .editorconfig) (pull_request) Successful in 14m31s
The all-items endpoint fired ten index searches with limit:0 (every hit), so a broad authenticated query materialized the whole index into one response. Add optional pageNum/pageSize (clamped 1..1000; pageNum 0..2_000_000 so skip can't overflow int) and an additive per-kind Totals on the response; the SPA add-all flow now pages to completeness instead of a single unbounded fetch. - SearchController.SearchAllItems: clamp params (Logs §1 precedent), map Totals - QuerySearchIndexAllItemsHandler: skip=pageNum*pageSize, limit=pageSize, read SearchResult.TotalCount per kind - SearchResultAllItemsResponseModel: additive Totals (frozen-v1-safe) - web/src/api/search.ts: getSearchAllItems paging params + getAllSearchItemIds (pages until each kind hits its total; empty-page safety break) - tests: controller clamp/thread/totals, handler skip/limit/totals, SPA paging - docs: decisions.md 2026-07-18 (#293), api-conventions.md §5; regenerated OpenAPI Design: issue option (a) full pagination, operator-confirmed. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
79 lines
2.6 KiB
C#
79 lines
2.6 KiB
C#
using ErsatzTV.Application.Search;
|
|
using ErsatzTV.Core.Interfaces.Search;
|
|
using ErsatzTV.Core.Search;
|
|
using NSubstitute;
|
|
using NUnit.Framework;
|
|
using Shouldly;
|
|
|
|
namespace ErsatzTV.Tests.Application.Search;
|
|
|
|
[TestFixture]
|
|
public class QuerySearchIndexAllItemsHandlerTests
|
|
{
|
|
private ISearchIndex _searchIndex = null!;
|
|
private QuerySearchIndexAllItemsHandler _handler = null!;
|
|
|
|
[SetUp]
|
|
public void SetUp()
|
|
{
|
|
_searchIndex = Substitute.For<ISearchIndex>();
|
|
|
|
// Default every kind's search to an empty page so unconfigured kinds don't NRE.
|
|
_searchIndex.Search(
|
|
Arg.Any<string>(),
|
|
Arg.Any<string>(),
|
|
Arg.Any<int>(),
|
|
Arg.Any<int>(),
|
|
Arg.Any<CancellationToken>())
|
|
.Returns(new SearchResult([], 0));
|
|
|
|
_handler = new QuerySearchIndexAllItemsHandler(_searchIndex);
|
|
}
|
|
|
|
[Test]
|
|
public async Task Handle_Should_Translate_Page_To_Skip_And_Limit()
|
|
{
|
|
await _handler.Handle(new QuerySearchIndexAllItems("star", 2, 50), CancellationToken.None);
|
|
|
|
// Every one of the ten media kinds is queried with skip = pageNum * pageSize, limit = pageSize.
|
|
await _searchIndex.Received(10).Search(
|
|
Arg.Any<string>(),
|
|
string.Empty,
|
|
100,
|
|
50,
|
|
Arg.Any<CancellationToken>());
|
|
await _searchIndex.Received(1).Search(
|
|
Arg.Is<string>(q => q.Contains("type:movie")),
|
|
string.Empty,
|
|
100,
|
|
50,
|
|
Arg.Any<CancellationToken>());
|
|
}
|
|
|
|
[Test]
|
|
public async Task Handle_Should_Return_Ids_And_Per_Kind_Totals()
|
|
{
|
|
_searchIndex.Search(
|
|
Arg.Is<string>(q => q.Contains("type:movie")),
|
|
Arg.Any<string>(),
|
|
Arg.Any<int>(),
|
|
Arg.Any<int>(),
|
|
Arg.Any<CancellationToken>())
|
|
.Returns(new SearchResult(
|
|
[new SearchItem("movie", 1), new SearchItem("movie", 2)],
|
|
7));
|
|
|
|
SearchResultAllItemsViewModel result =
|
|
await _handler.Handle(new QuerySearchIndexAllItems("star", 0, 500), CancellationToken.None);
|
|
|
|
// The bucket holds this page's ids; the total reflects the full hit count (SearchResult.TotalCount),
|
|
// which is what lets a client page to completeness.
|
|
result.MovieIds.ShouldBe(new List<int> { 1, 2 });
|
|
result.Totals.MovieCount.ShouldBe(7);
|
|
|
|
// A kind with no hits returns an empty bucket and a zero total.
|
|
result.ShowIds.ShouldBeEmpty();
|
|
result.Totals.ShowCount.ShouldBe(0);
|
|
}
|
|
}
|