react-code-dataset / goalert /engine /message /dedupconcallnotifications_test.go
Devendra174's picture
Upload folder using huggingface_hub
1e92f2d verified
raw
history blame contribute delete
963 Bytes
package message
import (
"testing"
"time"
"github.com/stretchr/testify/assert"
"github.com/target/goalert/notification"
)
func TestDedupOnCallNotifications(t *testing.T) {
n := time.Now()
msg := []Message{
{
ID: "a",
Type: notification.MessageTypeAlertStatus,
CreatedAt: n,
},
{
ID: "b",
Type: notification.MessageTypeScheduleOnCallUsers,
ScheduleID: "A",
CreatedAt: n.Add(time.Minute),
},
{
ID: "c",
Type: notification.MessageTypeScheduleOnCallUsers,
ScheduleID: "A",
CreatedAt: n.Add(2 * time.Second),
},
{
ID: "d",
Type: notification.MessageTypeScheduleOnCallUsers,
ScheduleID: "B",
CreatedAt: n.Add(time.Second),
},
}
out, toDelete := dedupOnCallNotifications(msg)
assert.Equal(t, []string{"c"}, toDelete)
var ids []string
for _, m := range out {
ids = append(ids, m.ID)
}
assert.Equal(t, []string{"a", "b", "d"}, ids)
}