@@ -23,7 +23,7 @@ import org.wordpress.android.fluxc.store.WooCommerceStore
2323import org.wordpress.android.fluxc.wc.settings.WCSettingsTestUtils
2424
2525@ExperimentalCoroutinesApi
26- class WooPosSurveysNotificationSchedularTest {
26+ class WooPosSurveysNotificationSchedulerTest {
2727 @Rule
2828 @JvmField
2929 val coroutinesTestRule = WooPosCoroutineTestRule ()
@@ -33,7 +33,7 @@ class WooPosSurveysNotificationSchedularTest {
3333 private lateinit var wooPosPreferencesRepository: WooPosPreferencesRepository
3434 private lateinit var selectedSite: SelectedSite
3535 private lateinit var wooCommerceStore: WooCommerceStore
36- private lateinit var schedular : WooPosSurveysNotificationSchedular
36+ private lateinit var scheduler : WooPosSurveysNotificationScheduler
3737 private lateinit var siteModel: SiteModel
3838
3939 @Before
@@ -49,7 +49,7 @@ class WooPosSurveysNotificationSchedularTest {
4949
5050 whenever(selectedSite.get()).thenReturn(siteModel)
5151
52- schedular = WooPosSurveysNotificationSchedular (
52+ scheduler = WooPosSurveysNotificationScheduler (
5353 localNotificationScheduler = localNotificationScheduler,
5454 appPrefs = appPrefs,
5555 wooPosPreferencesRepository = wooPosPreferencesRepository,
@@ -59,110 +59,167 @@ class WooPosSurveysNotificationSchedularTest {
5959 }
6060
6161 @Test
62- fun `given all conditions met, when schedularPotentialUserSurveyNotification called, then notification scheduled` () =
62+ fun `given all conditions met, when schedulePotentialUserSurveyNotification called, then notification scheduled` () =
6363 runTest {
6464 val siteSettings = WCSettingsTestUtils .generateSettings(LocalId (1 )).copy(countryCode = " US" )
6565 whenever(appPrefs.isWooPosSurveyNotificationPotentialUserShown).thenReturn(false )
6666 whenever(wooPosPreferencesRepository.wasOpenedOnce).thenReturn(flowOf(false ))
6767 whenever(wooCommerceStore.getSiteSettingsAsync(siteModel)).thenReturn(siteSettings)
6868
69- schedular.schedularPotentialUserSurveyNotification ()
69+ scheduler.schedulePotentialUserSurveyNotification ()
7070
7171 verify(localNotificationScheduler).scheduleNotification(
7272 LocalNotification .WooPosSurveyPotentialUserNotification (siteId = 123L )
7373 )
7474 }
7575
7676 @Test
77- fun `given notification already shown, when schedularPotentialUserSurveyNotification called, then notification not scheduled` () =
77+ fun `given notification already shown, when schedulePotentialUserSurveyNotification called, then notification not scheduled` () =
7878 runTest {
7979 val siteSettings = WCSettingsTestUtils .generateSettings(LocalId (1 )).copy(countryCode = " US" )
8080 whenever(appPrefs.isWooPosSurveyNotificationPotentialUserShown).thenReturn(true )
8181 whenever(wooPosPreferencesRepository.wasOpenedOnce).thenReturn(flowOf(false ))
8282 whenever(wooCommerceStore.getSiteSettingsAsync(siteModel)).thenReturn(siteSettings)
8383
84- schedular.schedularPotentialUserSurveyNotification ()
84+ scheduler.schedulePotentialUserSurveyNotification ()
8585
8686 verify(localNotificationScheduler, never()).scheduleNotification(any())
8787 }
8888
8989 @Test
90- fun `given country not allowed, when schedularPotentialUserSurveyNotification called, then notification not scheduled` () =
90+ fun `given country not allowed, when schedulePotentialUserSurveyNotification called, then notification not scheduled` () =
9191 runTest {
9292 val siteSettings = WCSettingsTestUtils .generateSettings(LocalId (1 )).copy(countryCode = " FR" )
9393 whenever(appPrefs.isWooPosSurveyNotificationPotentialUserShown).thenReturn(false )
9494 whenever(wooPosPreferencesRepository.wasOpenedOnce).thenReturn(flowOf(false ))
9595 whenever(wooCommerceStore.getSiteSettingsAsync(siteModel)).thenReturn(siteSettings)
9696
97- schedular.schedularPotentialUserSurveyNotification ()
97+ scheduler.schedulePotentialUserSurveyNotification ()
9898
9999 verify(localNotificationScheduler, never()).scheduleNotification(any())
100100 }
101101
102102 @Test
103- fun `given WooPOS opened before, when schedularPotentialUserSurveyNotification called, then notification not scheduled` () =
103+ fun `given WooPOS opened before, when schedulePotentialUserSurveyNotification called, then notification not scheduled` () =
104104 runTest {
105105 val siteSettings = WCSettingsTestUtils .generateSettings(LocalId (1 )).copy(countryCode = " US" )
106106 whenever(appPrefs.isWooPosSurveyNotificationPotentialUserShown).thenReturn(false )
107107 whenever(wooPosPreferencesRepository.wasOpenedOnce).thenReturn(flowOf(true ))
108108 whenever(wooCommerceStore.getSiteSettingsAsync(siteModel)).thenReturn(siteSettings)
109109
110- schedular.schedularPotentialUserSurveyNotification ()
110+ scheduler.schedulePotentialUserSurveyNotification ()
111111
112112 verify(localNotificationScheduler, never()).scheduleNotification(any())
113113 }
114114
115115 @Test
116- fun `given GB country code, when schedularPotentialUserSurveyNotification called, then notification scheduled` () =
116+ fun `given GB country code, when schedulePotentialUserSurveyNotification called, then notification scheduled` () =
117117 runTest {
118118 val siteSettings = WCSettingsTestUtils .generateSettings(LocalId (1 )).copy(countryCode = " GB" )
119119 whenever(appPrefs.isWooPosSurveyNotificationPotentialUserShown).thenReturn(false )
120120 whenever(wooPosPreferencesRepository.wasOpenedOnce).thenReturn(flowOf(false ))
121121 whenever(wooCommerceStore.getSiteSettingsAsync(siteModel)).thenReturn(siteSettings)
122122
123- schedular.schedularPotentialUserSurveyNotification ()
123+ scheduler.schedulePotentialUserSurveyNotification ()
124124
125125 verify(localNotificationScheduler).scheduleNotification(
126126 LocalNotification .WooPosSurveyPotentialUserNotification (siteId = 123L )
127127 )
128128 }
129129
130130 @Test
131- fun `given lowercase country code, when schedularPotentialUserSurveyNotification called, then notification scheduled` () =
131+ fun `given lowercase country code, when schedulePotentialUserSurveyNotification called, then notification scheduled` () =
132132 runTest {
133133 val siteSettings = WCSettingsTestUtils .generateSettings(LocalId (1 )).copy(countryCode = " us" )
134134 whenever(appPrefs.isWooPosSurveyNotificationPotentialUserShown).thenReturn(false )
135135 whenever(wooPosPreferencesRepository.wasOpenedOnce).thenReturn(flowOf(false ))
136136 whenever(wooCommerceStore.getSiteSettingsAsync(siteModel)).thenReturn(siteSettings)
137137
138- schedular.schedularPotentialUserSurveyNotification ()
138+ scheduler.schedulePotentialUserSurveyNotification ()
139139
140140 verify(localNotificationScheduler).scheduleNotification(
141141 LocalNotification .WooPosSurveyPotentialUserNotification (siteId = 123L )
142142 )
143143 }
144144
145145 @Test
146- fun `given null country code, when schedularPotentialUserSurveyNotification called, then notification not scheduled` () =
146+ fun `given null country code, when schedulePotentialUserSurveyNotification called, then notification not scheduled` () =
147147 runTest {
148148 val siteSettings = WCSettingsTestUtils .generateSettings(LocalId (1 )).copy(countryCode = " " )
149149 whenever(appPrefs.isWooPosSurveyNotificationPotentialUserShown).thenReturn(false )
150150 whenever(wooPosPreferencesRepository.wasOpenedOnce).thenReturn(flowOf(false ))
151151 whenever(wooCommerceStore.getSiteSettingsAsync(siteModel)).thenReturn(siteSettings)
152152
153- schedular.schedularPotentialUserSurveyNotification ()
153+ scheduler.schedulePotentialUserSurveyNotification ()
154154
155155 verify(localNotificationScheduler, never()).scheduleNotification(any())
156156 }
157157
158158 @Test
159- fun `given null site settings, when schedularPotentialUserSurveyNotification called, then notification not scheduled` () =
159+ fun `given null site settings, when schedulePotentialUserSurveyNotification called, then notification not scheduled` () =
160160 runTest {
161161 whenever(appPrefs.isWooPosSurveyNotificationPotentialUserShown).thenReturn(false )
162162 whenever(wooPosPreferencesRepository.wasOpenedOnce).thenReturn(flowOf(false ))
163163 whenever(wooCommerceStore.getSiteSettingsAsync(siteModel)).thenReturn(null )
164164
165- schedular.schedularPotentialUserSurveyNotification()
165+ scheduler.schedulePotentialUserSurveyNotification()
166+
167+ verify(localNotificationScheduler, never()).scheduleNotification(any())
168+ }
169+
170+ @Test
171+ fun `given all conditions met, when scheduleCurrentUserSurveyNotification called, then notification scheduled with delay` () =
172+ runTest {
173+ val siteSettings = WCSettingsTestUtils .generateSettings(LocalId (1 )).copy(countryCode = " US" )
174+ whenever(appPrefs.isWooPosSurveyNotificationCurrentUserShown).thenReturn(false )
175+ whenever(wooPosPreferencesRepository.wasOpenedOnce).thenReturn(flowOf(true ))
176+ whenever(wooCommerceStore.getSiteSettingsAsync(siteModel)).thenReturn(siteSettings)
177+
178+ scheduler.scheduleCurrentUserSurveyNotification()
179+
180+ verify(localNotificationScheduler).scheduleNotification(
181+ LocalNotification .WooPosSurveyCurrentUserNotification (
182+ delay = 300000L ,
183+ siteId = 123L
184+ )
185+ )
186+ }
187+
188+ @Test
189+ fun `given notification already shown, when scheduleCurrentUserSurveyNotification called, then notification not scheduled` () =
190+ runTest {
191+ val siteSettings = WCSettingsTestUtils .generateSettings(LocalId (1 )).copy(countryCode = " US" )
192+ whenever(appPrefs.isWooPosSurveyNotificationCurrentUserShown).thenReturn(true )
193+ whenever(wooPosPreferencesRepository.wasOpenedOnce).thenReturn(flowOf(true ))
194+ whenever(wooCommerceStore.getSiteSettingsAsync(siteModel)).thenReturn(siteSettings)
195+
196+ scheduler.scheduleCurrentUserSurveyNotification()
197+
198+ verify(localNotificationScheduler, never()).scheduleNotification(any())
199+ }
200+
201+ @Test
202+ fun `given WooPOS not opened before, when scheduleCurrentUserSurveyNotification called, then notification not scheduled` () =
203+ runTest {
204+ val siteSettings = WCSettingsTestUtils .generateSettings(LocalId (1 )).copy(countryCode = " US" )
205+ whenever(appPrefs.isWooPosSurveyNotificationCurrentUserShown).thenReturn(false )
206+ whenever(wooPosPreferencesRepository.wasOpenedOnce).thenReturn(flowOf(false ))
207+ whenever(wooCommerceStore.getSiteSettingsAsync(siteModel)).thenReturn(siteSettings)
208+
209+ scheduler.scheduleCurrentUserSurveyNotification()
210+
211+ verify(localNotificationScheduler, never()).scheduleNotification(any())
212+ }
213+
214+ @Test
215+ fun `given country not allowed, when scheduleCurrentUserSurveyNotification called, then notification not scheduled` () =
216+ runTest {
217+ val siteSettings = WCSettingsTestUtils .generateSettings(LocalId (1 )).copy(countryCode = " FR" )
218+ whenever(appPrefs.isWooPosSurveyNotificationCurrentUserShown).thenReturn(false )
219+ whenever(wooPosPreferencesRepository.wasOpenedOnce).thenReturn(flowOf(true ))
220+ whenever(wooCommerceStore.getSiteSettingsAsync(siteModel)).thenReturn(siteSettings)
221+
222+ scheduler.scheduleCurrentUserSurveyNotification()
166223
167224 verify(localNotificationScheduler, never()).scheduleNotification(any())
168225 }
0 commit comments