@@ -85,7 +85,7 @@ class NotificationServiceTest : RobolectricTest() {
8585 }
8686
8787 @Test
88- fun `onReceive with less cards than card threshold should not fire notification but schedule next` () =
88+ fun `triggering with less cards than card threshold should not fire notification but schedule next` () =
8989 runTest {
9090 val did1 = addDeck(" Deck" , setAsSelected = true ).withNotes(count = 2 )
9191 val reviewReminderDeckSpecific = createTestReminder(deckId = did1, thresholdInt = 3 )
@@ -105,7 +105,7 @@ class NotificationServiceTest : RobolectricTest() {
105105 }
106106
107107 @Test
108- fun `onReceive with happy path for single deck should fire notification and schedule next` () =
108+ fun `triggering with happy path for single deck should fire notification and schedule next` () =
109109 runTest {
110110 val did1 = addDeck(" Deck" , setAsSelected = true ).withNotes(count = 2 )
111111 val reviewReminder = createAndSaveDummyDeckSpecificReminder(did1)
@@ -119,7 +119,7 @@ class NotificationServiceTest : RobolectricTest() {
119119 }
120120
121121 @Test
122- fun `onReceive with happy path for global reminder should fire notification and schedule next` () =
122+ fun `triggering with happy path for global reminder should fire notification and schedule next` () =
123123 runTest {
124124 addDeck(" Deck1" ).withNotes(count = 2 )
125125 addDeck(" Deck2" ).withNotes(count = 2 )
@@ -134,9 +134,10 @@ class NotificationServiceTest : RobolectricTest() {
134134 }
135135
136136 @Test
137- fun `onReceive with non-existent deck should not fire notification but schedule next` () =
137+ fun `triggering with non-existent deck should not fire notification but schedule next` () =
138138 runTest {
139- val reviewReminder = createTestReminder(deckId = 9999 )
139+ val did1 = addDeck(" Deck" )
140+ val reviewReminder = createTestReminder(deckId = did1 + 1 )
140141 val creationTime = reviewReminder.latestNotifTime
141142
142143 triggerDummyReminderNotification(reviewReminder)
@@ -147,7 +148,7 @@ class NotificationServiceTest : RobolectricTest() {
147148 }
148149
149150 @Test
150- fun `onReceive with reviews today and onlyNotifyIfNoReviews is true should not fire notification` () =
151+ fun `triggering with reviews today and onlyNotifyIfNoReviews is true should not fire notification` () =
151152 runTest {
152153 val did1 = addDeck(" Deck" , setAsSelected = true ).withNote()
153154 col.sched.answerCard(col.sched.card!! , CardAnswer .Rating .GOOD )
@@ -162,7 +163,7 @@ class NotificationServiceTest : RobolectricTest() {
162163 }
163164
164165 @Test
165- fun `onReceive with no reviews ever and onlyNotifyIfNoReviews is true should fire notification` () =
166+ fun `triggering with no reviews ever and onlyNotifyIfNoReviews is true should fire notification` () =
166167 runTest {
167168 val did1 = addDeck(" Deck" , setAsSelected = true ).withNote()
168169 val reviewReminderDeckSpecific = createTestReminder(deckId = did1, thresholdInt = 1 , onlyNotifyIfNoReviews = true )
@@ -177,7 +178,7 @@ class NotificationServiceTest : RobolectricTest() {
177178 }
178179
179180 @Test
180- fun `onReceive with review yesterday but none today and onlyNotifyIfNoReviews is true should fire notification` () =
181+ fun `triggering with review yesterday but none today and onlyNotifyIfNoReviews is true should fire notification` () =
181182 runTest {
182183 TimeManager .resetWith(yesterday) // Wind back time and perform the review
183184 val did1 = addDeck(" Deck" , setAsSelected = true ).withNote()
@@ -201,7 +202,7 @@ class NotificationServiceTest : RobolectricTest() {
201202 }
202203
203204 @Test
204- fun `onReceive with onlyNotifyIfNoReviews is false should always fire notification` () =
205+ fun `triggering with onlyNotifyIfNoReviews is false should always fire notification` () =
205206 runTest {
206207 val did1 = addDeck(" Deck" , setAsSelected = true ).withNote()
207208 val reviewReminderDeckSpecific = createAndSaveDummyDeckSpecificReminder(did1)
@@ -218,7 +219,7 @@ class NotificationServiceTest : RobolectricTest() {
218219 }
219220
220221 @Test
221- fun `onReceive with blocked collection should not fire notification but schedule next` () =
222+ fun `triggering with blocked collection should not fire notification but schedule next` () =
222223 runTest {
223224 val did1 = addDeck(" Deck" , setAsSelected = true ).withNotes(count = 2 )
224225 val reviewReminderDeckSpecific = createAndSaveDummyDeckSpecificReminder(did1)
@@ -238,18 +239,16 @@ class NotificationServiceTest : RobolectricTest() {
238239 }
239240
240241 @Test
241- fun `onReceive with snoozed notification should fire notification but not schedule next` () =
242+ fun `triggering with snoozed notification should fire notification but not schedule next` () =
242243 runTest {
243244 val did1 = addDeck(" Deck" , setAsSelected = true ).withNotes(count = 2 )
244245 val reviewReminderDeckSpecific = createAndSaveDummyDeckSpecificReminder(did1)
245246 val reviewReminderAppWide = createAndSaveDummyAppWideReminder()
246247 val deckSpecificCreationTime = reviewReminderDeckSpecific.latestNotifTime
247248 val appWideCreationTime = reviewReminderAppWide.latestNotifTime
248249
249- val intentDeckSpecific = reviewReminderDeckSpecific.getNotifIntent(NotifIntent .SNOOZE )
250- val intentAppWide = reviewReminderAppWide.getNotifIntent(NotifIntent .SNOOZE )
251- NotificationService ().onReceive(context, intentDeckSpecific)
252- NotificationService ().onReceive(context, intentAppWide)
250+ triggerDummyReminderNotification(reviewReminderDeckSpecific, isRecurring = false )
251+ triggerDummyReminderNotification(reviewReminderAppWide, isRecurring = false )
253252
254253 verifyNotifSent(reviewReminderDeckSpecific)
255254 verifyNotifSent(reviewReminderAppWide)
@@ -270,11 +269,8 @@ class NotificationServiceTest : RobolectricTest() {
270269 val slotOne = slot<Notification >()
271270 val slotTwo = slot<Notification >()
272271
273- val intentOne = reviewReminderOne.getNotifIntent(NotifIntent .RECURRING )
274- NotificationService ().onReceive(context, intentOne)
275-
276- val intentTwo = reviewReminderTwo.getNotifIntent(NotifIntent .RECURRING )
277- NotificationService ().onReceive(context, intentTwo)
272+ triggerDummyReminderNotification(reviewReminderOne)
273+ triggerDummyReminderNotification(reviewReminderTwo)
278274
279275 verifyNotifSent(reviewReminderOne, slot = slotOne)
280276 verifyNotifSent(reviewReminderTwo, slot = slotTwo)
@@ -301,9 +297,15 @@ class NotificationServiceTest : RobolectricTest() {
301297 return reviewReminder
302298 }
303299
304- private fun triggerDummyReminderNotification (reviewReminder : ReviewReminder ) {
305- val intent = reviewReminder.getNotifIntent(NotifIntent .RECURRING )
306- NotificationService ().onReceive(context, intent)
300+ private suspend fun triggerDummyReminderNotification (
301+ reviewReminder : ReviewReminder ,
302+ isRecurring : Boolean = true,
303+ ) {
304+ NotificationService .handleReviewReminderNotification(
305+ context,
306+ reviewReminder,
307+ isRecurringNotification = isRecurring,
308+ )
307309 }
308310
309311 /* *
@@ -367,20 +369,4 @@ class NotificationServiceTest : RobolectricTest() {
367369 assertThat(previousTime, equalTo(storedReminder.latestNotifTime))
368370 }
369371 }
370-
371- /* *
372- * Convenience enum class to minimize verbosity in test methods when using [getNotifIntent].
373- */
374- private enum class NotifIntent {
375- RECURRING ,
376- SNOOZE ,
377- }
378-
379- private fun ReviewReminder.getNotifIntent (action : NotifIntent ) =
380- when (action) {
381- NotifIntent .RECURRING -> NotificationService .NotificationServiceAction .ScheduleRecurringNotifications
382- NotifIntent .SNOOZE -> NotificationService .NotificationServiceAction .SnoozeNotification
383- }.let { action ->
384- NotificationService .getIntent(context, this , action)
385- }
386372}
0 commit comments