-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpinganomaly_test.go
228 lines (222 loc) · 23.1 KB
/
pinganomaly_test.go
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
package main
import (
"testing"
"time"
"github.com/asendia/salmonping/db"
"github.com/google/uuid"
"github.com/jackc/pgx/v5/pgtype"
"github.com/stretchr/testify/assert"
)
func TestGetPingAnomalies(t *testing.T) {
loc, err := time.LoadLocation("Asia/Jakarta")
if err != nil {
t.Fatal(err)
}
today09_59 := time.Date(time.Now().Year(), time.Now().Month(), time.Now().Day(), 9, 59, 0, 0, loc)
today10_01 := time.Date(time.Now().Year(), time.Now().Month(), time.Now().Day(), 10, 1, 0, 0, loc)
today10_11 := time.Date(time.Now().Year(), time.Now().Month(), time.Now().Day(), 10, 11, 0, 0, loc)
today10_21 := time.Date(time.Now().Year(), time.Now().Month(), time.Now().Day(), 10, 21, 0, 0, loc)
today10_31 := time.Date(time.Now().Year(), time.Now().Month(), time.Now().Day(), 10, 31, 0, 0, loc)
today10_41 := time.Date(time.Now().Year(), time.Now().Month(), time.Now().Day(), 10, 41, 0, 0, loc)
today19_51 := time.Date(time.Now().Year(), time.Now().Month(), time.Now().Day(), 19, 51, 0, 0, loc)
today19_59 := time.Date(time.Now().Year(), time.Now().Month(), time.Now().Day(), 19, 59, 0, 0, loc)
today20_01 := time.Date(time.Now().Year(), time.Now().Month(), time.Now().Day(), 20, 1, 0, 0, loc)
today20_11 := time.Date(time.Now().Year(), time.Now().Month(), time.Now().Day(), 20, 11, 0, 0, loc)
dayOfWeek := today10_01.Weekday()
uuid1 := pgtype.UUID{Bytes: uuid.New(), Valid: true}
uuid2 := pgtype.UUID{Bytes: uuid.New(), Valid: true}
uuid3 := pgtype.UUID{Bytes: uuid.New(), Valid: true}
uuid4 := pgtype.UUID{Bytes: uuid.New(), Valid: true}
schedules := []db.SelectOnlineListingSchedulesRow{
{OnlineListingID: uuid1, OpeningTime: pgtype.Time{Microseconds: toMicrosSinceMidnight(today10_01), Valid: true}, ClosingTime: pgtype.Time{Microseconds: toMicrosSinceMidnight(today20_01), Valid: true}, DayOfWeek: int32(dayOfWeek), Name: "Gofood: Resto A", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid2, OpeningTime: pgtype.Time{Microseconds: toMicrosSinceMidnight(today10_01), Valid: true}, ClosingTime: pgtype.Time{Microseconds: toMicrosSinceMidnight(today20_01), Valid: true}, DayOfWeek: int32(dayOfWeek), Name: "Gofood: Resto B", Platform: "gofood", Url: "https://gofood.com/resto-b"},
{OnlineListingID: uuid3, OpeningTime: pgtype.Time{Microseconds: toMicrosSinceMidnight(today10_01), Valid: true}, ClosingTime: pgtype.Time{Microseconds: toMicrosSinceMidnight(today20_01), Valid: true}, DayOfWeek: int32(dayOfWeek), Name: "Gofood: Resto C", Platform: "gofood", Url: "https://gofood.com/resto-c"},
{OnlineListingID: uuid4, OpeningTime: pgtype.Time{Microseconds: toMicrosSinceMidnight(today10_01), Valid: true}, ClosingTime: pgtype.Time{Microseconds: toMicrosSinceMidnight(today20_01), Valid: true}, DayOfWeek: int32(dayOfWeek), Name: "Grabfood: Resto A", Platform: "grabfood", Url: "https://grabfood.com/resto-a"},
}
// Define test cases
testCases := []struct {
name string
schedules []db.SelectOnlineListingSchedulesRow
pings []db.SelectOnlineListingPingsRow
expected []db.SelectOnlineListingPingsRow
}{
{
name: "anomalies: (1) Gofood: Resto A open -> closed, (2) Grabfood: Resto A closed first ping",
schedules: schedules,
pings: []db.SelectOnlineListingPingsRow{
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_21, Valid: true}, Status: "closed", Name: "Gofood: Resto A", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_21, Valid: true}, Status: "open", Name: "Gofood: Resto B", Platform: "gofood", Url: "https://gofood.com/resto-b"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_21, Valid: true}, Status: "closed", Name: "Grabfood: Resto A", Platform: "gofood", Url: "https://grabfood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_11, Valid: true}, Status: "open", Name: "Gofood: Resto A", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_11, Valid: true}, Status: "open", Name: "Gofood: Resto B", Platform: "gofood", Url: "https://gofood.com/resto-b"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today09_59, Valid: true}, Status: "closed", Name: "Gofood: Resto A", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today09_59, Valid: true}, Status: "closed", Name: "Gofood: Resto B", Platform: "gofood", Url: "https://gofood.com/resto-b"},
},
expected: []db.SelectOnlineListingPingsRow{
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_21, Valid: true}, Status: "closed", Name: "Gofood: Resto A", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_21, Valid: true}, Status: "closed", Name: "Grabfood: Resto A", Platform: "gofood", Url: "https://grabfood.com/resto-a"},
},
},
{
name: "anomalies: Gofood: Resto A & C closed first ping",
schedules: schedules,
pings: []db.SelectOnlineListingPingsRow{
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_11, Valid: true}, Status: "closed", Name: "Gofood: Resto A", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_11, Valid: true}, Status: "open", Name: "Gofood: Resto B", Platform: "gofood", Url: "https://gofood.com/resto-b"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_11, Valid: true}, Status: "closed", Name: "Gofood: Resto C", Platform: "gofood", Url: "https://gofood.com/resto-c"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_11, Valid: true}, Status: "open", Name: "Grabfood: Resto A", Platform: "gofood", Url: "https://grabfood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today09_59, Valid: true}, Status: "closed", Name: "Gofood: Resto B", Platform: "gofood", Url: "https://gofood.com/resto-b"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today09_59, Valid: true}, Status: "closed", Name: "Grabfood: Resto A", Platform: "gofood", Url: "https://grabfood.com/resto-a"},
},
expected: []db.SelectOnlineListingPingsRow{
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_11, Valid: true}, Status: "closed", Name: "Gofood: Resto A", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_11, Valid: true}, Status: "closed", Name: "Gofood: Resto C", Platform: "gofood", Url: "https://gofood.com/resto-c"},
},
},
{
name: "anomalies: Gofood: unknown 3 times in a row",
schedules: schedules,
pings: []db.SelectOnlineListingPingsRow{
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_41, Valid: true}, Status: "unknown", Name: "Gofood: Resto A", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_31, Valid: true}, Status: "unknown", Name: "Gofood: Resto A", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_31, Valid: true}, Status: "unknown", Name: "Gofood: Resto C", Platform: "gofood", Url: "https://gofood.com/resto-c"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_21, Valid: true}, Status: "unknown", Name: "Gofood: Resto A", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_21, Valid: true}, Status: "unknown", Name: "Gofood: Resto C", Platform: "gofood", Url: "https://gofood.com/resto-c"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_11, Valid: true}, Status: "open", Name: "Gofood: Resto A", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_11, Valid: true}, Status: "closed", Name: "Gofood: Resto B", Platform: "gofood", Url: "https://gofood.com/resto-b"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_11, Valid: true}, Status: "unknown", Name: "Gofood: Resto C", Platform: "gofood", Url: "https://gofood.com/resto-c"},
},
expected: []db.SelectOnlineListingPingsRow{
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_41, Valid: true}, Status: "unknown", Name: "Gofood: Resto A", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_11, Valid: true}, Status: "closed", Name: "Gofood: Resto B", Platform: "gofood", Url: "https://gofood.com/resto-b"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_31, Valid: true}, Status: "unknown", Name: "Gofood: Resto C", Platform: "gofood", Url: "https://gofood.com/resto-c"},
},
},
{
name: "anomalies: closed outside operational hours, unknown several times then closed",
schedules: schedules,
pings: []db.SelectOnlineListingPingsRow{
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_41, Valid: true}, Status: "closed", Name: "Gofood: Resto A", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_31, Valid: true}, Status: "unknown", Name: "Gofood: Resto A", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_21, Valid: true}, Status: "unknown", Name: "Gofood: Resto A", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_11, Valid: true}, Status: "unknown", Name: "Gofood: Resto A", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_01, Valid: true}, Status: "unknown", Name: "Gofood: Resto A", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today09_59, Valid: true}, Status: "closed", Name: "Gofood: Resto A", Platform: "gofood", Url: "https://gofood.com/resto-a"},
},
expected: []db.SelectOnlineListingPingsRow{
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_41, Valid: true}, Status: "closed", Name: "Gofood: Resto A", Platform: "gofood", Url: "https://gofood.com/resto-a"},
},
},
{
name: "no anomalies: open on first ping",
schedules: schedules,
pings: []db.SelectOnlineListingPingsRow{
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_11, Valid: true}, Status: "open", Name: "Gofood: Resto A", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_11, Valid: true}, Status: "open", Name: "Gofood: Resto B", Platform: "gofood", Url: "https://gofood.com/resto-b"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_11, Valid: true}, Status: "open", Name: "Gofood: Resto C", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_11, Valid: true}, Status: "open", Name: "Grabfood: Resto A", Platform: "gofood", Url: "https://grabfood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today09_59, Valid: true}, Status: "closed", Name: "Gofood: Resto A", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today09_59, Valid: true}, Status: "closed", Name: "Gofood: Resto B", Platform: "gofood", Url: "https://gofood.com/resto-b"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today09_59, Valid: true}, Status: "closed", Name: "Gofood: Resto C", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today09_59, Valid: true}, Status: "closed", Name: "Grabfood: Resto A", Platform: "gofood", Url: "https://grabfood.com/resto-a"},
},
expected: nil,
},
{
name: "no anomalies: closed 2x in a row",
schedules: schedules,
pings: []db.SelectOnlineListingPingsRow{
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_31, Valid: true}, Status: "closed", Name: "Gofood: Resto A", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_31, Valid: true}, Status: "open", Name: "Gofood: Resto B", Platform: "gofood", Url: "https://gofood.com/resto-b"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_31, Valid: true}, Status: "closed", Name: "Gofood: Resto C", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_31, Valid: true}, Status: "open", Name: "Grabfood: Resto A", Platform: "gofood", Url: "https://grabfood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_21, Valid: true}, Status: "closed", Name: "Gofood: Resto A", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_21, Valid: true}, Status: "open", Name: "Gofood: Resto B", Platform: "gofood", Url: "https://gofood.com/resto-b"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_21, Valid: true}, Status: "closed", Name: "Gofood: Resto C", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_21, Valid: true}, Status: "open", Name: "Grabfood: Resto A", Platform: "gofood", Url: "https://grabfood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_11, Valid: true}, Status: "open", Name: "Gofood: Resto A", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_11, Valid: true}, Status: "open", Name: "Gofood: Resto B", Platform: "gofood", Url: "https://gofood.com/resto-b"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_11, Valid: true}, Status: "open", Name: "Gofood: Resto C", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_11, Valid: true}, Status: "open", Name: "Grabfood: Resto A", Platform: "gofood", Url: "https://grabfood.com/resto-a"},
},
expected: nil,
},
{
name: "no anomalies: always open",
schedules: schedules,
pings: []db.SelectOnlineListingPingsRow{
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_31, Valid: true}, Status: "open", Name: "Gofood: Resto A", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_31, Valid: true}, Status: "open", Name: "Gofood: Resto B", Platform: "gofood", Url: "https://gofood.com/resto-b"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_31, Valid: true}, Status: "open", Name: "Gofood: Resto C", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_31, Valid: true}, Status: "open", Name: "Grabfood: Resto A", Platform: "gofood", Url: "https://grabfood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_21, Valid: true}, Status: "open", Name: "Gofood: Resto A", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_21, Valid: true}, Status: "open", Name: "Gofood: Resto B", Platform: "gofood", Url: "https://gofood.com/resto-b"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_21, Valid: true}, Status: "open", Name: "Gofood: Resto C", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_21, Valid: true}, Status: "open", Name: "Grabfood: Resto A", Platform: "gofood", Url: "https://grabfood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_11, Valid: true}, Status: "open", Name: "Gofood: Resto A", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_11, Valid: true}, Status: "open", Name: "Gofood: Resto B", Platform: "gofood", Url: "https://gofood.com/resto-b"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_11, Valid: true}, Status: "open", Name: "Gofood: Resto C", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_11, Valid: true}, Status: "open", Name: "Grabfood: Resto A", Platform: "gofood", Url: "https://grabfood.com/resto-a"},
},
expected: nil,
},
{
name: "no anomalies: closed outside operational hours",
schedules: schedules,
pings: []db.SelectOnlineListingPingsRow{
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today20_11, Valid: true}, Status: "closed", Name: "Gofood: Resto A", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today20_11, Valid: true}, Status: "closed", Name: "Gofood: Resto B", Platform: "gofood", Url: "https://gofood.com/resto-b"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today20_11, Valid: true}, Status: "open", Name: "Gofood: Resto C", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today20_11, Valid: true}, Status: "closed", Name: "Grabfood: Resto A", Platform: "gofood", Url: "https://grabfood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today19_59, Valid: true}, Status: "open", Name: "Gofood: Resto A", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today19_59, Valid: true}, Status: "open", Name: "Gofood: Resto B", Platform: "gofood", Url: "https://gofood.com/resto-b"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today19_59, Valid: true}, Status: "open", Name: "Gofood: Resto C", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today19_59, Valid: true}, Status: "open", Name: "Grabfood: Resto A", Platform: "gofood", Url: "https://grabfood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today19_51, Valid: true}, Status: "open", Name: "Gofood: Resto A", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today19_51, Valid: true}, Status: "open", Name: "Gofood: Resto B", Platform: "gofood", Url: "https://gofood.com/resto-b"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today19_51, Valid: true}, Status: "open", Name: "Gofood: Resto C", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today19_51, Valid: true}, Status: "open", Name: "Grabfood: Resto A", Platform: "gofood", Url: "https://grabfood.com/resto-a"},
},
expected: nil,
},
{
name: "no anomalies: known to be closed during operational hours, unknown several times then closed again",
schedules: schedules,
pings: []db.SelectOnlineListingPingsRow{
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_41, Valid: true}, Status: "closed", Name: "Gofood: Resto A", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_31, Valid: true}, Status: "unknown", Name: "Gofood: Resto A", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_21, Valid: true}, Status: "unknown", Name: "Gofood: Resto A", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_11, Valid: true}, Status: "unknown", Name: "Gofood: Resto A", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today10_01, Valid: true}, Status: "closed", Name: "Gofood: Resto A", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today09_59, Valid: true}, Status: "unknown", Name: "Gofood: Resto A", Platform: "gofood", Url: "https://gofood.com/resto-a"},
},
expected: nil,
},
{
name: "no anomalies: unkown outside operational hours",
schedules: schedules,
pings: []db.SelectOnlineListingPingsRow{
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today20_11, Valid: true}, Status: "unknown", Name: "Gofood: Resto A", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today20_11, Valid: true}, Status: "unknown", Name: "Gofood: Resto B", Platform: "gofood", Url: "https://gofood.com/resto-b"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today20_11, Valid: true}, Status: "unknown", Name: "Gofood: Resto C", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today20_11, Valid: true}, Status: "unknown", Name: "Grabfood: Resto A", Platform: "gofood", Url: "https://grabfood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today19_59, Valid: true}, Status: "unknown", Name: "Gofood: Resto A", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today19_59, Valid: true}, Status: "unknown", Name: "Gofood: Resto B", Platform: "gofood", Url: "https://gofood.com/resto-b"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today19_59, Valid: true}, Status: "unknown", Name: "Gofood: Resto C", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today19_59, Valid: true}, Status: "unknown", Name: "Grabfood: Resto A", Platform: "gofood", Url: "https://grabfood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today19_51, Valid: true}, Status: "open", Name: "Gofood: Resto A", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today19_51, Valid: true}, Status: "unknown", Name: "Gofood: Resto B", Platform: "gofood", Url: "https://gofood.com/resto-b"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today19_51, Valid: true}, Status: "unknown", Name: "Gofood: Resto C", Platform: "gofood", Url: "https://gofood.com/resto-a"},
{OnlineListingID: uuid1, CreatedAt: pgtype.Timestamptz{Time: today19_51, Valid: true}, Status: "unknown", Name: "Grabfood: Resto A", Platform: "gofood", Url: "https://grabfood.com/resto-a"},
},
expected: nil,
},
}
// Run test cases
for _, tc := range testCases {
t.Run(tc.name, func(t *testing.T) {
actual := getPingAnomalies(tc.schedules, tc.pings)
assert.Equal(t, actual, tc.expected)
})
}
}