Skip to content

Commit 6ef9c23

Browse files
committed
chore: add more scenarios
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
1 parent 7cc0c8a commit 6ef9c23

1 file changed

Lines changed: 104 additions & 8 deletions

File tree

tests/php/Unit/Service/ReminderServiceTest.php

Lines changed: 104 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -142,32 +142,32 @@ public static function providerWillNotify(): array {
142142
],
143143
'no notification, scheduled for today, between = 0' => [
144144
[
145-
'first' => (clone $now),
146-
'last' => (clone $now),
145+
'first' => (clone $now)->setTime(0, 0),
146+
'last' => (clone $now)->setTime(0, 0),
147147
'total' => 1,
148148
],
149149
'now' => $now, 'daysBefore' => 1, 'daysBetween' => 0, 'max' => 5, false,
150150
],
151151
'no notification, scheduled for today, between = 1' => [
152152
[
153-
'first' => (clone $now),
154-
'last' => (clone $now),
153+
'first' => (clone $now)->setTime(0, 0),
154+
'last' => (clone $now)->setTime(0, 0),
155155
'total' => 1,
156156
],
157157
'now' => $now, 'daysBefore' => 1, 'daysBetween' => 1, 'max' => 5, false,
158158
],
159159
'no notification, scheduled for yesterday, between = 0' => [
160160
[
161-
'first' => (clone $now)->modify('-1 day'),
162-
'last' => (clone $now)->modify('-1 day'),
161+
'first' => (clone $now)->modify('-1 day')->setTime(0, 0),
162+
'last' => (clone $now)->modify('-1 day')->setTime(0, 0),
163163
'total' => 1,
164164
],
165165
'now' => $now, 'daysBefore' => 1, 'daysBetween' => 0, 'max' => 5, false,
166166
],
167167
'one notification, scheduled for yesterday, between = 1' => [
168168
[
169-
'first' => (clone $now)->modify('-1 day')->setTime(11, 0),
170-
'last' => (clone $now)->modify('-1 day')->setTime(11, 0),
169+
'first' => (clone $now)->modify('-1 day')->setTime(0, 0),
170+
'last' => (clone $now)->modify('-1 day')->setTime(0, 0),
171171
'total' => 1,
172172
],
173173
'now' => $now, 'daysBefore' => 1, 'daysBetween' => 1, 'max' => 5, true,
@@ -220,6 +220,102 @@ public static function providerWillNotify(): array {
220220
],
221221
'now' => $now, 'daysBefore' => 0, 'daysBetween' => 0, 'max' => 5, false,
222222
],
223+
'one notification, exact daysBefore limit, should notify' => [
224+
[
225+
'first' => (clone $now)->modify('-1 day')->setTime(0, 0),
226+
'last' => (clone $now)->modify('-1 day')->setTime(0, 0),
227+
'total' => 1,
228+
],
229+
'now' => $now, 'daysBefore' => 1, 'daysBetween' => 1, 'max' => 5, true,
230+
],
231+
'two notifications, exact daysBetween limit, should notify' => [
232+
[
233+
'first' => (clone $now)->modify('-3 days'),
234+
'last' => (clone $now)->modify('-2 days')->setTime(0, 0),
235+
'total' => 2,
236+
],
237+
'now' => $now, 'daysBefore' => 1, 'daysBetween' => 2, 'max' => 5, true,
238+
],
239+
'no notifications, valid config but daysBetween = 0' => [
240+
[
241+
'first' => null,
242+
'last' => null,
243+
'total' => 0,
244+
],
245+
'now' => $now, 'daysBefore' => 1, 'daysBetween' => 0, 'max' => 5, false,
246+
],
247+
'inconsistent data: total > 0 but null dates' => [
248+
[
249+
'first' => null,
250+
'last' => null,
251+
'total' => 1,
252+
],
253+
'now' => $now, 'daysBefore' => 1, 'daysBetween' => 1, 'max' => 5, false,
254+
],
255+
'max = 0 means no limit, should send with valid config' => [
256+
[
257+
'first' => (clone $now)->modify('-2 days'),
258+
'last' => (clone $now)->modify('-2 days'),
259+
'total' => 1,
260+
],
261+
'now' => $now, 'daysBefore' => 1, 'daysBetween' => 1, 'max' => 0, true,
262+
],
263+
'max = 0, high total count, should still send' => [
264+
[
265+
'first' => (clone $now)->modify('-10 days'),
266+
'last' => (clone $now)->modify('-2 days'),
267+
'total' => 100,
268+
],
269+
'now' => $now, 'daysBefore' => 1, 'daysBetween' => 1, 'max' => 0, true,
270+
],
271+
'total exceeds max, should not send' => [
272+
[
273+
'first' => (clone $now)->modify('-5 days'),
274+
'last' => (clone $now)->modify('-2 days'),
275+
'total' => 6,
276+
],
277+
'now' => $now, 'daysBefore' => 1, 'daysBetween' => 1, 'max' => 5, false,
278+
],
279+
'notification today, should not send' => [
280+
[
281+
'first' => (clone $now)->setTime(0, 0),
282+
'last' => (clone $now)->setTime(0, 0),
283+
'total' => 1,
284+
],
285+
'now' => $now, 'daysBefore' => 1, 'daysBetween' => 1, 'max' => 5, false,
286+
],
287+
'multiple notifications, insufficient daysBetween' => [
288+
[
289+
'first' => (clone $now)->modify('-5 days'),
290+
'last' => (clone $now)->setTime(0, 0),
291+
'total' => 3,
292+
],
293+
'now' => $now, 'daysBefore' => 1, 'daysBetween' => 2, 'max' => 5, false,
294+
],
295+
'negative daysBefore, should not send' => [
296+
[
297+
'first' => (clone $now)->modify('-2 days'),
298+
'last' => (clone $now)->modify('-2 days'),
299+
'total' => 1,
300+
],
301+
'now' => $now, 'daysBefore' => -1, 'daysBetween' => 1, 'max' => 5, false,
302+
],
303+
'negative daysBetween, should not send' => [
304+
[
305+
'first' => (clone $now)->modify('-5 days'),
306+
'last' => (clone $now)->modify('-2 days'),
307+
'total' => 2,
308+
],
309+
'now' => $now, 'daysBefore' => 1, 'daysBetween' => -1, 'max' => 5, false,
310+
],
311+
'negative max acts as no limit, should send' => [
312+
[
313+
'first' => (clone $now)->modify('-3 days'),
314+
'last' => (clone $now)->modify('-2 days'),
315+
'total' => 10,
316+
],
317+
'now' => $now, 'daysBefore' => 1, 'daysBetween' => 1, 'max' => -1, true,
318+
],
223319
];
224320
}
225321

0 commit comments

Comments
 (0)