feat(management): secured-write list paging with TotalCount (arch-review P3)

Claude-Session: https://claude.ai/code/session_01MtdgwpEeCUn6cUA5f1LMPj
This commit is contained in:
Joseph Doherty
2026-07-10 05:42:35 -04:00
parent 03295e91bb
commit 8d4ffa7ef1
8 changed files with 195 additions and 8 deletions
@@ -0,0 +1,62 @@
using System.CommandLine;
using ZB.MOM.WW.ScadaBridge.CLI.Commands;
namespace ZB.MOM.WW.ScadaBridge.CLI.Tests.Commands;
/// <summary>
/// PLAN-07 Task 17 (arch-review P3): <c>secured-write list</c> must expose <c>--skip</c>
/// / <c>--take</c> offset-paging options alongside the <c>--status</c> / <c>--site</c>
/// filters, and map them onto <see cref="Commons.Messages.Management.ListSecuredWritesCommand"/>.
/// Omitting the paging flags preserves the historical unpaged default (skip 0, take 200).
/// </summary>
public class SecuredWriteListCommandTests
{
private static readonly Option<string> Url = new("--url") { Recursive = true };
private static readonly Option<string> Format = new("--format") { Recursive = true };
private static readonly Option<string> Username = new("--username") { Recursive = true };
private static readonly Option<string> Password = new("--password") { Recursive = true };
private static Command Group() => SecuredWriteCommands.Build(Url, Format, Username, Password);
private static Command List() => Group().Subcommands.Single(c => c.Name == "list");
private static Option? FindOption(Command command, string name)
=> command.Options.SingleOrDefault(o => o.Name == name);
[Fact]
public void List_HasSkipAndTakeOptions()
{
var list = List();
Assert.NotNull(FindOption(list, "--skip"));
Assert.NotNull(FindOption(list, "--take"));
}
[Fact]
public void List_ParsesSkipTakeAndFilters_ForwardsToCommand()
{
var parse = Group().Parse(new[]
{
"list", "--status", "Pending", "--site", "SITE1", "--skip", "10", "--take", "25",
});
Assert.Empty(parse.Errors);
var command = SecuredWriteCommands.BuildListCommand(parse);
Assert.Equal("Pending", command.Status);
Assert.Equal("SITE1", command.SiteId);
Assert.Equal(10, command.Skip);
Assert.Equal(25, command.Take);
}
[Fact]
public void List_OmittedPaging_UsesUnpagedDefaults()
{
var parse = Group().Parse(new[] { "list" });
Assert.Empty(parse.Errors);
var command = SecuredWriteCommands.BuildListCommand(parse);
Assert.Null(command.Status);
Assert.Null(command.SiteId);
Assert.Equal(0, command.Skip);
Assert.Equal(200, command.Take);
}
}
@@ -613,6 +613,26 @@ public class SecuredWriteHandlerTests : TestKit, IDisposable
Assert.Contains("not found", updated.ExecutionError);
}
// ------------------------------------------------------------------------
// List paging — Task 17 (arch-review P3)
// ------------------------------------------------------------------------
[Fact]
public void List_WithSkipTake_ForwardsPagingAndReturnsTotalCount()
{
_securedWriteRepo.QueryAsync(null, null, 10, 25, Arg.Any<CancellationToken>())
.Returns(new List<PendingSecuredWrite>());
_securedWriteRepo.CountAsync(null, null, 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<CancellationToken>());
_securedWriteRepo.Received(1).CountAsync(null, null, Arg.Any<CancellationToken>());
Assert.Contains("\"totalCount\":87", resp.JsonData);
}
// ------------------------------------------------------------------------
// Opportunistic expiry sweep on list — Task 16 (arch-review S2)
// ------------------------------------------------------------------------