fix(ui): apply site scope and the history status filter in the server query, before paging (UI-7, UI-9, UI-10, WP1 task 1.7)
UI-7: Site Calls and the Notification report sent an unscoped query and dropped other sites' rows client-side after paging - Site Calls pages went short (Next disabled, own rows hidden), Notifications showed other sites' counts and empty pages. New additive SourceSitesFilter on SiteCallQueryRequest / NotificationOutboxQueryRequest (+ SourceSites / SourceSiteIds on the repository filters; OPENJSON IN-list in the SiteCalls keyset SQL, Contains in EF) carries the permitted identifiers; an empty set matches nothing. Next is gated on the server page size. UI-9: Secured Writes history paged over every status and filtered terminal rows client-side. Additive ListSecuredWritesCommand.Statuses reaches the repository query and count. UI-10: Notification KPIs per-site table is narrowed to the caller's sites (SiteScopeService.Resolve on the principal). Tests: MSSQL mixed-site keyset/offset paging + count for both repos and the secured-write status set; handler forwards Statuses; UI pages send the permitted set (scoped) / none (system-wide); history requests the terminal statuses; KPI per-site rows narrowed.
This commit is contained in:
@@ -57,14 +57,14 @@ public class SecuredWritesTests : BunitContext
|
||||
|
||||
// Empty list by default; individual tests seed the queue/history.
|
||||
_service.ListAsync(
|
||||
Arg.Any<string?>(), Arg.Any<string?>(), Arg.Any<int>(), Arg.Any<int>(), Arg.Any<CancellationToken>())
|
||||
Arg.Any<string?>(), Arg.Any<string?>(), Arg.Any<int>(), Arg.Any<int>(), Arg.Any<IReadOnlyList<string>?>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult(new SecuredWriteListResult(Array.Empty<SecuredWriteDto>(), 0)));
|
||||
}
|
||||
|
||||
/// <summary>Stubs <c>ListAsync</c> (any filter/paging args) to return <paramref name="rows"/>.</summary>
|
||||
private void SeedList(IReadOnlyList<SecuredWriteDto> rows, int? totalCount = null)
|
||||
=> _service.ListAsync(
|
||||
Arg.Any<string?>(), Arg.Any<string?>(), Arg.Any<int>(), Arg.Any<int>(), Arg.Any<CancellationToken>())
|
||||
Arg.Any<string?>(), Arg.Any<string?>(), Arg.Any<int>(), Arg.Any<int>(), Arg.Any<IReadOnlyList<string>?>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult(new SecuredWriteListResult(rows, totalCount ?? rows.Count)));
|
||||
|
||||
/// <summary>
|
||||
@@ -295,7 +295,25 @@ public class SecuredWritesTests : BunitContext
|
||||
|
||||
// The history second-page fetch offsets by one page (skip: 50).
|
||||
_service.Received().ListAsync(
|
||||
Arg.Any<string?>(), Arg.Any<string?>(), 50, Arg.Any<int>(), Arg.Any<CancellationToken>());
|
||||
Arg.Any<string?>(), Arg.Any<string?>(), 50, Arg.Any<int>(), Arg.Any<IReadOnlyList<string>?>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Code review 2026-12-02 UI-9: the history list asks the server for the terminal
|
||||
/// statuses (filter + count in SQL) instead of paging over every status and dropping
|
||||
/// Pending rows client-side.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void History_RequestsTerminalStatuses_ServerSide()
|
||||
{
|
||||
AddAuth("op", "Operator");
|
||||
var cut = RenderPage();
|
||||
|
||||
cut.WaitForAssertion(() => _service.Received().ListAsync(
|
||||
Arg.Is<string?>(x => x == null), Arg.Is<string?>(x => x == null), Arg.Is(0), Arg.Any<int>(),
|
||||
Arg.Is<IReadOnlyList<string>?>(s => s != null
|
||||
&& s.OrderBy(x => x).SequenceEqual(new[] { "Executed", "Expired", "Failed", "Rejected" })),
|
||||
Arg.Any<CancellationToken>()));
|
||||
}
|
||||
|
||||
// ── (e) Approve dialog surfaces submission age (stale-setpoint scenario) ──
|
||||
|
||||
@@ -168,6 +168,44 @@ public class NotificationKpisPageTests : BunitContext
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Code review 2026-12-02 UI-10: a Deployer scoped to Plant A sees only Plant A's per-site
|
||||
/// row, not every site's names, queue depths and parked/stuck counts. A system-wide user
|
||||
/// still sees both.
|
||||
/// </summary>
|
||||
/// <param name="scoped">Whether the caller carries a SiteId claim for Plant A.</param>
|
||||
[Theory]
|
||||
[InlineData(true)]
|
||||
[InlineData(false)]
|
||||
public void PerSiteRows_AreNarrowedToTheCallersSites(bool scoped)
|
||||
{
|
||||
_perSiteReply = new PerSiteNotificationKpiResponse("p", true, null, new List<SiteNotificationKpiSnapshot>
|
||||
{
|
||||
new("plant-a", QueueDepth: 4, StuckCount: 1, ParkedCount: 0,
|
||||
DeliveredLastInterval: 9, OldestPendingAge: TimeSpan.FromMinutes(7)),
|
||||
new("plant-b", QueueDepth: 13, StuckCount: 0, ParkedCount: 3,
|
||||
DeliveredLastInterval: 2, OldestPendingAge: TimeSpan.FromMinutes(1)),
|
||||
});
|
||||
if (scoped)
|
||||
{
|
||||
var scopedUser = new ClaimsPrincipal(new ClaimsIdentity(new[]
|
||||
{
|
||||
new Claim(JwtTokenService.UsernameClaimType, "scoped"),
|
||||
new Claim(JwtTokenService.RoleClaimType, "Deployer"),
|
||||
new Claim(JwtTokenService.SiteIdClaimType, "1"), // Plant A only
|
||||
}, "TestAuth"));
|
||||
Services.AddSingleton<AuthenticationStateProvider>(new TestAuthStateProvider(scopedUser));
|
||||
}
|
||||
|
||||
var cut = Render<NotificationKpisPage>();
|
||||
|
||||
cut.WaitForAssertion(() => Assert.Contains("Plant A", cut.Markup));
|
||||
if (scoped)
|
||||
Assert.DoesNotContain("Plant B", cut.Markup);
|
||||
else
|
||||
Assert.Contains("Plant B", cut.Markup);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that the page shows the per-site empty state when there are no sites.</summary>
|
||||
/// <returns>The result.</returns>
|
||||
[Fact]
|
||||
|
||||
@@ -338,6 +338,38 @@ public class NotificationReportPageTests : BunitContext
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Code review 2026-12-02 UI-7: a scoped user's permitted sites ride the query itself
|
||||
/// (<c>SourceSitesFilter</c>), so the page and the total count cover only in-scope rows;
|
||||
/// a system-wide user sends no such constraint.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void SiteScoping_ScopedUser_PushesPermittedSitesIntoTheQuery()
|
||||
{
|
||||
var scopedUser = new ClaimsPrincipal(new ClaimsIdentity(new[]
|
||||
{
|
||||
new Claim(JwtTokenService.UsernameClaimType, "scoped"),
|
||||
new Claim(JwtTokenService.RoleClaimType, "Deployer"),
|
||||
new Claim(JwtTokenService.SiteIdClaimType, "1"), // Plant A only
|
||||
}, "TestAuth"));
|
||||
Services.AddSingleton<AuthenticationStateProvider>(new TestAuthStateProvider(scopedUser));
|
||||
|
||||
var cut = Render<NotificationReportPage>();
|
||||
|
||||
cut.WaitForAssertion(() => Assert.NotEmpty(_queryRequests));
|
||||
Assert.Equal(new[] { "plant-a" }, _queryRequests[0].SourceSitesFilter);
|
||||
}
|
||||
|
||||
/// <summary>A system-wide user's query carries no permitted-sites constraint.</summary>
|
||||
[Fact]
|
||||
public void SiteScoping_SystemWideUser_SendsNoSitesConstraint()
|
||||
{
|
||||
var cut = Render<NotificationReportPage>();
|
||||
|
||||
cut.WaitForAssertion(() => Assert.NotEmpty(_queryRequests));
|
||||
Assert.Null(_queryRequests[0].SourceSitesFilter);
|
||||
}
|
||||
|
||||
/// <summary>Verifies that clearing the notification filter pill drops the filter and re-queries.</summary>
|
||||
[Fact]
|
||||
public void NotificationFilterPill_Clear_DropsTheFilterAndRequeries()
|
||||
|
||||
@@ -663,6 +663,38 @@ public class SiteCallsReportPageTests : BunitContext
|
||||
Assert.DoesNotContain(FailedId.ToString("N")[..12], cut.Markup);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Code review 2026-12-02 UI-7: a scoped user's permitted sites ride the query itself
|
||||
/// (<c>SourceSitesFilter</c>), so keyset paging runs over in-scope rows; a system-wide
|
||||
/// user sends no such constraint.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void SiteScoping_ScopedUser_PushesPermittedSitesIntoTheQuery()
|
||||
{
|
||||
var scopedUser = new ClaimsPrincipal(new ClaimsIdentity(new[]
|
||||
{
|
||||
new Claim(JwtTokenService.UsernameClaimType, "scoped"),
|
||||
new Claim(JwtTokenService.RoleClaimType, "Deployer"),
|
||||
new Claim(JwtTokenService.SiteIdClaimType, "1"), // Plant A only
|
||||
}, "TestAuth"));
|
||||
Services.AddSingleton<AuthenticationStateProvider>(new TestAuthStateProvider(scopedUser));
|
||||
|
||||
var cut = Render<SiteCallsReportPage>();
|
||||
|
||||
cut.WaitForAssertion(() => Assert.NotEmpty(_queryRequests));
|
||||
Assert.Equal(new[] { "plant-a" }, _queryRequests[0].SourceSitesFilter);
|
||||
}
|
||||
|
||||
/// <summary>A system-wide user's query carries no permitted-sites constraint.</summary>
|
||||
[Fact]
|
||||
public void SiteScoping_SystemWideUser_SendsNoSitesConstraint()
|
||||
{
|
||||
var cut = Render<SiteCallsReportPage>();
|
||||
|
||||
cut.WaitForAssertion(() => Assert.NotEmpty(_queryRequests));
|
||||
Assert.Null(_queryRequests[0].SourceSitesFilter);
|
||||
}
|
||||
|
||||
// ─────────────────────────────────────────────────────────────────────────
|
||||
// Trends (K14) — a collapsible section with one KpiTrendChart per metric
|
||||
// (buffered / parked / failedLastInterval) for SiteCallAudit / Global. The
|
||||
|
||||
+46
-3
@@ -139,6 +139,47 @@ public class NotificationOutboxRepositoryIntegrationTests : IClassFixture<MsSqlM
|
||||
Assert.Equal("Wanted", row.Subject);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Code review 2026-12-02 UI-7: the permitted-sites filter is applied in the query, so the
|
||||
/// page AND the total count cover only rows the scoped caller may see (pre-fix the count
|
||||
/// included every site and pages came back partly or wholly empty after client filtering).
|
||||
/// </summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[SkippableFact]
|
||||
public async Task QueryAsync_SourceSiteIdsFilter_PagesAndCountsInScopeRowsOnly()
|
||||
{
|
||||
Skip.IfNot(_fixture.Available, _fixture.SkipReason);
|
||||
|
||||
var mine = "site-ui7-" + Guid.NewGuid().ToString("N")[..8];
|
||||
var other = "site-ui7-" + Guid.NewGuid().ToString("N")[..8];
|
||||
await using (var context = CreateContext())
|
||||
{
|
||||
var repo = new NotificationOutboxRepository(context);
|
||||
for (var i = 0; i < 3; i++)
|
||||
await repo.InsertIfNotExistsAsync(MakeNotification(Guid.NewGuid().ToString(), sourceSiteId: mine, minutes: i));
|
||||
for (var i = 0; i < 7; i++)
|
||||
await repo.InsertIfNotExistsAsync(MakeNotification(Guid.NewGuid().ToString(), sourceSiteId: other, minutes: 10 + i));
|
||||
}
|
||||
|
||||
await using var queryContext = CreateContext();
|
||||
var queryRepo = new NotificationOutboxRepository(queryContext);
|
||||
var (rows, totalCount) = await queryRepo.QueryAsync(
|
||||
new NotificationOutboxFilter(SourceSiteIds: new[] { mine }), pageNumber: 1, pageSize: 2);
|
||||
|
||||
Assert.Equal(3, totalCount);
|
||||
Assert.Equal(2, rows.Count);
|
||||
Assert.All(rows, r => Assert.Equal(mine, r.SourceSiteId));
|
||||
|
||||
var (page2, _) = await queryRepo.QueryAsync(
|
||||
new NotificationOutboxFilter(SourceSiteIds: new[] { mine }), pageNumber: 2, pageSize: 2);
|
||||
Assert.Equal(mine, Assert.Single(page2).SourceSiteId);
|
||||
|
||||
var (none, noneCount) = await queryRepo.QueryAsync(
|
||||
new NotificationOutboxFilter(SourceSiteIds: Array.Empty<string>()), pageNumber: 1, pageSize: 50);
|
||||
Assert.Empty(none);
|
||||
Assert.Equal(0, noneCount);
|
||||
}
|
||||
|
||||
// --- helpers ------------------------------------------------------------
|
||||
|
||||
private ScadaBridgeDbContext CreateContext()
|
||||
@@ -152,7 +193,9 @@ public class NotificationOutboxRepositoryIntegrationTests : IClassFixture<MsSqlM
|
||||
private static Notification MakeNotification(
|
||||
string id,
|
||||
NotificationStatus status = NotificationStatus.Pending,
|
||||
string subject = "Subject")
|
||||
string subject = "Subject",
|
||||
string sourceSiteId = "site-cd015",
|
||||
int minutes = 0)
|
||||
{
|
||||
return new Notification(
|
||||
id,
|
||||
@@ -160,10 +203,10 @@ public class NotificationOutboxRepositoryIntegrationTests : IClassFixture<MsSqlM
|
||||
"Ops List",
|
||||
subject,
|
||||
"Body",
|
||||
"site-cd015")
|
||||
sourceSiteId)
|
||||
{
|
||||
Status = status,
|
||||
CreatedAt = new DateTimeOffset(2026, 5, 20, 10, 0, 0, TimeSpan.Zero),
|
||||
CreatedAt = new DateTimeOffset(2026, 5, 20, 10, 0, 0, TimeSpan.Zero).AddMinutes(minutes),
|
||||
SiteEnqueuedAt = new DateTimeOffset(2026, 5, 20, 9, 59, 0, TimeSpan.Zero),
|
||||
};
|
||||
}
|
||||
|
||||
+40
@@ -489,6 +489,46 @@ public class SiteCallAuditRepositoryTests : IClassFixture<MsSqlMigrationFixture>
|
||||
Assert.All(rows, r => Assert.Equal(siteA, r.SourceSite));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Code review 2026-12-02 UI-7: a site-scoped caller's permitted set is applied in the
|
||||
/// query, so keyset paging runs over in-scope rows only. Mixed data where the OTHER site
|
||||
/// produces most of the traffic must still yield full in-scope pages and a cursor that
|
||||
/// reaches every in-scope row.
|
||||
/// </summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[SkippableFact]
|
||||
public async Task QueryAsync_SourceSitesFilter_PagesOverInScopeRowsOnly()
|
||||
{
|
||||
Skip.IfNot(_fixture.Available, _fixture.SkipReason);
|
||||
|
||||
var mine = NewSiteId();
|
||||
var other = NewSiteId();
|
||||
await using var context = CreateContext();
|
||||
var repo = new SiteCallAuditRepository(context);
|
||||
|
||||
// Newest-first order: 6 rows of the other site sit ON TOP of 5 of mine, interleaved.
|
||||
var t0 = new DateTime(2026, 6, 1, 10, 0, 0, DateTimeKind.Utc);
|
||||
for (var i = 0; i < 5; i++)
|
||||
await repo.UpsertAsync(NewRow(TrackedOperationId.New(), sourceSite: mine, createdAtUtc: t0.AddMinutes(i)));
|
||||
for (var i = 0; i < 6; i++)
|
||||
await repo.UpsertAsync(NewRow(TrackedOperationId.New(), sourceSite: other, createdAtUtc: t0.AddMinutes(10 + i)));
|
||||
|
||||
var scope = new SiteCallQueryFilter(SourceSites: new[] { mine });
|
||||
var page1 = await repo.QueryAsync(scope, new SiteCallPaging(PageSize: 3));
|
||||
Assert.Equal(3, page1.Count); // full page, not 0 (pre-fix: other site's rows)
|
||||
Assert.All(page1, r => Assert.Equal(mine, r.SourceSite));
|
||||
|
||||
var last = page1[^1];
|
||||
var page2 = await repo.QueryAsync(scope, new SiteCallPaging(
|
||||
PageSize: 3, AfterCreatedAtUtc: last.CreatedAtUtc, AfterId: last.TrackedOperationId));
|
||||
Assert.Equal(2, page2.Count);
|
||||
Assert.All(page2, r => Assert.Equal(mine, r.SourceSite));
|
||||
|
||||
// Empty permitted set matches nothing (fail closed), and composes with SourceSite.
|
||||
Assert.Empty(await repo.QueryAsync(new SiteCallQueryFilter(SourceSites: Array.Empty<string>()), new SiteCallPaging(PageSize: 50)));
|
||||
Assert.Empty(await repo.QueryAsync(new SiteCallQueryFilter(SourceSite: other, SourceSites: new[] { mine }), new SiteCallPaging(PageSize: 50)));
|
||||
}
|
||||
|
||||
/// <summary>Verifies that filtering by tracked operation id returns exactly that row.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[SkippableFact]
|
||||
|
||||
+27
@@ -286,6 +286,33 @@ public class SecuredWriteRepositoryTests : IClassFixture<MsSqlMigrationFixture>
|
||||
Assert.Equal(0, await repo.CountAsync(status: "Executed", siteId: siteId));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Code review 2026-12-02 UI-9: the history asks for the terminal statuses, applied in SQL
|
||||
/// before paging and counting, so Pending rows neither take page slots nor inflate the
|
||||
/// total that drives the pager.
|
||||
/// </summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[SkippableFact]
|
||||
public async Task QueryAndCount_StatusesFilter_PageAndCountOnlyThoseStatuses()
|
||||
{
|
||||
Skip.IfNot(_fixture.Available, _fixture.SkipReason);
|
||||
|
||||
var siteId = NewSiteId();
|
||||
await using var context = CreateContext();
|
||||
var repo = new SecuredWriteRepository(context);
|
||||
for (var i = 0; i < 4; i++) await repo.AddAsync(NewRow(siteId, status: "Pending"));
|
||||
await repo.AddAsync(NewRow(siteId, status: "Executed"));
|
||||
await repo.AddAsync(NewRow(siteId, status: "Rejected"));
|
||||
await repo.AddAsync(NewRow(siteId, status: "Expired"));
|
||||
|
||||
string[] terminal = ["Executed", "Failed", "Rejected", "Expired"];
|
||||
var page = await repo.QueryAsync(null, siteId, skip: 0, take: 2, statuses: terminal);
|
||||
Assert.Equal(2, page.Count);
|
||||
Assert.All(page, r => Assert.Contains(r.Status, terminal));
|
||||
Assert.Equal(3, await repo.CountAsync(null, siteId, statuses: terminal));
|
||||
Assert.Equal(7, await repo.CountAsync(null, siteId));
|
||||
}
|
||||
|
||||
/// <summary>Verifies that a query with permitted site ids returns only rows for those sites.</summary>
|
||||
/// <returns>A task that represents the asynchronous operation.</returns>
|
||||
[SkippableFact]
|
||||
|
||||
@@ -185,7 +185,7 @@ public class ManagementActorTests : TestKit, IDisposable
|
||||
var securedWriteRepo = Substitute.For<ISecuredWriteRepository>();
|
||||
securedWriteRepo.QueryAsync(
|
||||
Arg.Any<string?>(), Arg.Any<string?>(), Arg.Any<int>(), Arg.Any<int>(),
|
||||
Arg.Any<IReadOnlyCollection<string>?>(), Arg.Any<CancellationToken>())
|
||||
Arg.Any<IReadOnlyCollection<string>?>(), Arg.Any<IReadOnlyCollection<string>?>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Task.FromResult<IReadOnlyList<PendingSecuredWrite>>(
|
||||
Array.Empty<PendingSecuredWrite>()));
|
||||
_services.AddScoped(_ => securedWriteRepo);
|
||||
|
||||
@@ -469,7 +469,7 @@ public class SecuredWriteHandlerTests : TestKit, IDisposable
|
||||
[Fact]
|
||||
public void List_FiltersByStatusAndSite()
|
||||
{
|
||||
_securedWriteRepo.QueryAsync("Pending", "SITE1", 0, 200, Arg.Any<IReadOnlyCollection<string>?>(), Arg.Any<CancellationToken>())
|
||||
_securedWriteRepo.QueryAsync("Pending", "SITE1", 0, 200, Arg.Any<IReadOnlyCollection<string>?>(), Arg.Any<IReadOnlyCollection<string>?>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new List<PendingSecuredWrite>
|
||||
{
|
||||
new()
|
||||
@@ -492,14 +492,14 @@ public class SecuredWriteHandlerTests : TestKit, IDisposable
|
||||
Assert.Equal(envelope.CorrelationId, response.CorrelationId);
|
||||
Assert.Contains("\"id\":3", response.JsonData);
|
||||
Assert.Contains("alice", response.JsonData);
|
||||
_securedWriteRepo.Received(1).QueryAsync("Pending", "SITE1", 0, 200, Arg.Any<IReadOnlyCollection<string>?>(), Arg.Any<CancellationToken>());
|
||||
_securedWriteRepo.Received(1).QueryAsync("Pending", "SITE1", 0, 200, Arg.Any<IReadOnlyCollection<string>?>(), Arg.Any<IReadOnlyCollection<string>?>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
/// <summary>Verifies that listing with no filters passes nulls to the repository.</summary>
|
||||
[Fact]
|
||||
public void List_NoFilters_PassesNullsToRepository()
|
||||
{
|
||||
_securedWriteRepo.QueryAsync(null, null, 0, 200, Arg.Any<IReadOnlyCollection<string>?>(), Arg.Any<CancellationToken>())
|
||||
_securedWriteRepo.QueryAsync(null, null, 0, 200, Arg.Any<IReadOnlyCollection<string>?>(), Arg.Any<IReadOnlyCollection<string>?>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new List<PendingSecuredWrite>());
|
||||
|
||||
var actor = CreateActor();
|
||||
@@ -509,7 +509,7 @@ public class SecuredWriteHandlerTests : TestKit, IDisposable
|
||||
actor.Tell(envelope);
|
||||
|
||||
ExpectMsg<ManagementSuccess>(TimeSpan.FromSeconds(5));
|
||||
_securedWriteRepo.Received(1).QueryAsync(null, null, 0, 200, Arg.Any<IReadOnlyCollection<string>?>(), Arg.Any<CancellationToken>());
|
||||
_securedWriteRepo.Received(1).QueryAsync(null, null, 0, 200, Arg.Any<IReadOnlyCollection<string>?>(), Arg.Any<IReadOnlyCollection<string>?>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
/// <summary>Verifies that a site-scoped reader requesting an out-of-scope site is unauthorized.</summary>
|
||||
@@ -532,14 +532,14 @@ public class SecuredWriteHandlerTests : TestKit, IDisposable
|
||||
new("Site3", "SITE3") { Id = 3 },
|
||||
});
|
||||
_securedWriteRepo.QueryAsync(null, null, 0, 200,
|
||||
Arg.Any<IReadOnlyCollection<string>?>(), Arg.Any<CancellationToken>())
|
||||
Arg.Any<IReadOnlyCollection<string>?>(), Arg.Any<IReadOnlyCollection<string>?>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new List<PendingSecuredWrite>());
|
||||
var actor = CreateActor();
|
||||
actor.Tell(ScopedEnvelope(new ListSecuredWritesCommand(null, null), "bob", ["3"], "Verifier"));
|
||||
ExpectMsg<ManagementSuccess>(TimeSpan.FromSeconds(5));
|
||||
_securedWriteRepo.Received(1).QueryAsync(null, null, 0, 200,
|
||||
Arg.Is<IReadOnlyCollection<string>?>(s => s != null && s.Single() == "SITE3"),
|
||||
Arg.Any<CancellationToken>());
|
||||
Arg.Any<IReadOnlyCollection<string>?>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
/// <summary>Verifies that a system-wide reader passes a null permitted-sites filter.</summary>
|
||||
@@ -547,14 +547,14 @@ public class SecuredWriteHandlerTests : TestKit, IDisposable
|
||||
public void List_SystemWideReader_PassesNullPermittedFilter()
|
||||
{
|
||||
_securedWriteRepo.QueryAsync(null, null, 0, 200,
|
||||
Arg.Any<IReadOnlyCollection<string>?>(), Arg.Any<CancellationToken>())
|
||||
Arg.Any<IReadOnlyCollection<string>?>(), Arg.Any<IReadOnlyCollection<string>?>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new List<PendingSecuredWrite>());
|
||||
var actor = CreateActor();
|
||||
actor.Tell(Envelope(new ListSecuredWritesCommand(null, null), "carol", "Operator"));
|
||||
ExpectMsg<ManagementSuccess>(TimeSpan.FromSeconds(5));
|
||||
_securedWriteRepo.Received(1).QueryAsync(null, null, 0, 200,
|
||||
Arg.Is<IReadOnlyCollection<string>?>(s => s == null),
|
||||
Arg.Any<CancellationToken>());
|
||||
Arg.Any<IReadOnlyCollection<string>?>(), Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
@@ -802,19 +802,41 @@ public class SecuredWriteHandlerTests : TestKit, IDisposable
|
||||
[Fact]
|
||||
public void List_WithSkipTake_ForwardsPagingAndReturnsTotalCount()
|
||||
{
|
||||
_securedWriteRepo.QueryAsync(null, null, 10, 25, Arg.Any<IReadOnlyCollection<string>?>(), Arg.Any<CancellationToken>())
|
||||
_securedWriteRepo.QueryAsync(null, null, 10, 25, Arg.Any<IReadOnlyCollection<string>?>(), Arg.Any<IReadOnlyCollection<string>?>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new List<PendingSecuredWrite>());
|
||||
_securedWriteRepo.CountAsync(null, null, Arg.Any<IReadOnlyCollection<string>?>(), Arg.Any<CancellationToken>()).Returns(87);
|
||||
_securedWriteRepo.CountAsync(null, null, Arg.Any<IReadOnlyCollection<string>?>(), Arg.Any<IReadOnlyCollection<string>?>(), Arg.Any<CancellationToken>()).Returns(87);
|
||||
|
||||
var actor = CreateActor();
|
||||
actor.Tell(Envelope(new ListSecuredWritesCommand(null, null, Skip: 10, Take: 25), "carol", "Operator"));
|
||||
|
||||
var resp = ExpectMsg<ManagementSuccess>(TimeSpan.FromSeconds(5));
|
||||
_securedWriteRepo.Received(1).QueryAsync(null, null, 10, 25, Arg.Any<IReadOnlyCollection<string>?>(), Arg.Any<CancellationToken>());
|
||||
_securedWriteRepo.Received(1).CountAsync(null, null, Arg.Any<IReadOnlyCollection<string>?>(), Arg.Any<CancellationToken>());
|
||||
_securedWriteRepo.Received(1).QueryAsync(null, null, 10, 25, Arg.Any<IReadOnlyCollection<string>?>(), Arg.Any<IReadOnlyCollection<string>?>(), Arg.Any<CancellationToken>());
|
||||
_securedWriteRepo.Received(1).CountAsync(null, null, Arg.Any<IReadOnlyCollection<string>?>(), Arg.Any<IReadOnlyCollection<string>?>(), Arg.Any<CancellationToken>());
|
||||
Assert.Contains("\"totalCount\":87", resp.JsonData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Code review 2026-12-02 UI-9: a <c>Statuses</c> set on the command reaches both the
|
||||
/// page query and the count, so the history's terminal filter runs in SQL.
|
||||
/// </summary>
|
||||
[Fact]
|
||||
public void List_WithStatuses_ForwardsTheSetToQueryAndCount()
|
||||
{
|
||||
string[] terminal = ["Executed", "Failed", "Rejected", "Expired"];
|
||||
_securedWriteRepo.QueryAsync(null, null, 0, 50, Arg.Any<IReadOnlyCollection<string>?>(), Arg.Any<IReadOnlyCollection<string>?>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new List<PendingSecuredWrite>());
|
||||
_securedWriteRepo.CountAsync(null, null, Arg.Any<IReadOnlyCollection<string>?>(), Arg.Any<IReadOnlyCollection<string>?>(), Arg.Any<CancellationToken>()).Returns(3);
|
||||
|
||||
var actor = CreateActor();
|
||||
actor.Tell(Envelope(new ListSecuredWritesCommand(null, null, Skip: 0, Take: 50, Statuses: terminal), "carol", "Operator"));
|
||||
|
||||
ExpectMsg<ManagementSuccess>(TimeSpan.FromSeconds(5));
|
||||
_securedWriteRepo.Received(1).QueryAsync(null, null, 0, 50, Arg.Any<IReadOnlyCollection<string>?>(),
|
||||
Arg.Is<IReadOnlyCollection<string>?>(s => s != null && s.SequenceEqual(terminal)), Arg.Any<CancellationToken>());
|
||||
_securedWriteRepo.Received(1).CountAsync(null, null, Arg.Any<IReadOnlyCollection<string>?>(),
|
||||
Arg.Is<IReadOnlyCollection<string>?>(s => s != null && s.SequenceEqual(terminal)), Arg.Any<CancellationToken>());
|
||||
}
|
||||
|
||||
// ------------------------------------------------------------------------
|
||||
// Opportunistic expiry sweep on list
|
||||
// ------------------------------------------------------------------------
|
||||
@@ -835,7 +857,7 @@ public class SecuredWriteHandlerTests : TestKit, IDisposable
|
||||
ValueJson = "false", ValueType = "Boolean", Status = "Pending",
|
||||
OperatorUser = "alice", SubmittedAtUtc = DateTime.UtcNow.AddHours(-25) // TTL default 24h
|
||||
};
|
||||
_securedWriteRepo.QueryAsync(null, null, 0, 200, Arg.Any<IReadOnlyCollection<string>?>(), Arg.Any<CancellationToken>())
|
||||
_securedWriteRepo.QueryAsync(null, null, 0, 200, Arg.Any<IReadOnlyCollection<string>?>(), Arg.Any<IReadOnlyCollection<string>?>(), Arg.Any<CancellationToken>())
|
||||
.Returns(new List<PendingSecuredWrite> { fresh, stale });
|
||||
_securedWriteRepo.TryMarkExpiredAsync(2, Arg.Any<DateTime>(), Arg.Any<CancellationToken>())
|
||||
.Returns(true);
|
||||
|
||||
+1
-1
@@ -26,7 +26,7 @@ public class SecuredWriteTerminalPurgeTests : TestKit
|
||||
{
|
||||
_services.AddScoped(_ => _repo);
|
||||
_repo.QueryAsync(Arg.Any<string?>(), Arg.Any<string?>(), Arg.Any<int>(), Arg.Any<int>(),
|
||||
Arg.Any<IReadOnlyCollection<string>?>(), Arg.Any<CancellationToken>())
|
||||
Arg.Any<IReadOnlyCollection<string>?>(), Arg.Any<IReadOnlyCollection<string>?>(), Arg.Any<CancellationToken>())
|
||||
.Returns(Array.Empty<PendingSecuredWrite>());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user