Suppress superseded alerts in the /alerts/active endpoint
All checks were successful
ci/woodpecker/manual/build-image Pipeline was successful
All checks were successful
ci/woodpecker/manual/build-image Pipeline was successful
This commit is contained in:
@@ -272,6 +272,60 @@ func TestServiceLatestActiveAlertRunUsesEndsBeforeExpires(t *testing.T) {
|
||||
assertAlertIDs(t, run, []string{"ends-after-active-expires-before", "expires-fallback"})
|
||||
}
|
||||
|
||||
func TestServiceLatestActiveAlertRunSuppressesReferencedOriginal(t *testing.T) {
|
||||
activeAt := testTime(12)
|
||||
original := testAlert("https://api.weather.gov/alerts/urn:oid:original", "Alert", testTimePtr(9), testTimePtr(10), nil, testTimePtr(13), testTimePtr(13))
|
||||
update := testAlert("https://api.weather.gov/alerts/urn:oid:update", "Update", testTimePtr(11), testTimePtr(11), nil, testTimePtr(13), testTimePtr(13))
|
||||
update.References = []model.AlertReference{{Identifier: "urn:oid:original"}}
|
||||
unrelated := testAlert("https://api.weather.gov/alerts/urn:oid:unrelated", "Alert", testTimePtr(9), testTimePtr(10), nil, testTimePtr(13), testTimePtr(13))
|
||||
repo := &fakeRepository{alerts: testAlertRunWithAlerts([]model.WeatherAlert{original, update, unrelated})}
|
||||
svc := NewService(repo)
|
||||
|
||||
run, err := svc.LatestActiveAlertRun(context.Background(), activeAt)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
assertAlertIDs(t, run, []string{
|
||||
"https://api.weather.gov/alerts/urn:oid:update",
|
||||
"https://api.weather.gov/alerts/urn:oid:unrelated",
|
||||
})
|
||||
}
|
||||
|
||||
func TestServiceLatestActiveAlertRunCancelSuppressesReferencedOriginal(t *testing.T) {
|
||||
activeAt := testTime(12)
|
||||
original := testAlert("https://api.weather.gov/alerts/urn:oid:original", "Alert", testTimePtr(9), testTimePtr(10), nil, testTimePtr(13), testTimePtr(13))
|
||||
cancel := testAlert("https://api.weather.gov/alerts/urn:oid:cancel", "Cancel", testTimePtr(11), testTimePtr(11), nil, testTimePtr(13), testTimePtr(13))
|
||||
cancel.References = []model.AlertReference{{Identifier: "urn:oid:original"}}
|
||||
repo := &fakeRepository{alerts: testAlertRunWithAlerts([]model.WeatherAlert{original, cancel})}
|
||||
svc := NewService(repo)
|
||||
|
||||
run, err := svc.LatestActiveAlertRun(context.Background(), activeAt)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
assertAlertIDs(t, run, []string{})
|
||||
}
|
||||
|
||||
func TestServiceLatestActiveAlertRunReferenceIdentifierPrecedenceAndIDFallback(t *testing.T) {
|
||||
activeAt := testTime(12)
|
||||
fromID := testAlert("urn:oid:from-id", "Alert", testTimePtr(9), testTimePtr(10), nil, testTimePtr(13), testTimePtr(13))
|
||||
fromIdentifier := testAlert("urn:oid:from-identifier", "Alert", testTimePtr(9), testTimePtr(10), nil, testTimePtr(13), testTimePtr(13))
|
||||
idFallback := testAlert("urn:oid:id-fallback", "Alert", testTimePtr(9), testTimePtr(10), nil, testTimePtr(13), testTimePtr(13))
|
||||
update := testAlert("urn:oid:update", "Update", testTimePtr(11), testTimePtr(11), nil, testTimePtr(13), testTimePtr(13))
|
||||
update.References = []model.AlertReference{
|
||||
{ID: "urn:oid:from-id", Identifier: "urn:oid:from-identifier"},
|
||||
{ID: "urn:oid:id-fallback"},
|
||||
}
|
||||
repo := &fakeRepository{alerts: testAlertRunWithAlerts([]model.WeatherAlert{fromID, fromIdentifier, idFallback, update})}
|
||||
svc := NewService(repo)
|
||||
|
||||
run, err := svc.LatestActiveAlertRun(context.Background(), activeAt)
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected error: %v", err)
|
||||
}
|
||||
assertAlertIDs(t, run, []string{"urn:oid:from-id", "urn:oid:update"})
|
||||
}
|
||||
|
||||
func TestServiceDelegatesLatestConvectiveOutlookRun(t *testing.T) {
|
||||
repo := &fakeRepository{outlookRun: testOutlookRun()}
|
||||
svc := NewService(repo)
|
||||
|
||||
Reference in New Issue
Block a user