test(gateway): cover failback reason, FromFeed/SinceUtc badge paths; style + bounded drain (Tests-032..035)

This commit is contained in:
Joseph Doherty
2026-06-15 02:46:06 -04:00
parent b57d02cc4d
commit 56dd56954b
5 changed files with 328 additions and 15 deletions
@@ -1,3 +1,4 @@
using Google.Protobuf.WellKnownTypes;
using ZB.MOM.WW.MxGateway.Contracts.Proto;
using ZB.MOM.WW.MxGateway.Contracts.Proto.Galaxy;
using ZB.MOM.WW.MxGateway.Server.Dashboard;
@@ -170,6 +171,94 @@ public sealed class DashboardBrowseAndAlarmModelTests
Assert.True(model.IsDegraded);
Assert.Contains("bg-warning", model.BadgeCssClass, StringComparison.Ordinal);
Assert.Equal("x", model.Reason);
// Tests-033: pin the amber label text, not just the CSS class — a label swap
// would otherwise pass this test.
Assert.Equal(DashboardAlarmProviderStatus.DegradedLabel, model.Label);
}
/// <summary>
/// Tests-033: an explicitly-degraded status whose mode is still Alarmmgr (the
/// <c>Degraded || Mode==Subtag</c> guard's second, independent branch) must still
/// map to the degraded amber badge.
/// </summary>
[Fact]
public void FromProviderStatus_Alarmmgr_DegradedFlagSet_WarningBadge()
{
AlarmProviderStatus status = new()
{
Mode = AlarmProviderMode.Alarmmgr,
Degraded = true,
Reason = "independently degraded",
};
DashboardAlarmProviderStatus model = DashboardAlarmProviderStatus.FromProviderStatus(status);
Assert.True(model.IsDegraded);
Assert.Equal(DashboardAlarmProviderStatus.DegradedLabel, model.Label);
Assert.Contains("bg-warning", model.BadgeCssClass, StringComparison.Ordinal);
}
/// <summary>
/// Tests-033: the <c>SinceUtc</c> field must carry the protobuf <c>Since</c>
/// timestamp converted to a <see cref="DateTimeOffset" />.
/// </summary>
[Fact]
public void FromProviderStatus_WithSinceTimestamp_MapsSinceUtc()
{
DateTimeOffset since = new(2026, 6, 15, 12, 30, 0, TimeSpan.Zero);
AlarmProviderStatus status = new()
{
Mode = AlarmProviderMode.Subtag,
Degraded = true,
Reason = "x",
Since = Timestamp.FromDateTimeOffset(since),
};
DashboardAlarmProviderStatus model = DashboardAlarmProviderStatus.FromProviderStatus(status);
Assert.Equal(since, model.SinceUtc);
}
/// <summary>
/// Tests-033: <see cref="DashboardAlarmProviderStatus.FromFeed" /> — the entry the
/// dashboard SignalR snapshot path actually calls — projects a provider-status
/// feed message into the badge model.
/// </summary>
[Fact]
public void FromFeed_ProviderStatusPayload_ProjectsBadge()
{
AlarmFeedMessage message = new()
{
ProviderStatus = new AlarmProviderStatus
{
Mode = AlarmProviderMode.Subtag,
Degraded = true,
Reason = "alarmmgr failed",
},
};
DashboardAlarmProviderStatus model = DashboardAlarmProviderStatus.FromFeed(message);
Assert.Equal(AlarmProviderMode.Subtag, model.Mode);
Assert.True(model.IsDegraded);
Assert.Equal(DashboardAlarmProviderStatus.DegradedLabel, model.Label);
Assert.Equal("alarmmgr failed", model.Reason);
}
/// <summary>
/// Tests-033: <see cref="DashboardAlarmProviderStatus.FromFeed" /> throws
/// <see cref="ArgumentException" /> when the feed message does not carry a
/// provider-status payload.
/// </summary>
[Fact]
public void FromFeed_NonProviderStatusPayload_Throws()
{
AlarmFeedMessage message = new()
{
SnapshotComplete = true,
};
Assert.Throws<ArgumentException>(() => DashboardAlarmProviderStatus.FromFeed(message));
}
/// <summary>