61c6278bd0
Decision 2.8: preserve-if-null on the server. UpdateSiteCommand, UpdateDataConnectionCommand and UpdateApiMethodCommand fields (except the id) are now nullable; the ManagementActor handlers apply only non-null values and treat an empty string as 'clear this optional field'. The CLI update commands no longer require --name/--protocol/--script and drop the --failover-retry-count (3) and --timeout (30) defaults, so an omitted option travels as null instead of overwriting the stored value (site update --name used to null both gRPC addresses). The site gRPC-address validation now runs on the merged values. Additive/compatible: the fields only became nullable, so an older CLI that always sends every field still deserializes (pinned by a test) and now simply updates every field as before. The Central UI full-entity forms send "" for a field the operator cleared (description/addresses, removed backup endpoint, cleared parameter/return definitions) so clearing keeps working.
103 lines
4.6 KiB
C#
103 lines
4.6 KiB
C#
using Bunit;
|
||
using Bunit.TestDoubles;
|
||
using Microsoft.AspNetCore.Components;
|
||
using Microsoft.Extensions.DependencyInjection;
|
||
using ZB.MOM.WW.ScadaBridge.CentralUI.Components.Audit;
|
||
using ZB.MOM.WW.ScadaBridge.CentralUI.Services;
|
||
using ZB.MOM.WW.ScadaBridge.Commons.Types.Enums;
|
||
|
||
namespace ZB.MOM.WW.ScadaBridge.CentralUI.Tests.Audit;
|
||
|
||
/// <summary>
|
||
/// Flow Debugger drill-ins (design 2026-09-05 §4): the audit drawer's
|
||
/// detail body and the Execution Chain page both offer <em>Open in Flow Debugger</em>,
|
||
/// and the inbound-method form carries the <c>TraceAllCalls</c> checkbox wired to both
|
||
/// save paths.
|
||
/// </summary>
|
||
public class FlowDebuggerDrillinTests : BunitContext
|
||
{
|
||
/// <summary>Initializes the test context with the services the drill-in components need.</summary>
|
||
public FlowDebuggerDrillinTests()
|
||
{
|
||
JSInterop.Mode = JSRuntimeMode.Loose;
|
||
}
|
||
|
||
private static AuditEventView MakeEvent(Guid? executionId) => new()
|
||
{
|
||
EventId = Guid.Parse("11111111-2222-3333-4444-555555555555"),
|
||
OccurredAtUtc = new DateTime(2026, 9, 5, 12, 30, 45, DateTimeKind.Utc),
|
||
IngestedAtUtc = new DateTime(2026, 9, 5, 12, 30, 46, DateTimeKind.Utc),
|
||
Channel = AuditChannel.ApiInbound,
|
||
Kind = AuditKind.InboundRequest,
|
||
ExecutionId = executionId,
|
||
Actor = "tester",
|
||
Target = "POST /api/DelmiaRecipeDownload",
|
||
Status = AuditStatus.Delivered,
|
||
DurationMs = 42,
|
||
};
|
||
|
||
private static string SrcRoot
|
||
{
|
||
get
|
||
{
|
||
var dir = AppContext.BaseDirectory;
|
||
for (var i = 0; i < 6 && dir is not null; i++)
|
||
dir = Directory.GetParent(dir)?.FullName;
|
||
return Path.Combine(dir!, "src", "ZB.MOM.WW.ScadaBridge.CentralUI", "Components");
|
||
}
|
||
}
|
||
|
||
private static string Read(params string[] relative)
|
||
=> File.ReadAllText(Path.Combine([SrcRoot, .. relative]));
|
||
|
||
/// <summary>Verifies that an audit event with an execution id offers an Open in Flow Debugger button that navigates to the replay.</summary>
|
||
[Fact]
|
||
public void AuditEventDetail_WithExecutionId_OffersOpenInFlowDebugger_AndNavigatesToReplay()
|
||
{
|
||
var exec = Guid.Parse("12345678-aaaa-bbbb-cccc-1234567890ab");
|
||
var cut = Render<AuditEventDetail>(p => p.Add(c => c.Event, MakeEvent(exec)));
|
||
|
||
cut.Find("[data-test=\"open-flow-debugger\"]").Click();
|
||
|
||
var nav = (BunitNavigationManager)Services.GetRequiredService<NavigationManager>();
|
||
Assert.Contains($"/deployment/flow-debugger?executionId={exec}", nav.Uri);
|
||
}
|
||
|
||
/// <summary>Verifies that an audit event without an execution id hides the Open in Flow Debugger button.</summary>
|
||
[Fact]
|
||
public void AuditEventDetail_WithoutExecutionId_HidesTheButton()
|
||
{
|
||
var cut = Render<AuditEventDetail>(p => p.Add(c => c.Event, MakeEvent(null)));
|
||
|
||
Assert.DoesNotContain("data-test=\"open-flow-debugger\"", cut.Markup);
|
||
}
|
||
|
||
/// <summary>Verifies that the execution tree page links to the Flow Debugger replay beside the audit log link.</summary>
|
||
[Fact]
|
||
public void ExecutionTreePage_LinksToTheFlowDebuggerReplay_BesideTheAuditLogLink()
|
||
{
|
||
var markup = Read("Pages", "Audit", "ExecutionTreePage.razor");
|
||
|
||
Assert.Contains("data-test=\"open-flow-debugger\"", markup);
|
||
Assert.Contains("/deployment/flow-debugger?executionId={_executionId}", markup);
|
||
// Same block as the existing back-to-log link, so both actions sit together.
|
||
Assert.True(markup.IndexOf("execution-tree-back-to-log", StringComparison.Ordinal)
|
||
< markup.IndexOf("open-flow-debugger", StringComparison.Ordinal));
|
||
}
|
||
|
||
/// <summary>Verifies that the API method form has a trace-all-calls checkbox wired to both the create and update save paths.</summary>
|
||
[Fact]
|
||
public void ApiMethodForm_HasTraceAllCallsCheckbox_WiredToBothSavePaths()
|
||
{
|
||
var markup = Read("Pages", "Design", "ApiMethodForm.razor");
|
||
|
||
Assert.Contains("data-test=\"api-method-trace-all-calls\"", markup);
|
||
Assert.Contains("Trace all calls (Flow Debugger)", markup);
|
||
Assert.Contains("7–10 audit rows per call", markup);
|
||
// Load, update and create paths all carry the flag.
|
||
Assert.Contains("_traceAllCalls = _existing.TraceAllCalls;", markup);
|
||
Assert.Contains("new UpdateApiMethodCommand(_existing.Id, _script, _timeoutSeconds, _params?.Trim() ?? \"\", _returns?.Trim() ?? \"\", _traceAllCalls)", markup);
|
||
Assert.Contains("new CreateApiMethodCommand(methodName, _script, _timeoutSeconds, _params?.Trim(), _returns?.Trim(), _traceAllCalls)", markup);
|
||
}
|
||
}
|