File size: 963 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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)
}