1
1
package com.onesignal.user.internal.operations
2
2
3
3
import br.com.colman.kotest.android.extensions.robolectric.RobolectricTest
4
+ import com.onesignal.common.consistency.RywData
5
+ import com.onesignal.common.consistency.models.IConsistencyManager
4
6
import com.onesignal.common.exceptions.BackendException
5
7
import com.onesignal.core.internal.operations.ExecutionResponse
6
8
import com.onesignal.core.internal.operations.ExecutionResult
@@ -25,10 +27,13 @@ import io.kotest.core.spec.style.FunSpec
25
27
import io.kotest.matchers.collections.shouldBeOneOf
26
28
import io.kotest.matchers.shouldBe
27
29
import io.kotest.matchers.types.shouldBeInstanceOf
30
+ import io.mockk.clearMocks
28
31
import io.mockk.coEvery
29
32
import io.mockk.coVerify
30
33
import io.mockk.every
34
+ import io.mockk.just
31
35
import io.mockk.mockk
36
+ import io.mockk.runs
32
37
33
38
@RobolectricTest
34
39
class LoginUserOperationExecutorTests : FunSpec ({
@@ -39,6 +44,8 @@ class LoginUserOperationExecutorTests : FunSpec({
39
44
val localSubscriptionId2 = " local-subscriptionId2"
40
45
val remoteSubscriptionId1 = " remote-subscriptionId1"
41
46
val remoteSubscriptionId2 = " remote-subscriptionId2"
47
+ val rywData = RywData ("1", 500L)
48
+ val mockConsistencyManager = mockk<IConsistencyManager >()
42
49
val createSubscriptionOperation =
43
50
CreateSubscriptionOperation (
44
51
appId,
@@ -50,6 +57,11 @@ class LoginUserOperationExecutorTests : FunSpec({
50
57
SubscriptionStatus .SUBSCRIBED ,
51
58
)
52
59
60
+ beforeTest {
61
+ clearMocks(mockConsistencyManager)
62
+ coEvery { mockConsistencyManager.setRywData(any(), any(), any()) } just runs
63
+ }
64
+
53
65
test("login anonymous user successfully creates user") {
54
66
// Given
55
67
val mockUserBackendService = mockk<IUserBackendService >()
@@ -58,6 +70,7 @@ class LoginUserOperationExecutorTests : FunSpec({
58
70
mapOf(IdentityConstants .ONESIGNAL_ID to remoteOneSignalId),
59
71
PropertiesObject (),
60
72
listOf(),
73
+ rywData,
61
74
)
62
75
// Given
63
76
val mockIdentityOperationExecutor = mockk<IdentityOperationExecutor >()
@@ -76,6 +89,7 @@ class LoginUserOperationExecutorTests : FunSpec({
76
89
mockSubscriptionsModelStore,
77
90
MockHelper .configModelStore(),
78
91
MockHelper .languageContext(),
92
+ mockConsistencyManager,
79
93
)
80
94
val operations =
81
95
listOf<Operation >(
@@ -120,6 +134,7 @@ class LoginUserOperationExecutorTests : FunSpec({
120
134
mockSubscriptionsModelStore,
121
135
MockHelper .configModelStore(),
122
136
MockHelper .languageContext(),
137
+ mockConsistencyManager,
123
138
)
124
139
val operations =
125
140
listOf<Operation >(
@@ -148,7 +163,7 @@ class LoginUserOperationExecutorTests : FunSpec({
148
163
val mockSubscriptionsModelStore = mockk<SubscriptionModelStore >()
149
164
150
165
val loginUserOperationExecutor =
151
- LoginUserOperationExecutor (mockIdentityOperationExecutor, AndroidMockHelper .applicationService(), MockHelper .deviceService(), mockUserBackendService, mockIdentityModelStore, mockPropertiesModelStore, mockSubscriptionsModelStore, MockHelper .configModelStore(), MockHelper .languageContext())
166
+ LoginUserOperationExecutor (mockIdentityOperationExecutor, AndroidMockHelper .applicationService(), MockHelper .deviceService(), mockUserBackendService, mockIdentityModelStore, mockPropertiesModelStore, mockSubscriptionsModelStore, MockHelper .configModelStore(), MockHelper .languageContext(), mockConsistencyManager )
152
167
val operations =
153
168
listOf<Operation >(
154
169
LoginUserOperation (appId, localOneSignalId, null, null),
@@ -167,7 +182,7 @@ class LoginUserOperationExecutorTests : FunSpec({
167
182
// Given
168
183
val mockUserBackendService = mockk<IUserBackendService >()
169
184
coEvery { mockUserBackendService.createUser(any(), any(), any(), any()) } returns
170
- CreateUserResponse (mapOf(IdentityConstants .ONESIGNAL_ID to remoteOneSignalId), PropertiesObject (), listOf())
185
+ CreateUserResponse (mapOf(IdentityConstants .ONESIGNAL_ID to remoteOneSignalId), PropertiesObject (), listOf(), rywData )
171
186
172
187
val mockIdentityOperationExecutor = mockk<IdentityOperationExecutor >()
173
188
@@ -176,7 +191,7 @@ class LoginUserOperationExecutorTests : FunSpec({
176
191
val mockSubscriptionsModelStore = mockk<SubscriptionModelStore >()
177
192
178
193
val loginUserOperationExecutor =
179
- LoginUserOperationExecutor (mockIdentityOperationExecutor, MockHelper .applicationService(), MockHelper .deviceService(), mockUserBackendService, mockIdentityModelStore, mockPropertiesModelStore, mockSubscriptionsModelStore, MockHelper .configModelStore(), MockHelper .languageContext())
194
+ LoginUserOperationExecutor (mockIdentityOperationExecutor, MockHelper .applicationService(), MockHelper .deviceService(), mockUserBackendService, mockIdentityModelStore, mockPropertiesModelStore, mockSubscriptionsModelStore, MockHelper .configModelStore(), MockHelper .languageContext(), mockConsistencyManager )
180
195
val operations = listOf<Operation >(LoginUserOperation (appId, localOneSignalId, "externalId", null))
181
196
182
197
// When
@@ -195,7 +210,7 @@ class LoginUserOperationExecutorTests : FunSpec({
195
210
// Given
196
211
val mockUserBackendService = mockk<IUserBackendService >()
197
212
coEvery { mockUserBackendService.createUser(any(), any(), any(), any()) } returns
198
- CreateUserResponse (mapOf(IdentityConstants .ONESIGNAL_ID to remoteOneSignalId), PropertiesObject (), listOf())
213
+ CreateUserResponse (mapOf(IdentityConstants .ONESIGNAL_ID to remoteOneSignalId), PropertiesObject (), listOf(), rywData )
199
214
200
215
val mockIdentityOperationExecutor = mockk<IdentityOperationExecutor >()
201
216
@@ -214,6 +229,7 @@ class LoginUserOperationExecutorTests : FunSpec({
214
229
mockSubscriptionsModelStore,
215
230
MockHelper .configModelStore(),
216
231
MockHelper .languageContext(),
232
+ mockConsistencyManager,
217
233
)
218
234
val operations = listOf<Operation >(LoginUserOperation (appId, localOneSignalId, "externalId", null))
219
235
@@ -242,7 +258,7 @@ class LoginUserOperationExecutorTests : FunSpec({
242
258
val mockSubscriptionsModelStore = mockk<SubscriptionModelStore >()
243
259
244
260
val loginUserOperationExecutor =
245
- LoginUserOperationExecutor (mockIdentityOperationExecutor, MockHelper .applicationService(), MockHelper .deviceService(), mockUserBackendService, mockIdentityModelStore, mockPropertiesModelStore, mockSubscriptionsModelStore, MockHelper .configModelStore(), MockHelper .languageContext())
261
+ LoginUserOperationExecutor (mockIdentityOperationExecutor, MockHelper .applicationService(), MockHelper .deviceService(), mockUserBackendService, mockIdentityModelStore, mockPropertiesModelStore, mockSubscriptionsModelStore, MockHelper .configModelStore(), MockHelper .languageContext(), mockConsistencyManager )
246
262
val operations = listOf<Operation >(LoginUserOperation (appId, localOneSignalId, "externalId", "existingOneSignalId"))
247
263
248
264
// When
@@ -268,7 +284,7 @@ class LoginUserOperationExecutorTests : FunSpec({
268
284
// Given
269
285
val mockUserBackendService = mockk<IUserBackendService >()
270
286
coEvery { mockUserBackendService.createUser(any(), any(), any(), any()) } returns
271
- CreateUserResponse (mapOf(IdentityConstants .ONESIGNAL_ID to remoteOneSignalId), PropertiesObject (), listOf())
287
+ CreateUserResponse (mapOf(IdentityConstants .ONESIGNAL_ID to remoteOneSignalId), PropertiesObject (), listOf(), rywData )
272
288
273
289
val mockIdentityOperationExecutor = mockk<IdentityOperationExecutor >()
274
290
coEvery { mockIdentityOperationExecutor.execute(any()) } returns ExecutionResponse (ExecutionResult .FAIL_RETRY )
@@ -278,7 +294,7 @@ class LoginUserOperationExecutorTests : FunSpec({
278
294
val mockSubscriptionsModelStore = mockk<SubscriptionModelStore >()
279
295
280
296
val loginUserOperationExecutor =
281
- LoginUserOperationExecutor (mockIdentityOperationExecutor, MockHelper .applicationService(), MockHelper .deviceService(), mockUserBackendService, mockIdentityModelStore, mockPropertiesModelStore, mockSubscriptionsModelStore, MockHelper .configModelStore(), MockHelper .languageContext())
297
+ LoginUserOperationExecutor (mockIdentityOperationExecutor, MockHelper .applicationService(), MockHelper .deviceService(), mockUserBackendService, mockIdentityModelStore, mockPropertiesModelStore, mockSubscriptionsModelStore, MockHelper .configModelStore(), MockHelper .languageContext(), mockConsistencyManager )
282
298
val operations = listOf<Operation >(LoginUserOperation (appId, localOneSignalId, "externalId", "existingOneSignalId"))
283
299
284
300
// When
@@ -304,7 +320,7 @@ class LoginUserOperationExecutorTests : FunSpec({
304
320
// Given
305
321
val mockUserBackendService = mockk<IUserBackendService >()
306
322
coEvery { mockUserBackendService.createUser(any(), any(), any(), any()) } returns
307
- CreateUserResponse (mapOf(IdentityConstants .ONESIGNAL_ID to remoteOneSignalId), PropertiesObject (), listOf())
323
+ CreateUserResponse (mapOf(IdentityConstants .ONESIGNAL_ID to remoteOneSignalId), PropertiesObject (), listOf(), rywData )
308
324
309
325
val mockIdentityOperationExecutor = mockk<IdentityOperationExecutor >()
310
326
coEvery { mockIdentityOperationExecutor.execute(any()) } returns ExecutionResponse (ExecutionResult .FAIL_NORETRY )
@@ -314,7 +330,7 @@ class LoginUserOperationExecutorTests : FunSpec({
314
330
val mockSubscriptionsModelStore = mockk<SubscriptionModelStore >()
315
331
316
332
val loginUserOperationExecutor =
317
- LoginUserOperationExecutor (mockIdentityOperationExecutor, MockHelper .applicationService(), MockHelper .deviceService(), mockUserBackendService, mockIdentityModelStore, mockPropertiesModelStore, mockSubscriptionsModelStore, MockHelper .configModelStore(), MockHelper .languageContext())
333
+ LoginUserOperationExecutor (mockIdentityOperationExecutor, MockHelper .applicationService(), MockHelper .deviceService(), mockUserBackendService, mockIdentityModelStore, mockPropertiesModelStore, mockSubscriptionsModelStore, MockHelper .configModelStore(), MockHelper .languageContext(), mockConsistencyManager )
318
334
val operations = listOf<Operation >(LoginUserOperation (appId, localOneSignalId, "externalId", "existingOneSignalId"))
319
335
320
336
// When
@@ -352,7 +368,7 @@ class LoginUserOperationExecutorTests : FunSpec({
352
368
val mockSubscriptionsModelStore = mockk<SubscriptionModelStore >()
353
369
354
370
val loginUserOperationExecutor =
355
- LoginUserOperationExecutor (mockIdentityOperationExecutor, MockHelper .applicationService(), MockHelper .deviceService(), mockUserBackendService, mockIdentityModelStore, mockPropertiesModelStore, mockSubscriptionsModelStore, MockHelper .configModelStore(), MockHelper .languageContext())
371
+ LoginUserOperationExecutor (mockIdentityOperationExecutor, MockHelper .applicationService(), MockHelper .deviceService(), mockUserBackendService, mockIdentityModelStore, mockPropertiesModelStore, mockSubscriptionsModelStore, MockHelper .configModelStore(), MockHelper .languageContext(), mockConsistencyManager )
356
372
val operations = listOf<Operation >(LoginUserOperation (appId, localOneSignalId, "externalId", "existingOneSignalId"))
357
373
358
374
// When
@@ -385,6 +401,7 @@ class LoginUserOperationExecutorTests : FunSpec({
385
401
mapOf(IdentityConstants .ONESIGNAL_ID to remoteOneSignalId),
386
402
PropertiesObject (),
387
403
listOf(),
404
+ rywData,
388
405
)
389
406
// Given
390
407
val mockIdentityOperationExecutor = mockk<IdentityOperationExecutor >()
@@ -403,6 +420,7 @@ class LoginUserOperationExecutorTests : FunSpec({
403
420
mockSubscriptionsModelStore,
404
421
MockHelper .configModelStore(),
405
422
MockHelper .languageContext(),
423
+ mockConsistencyManager,
406
424
)
407
425
val operations =
408
426
listOf<Operation >(
@@ -471,6 +489,7 @@ class LoginUserOperationExecutorTests : FunSpec({
471
489
mapOf(IdentityConstants .ONESIGNAL_ID to remoteOneSignalId),
472
490
PropertiesObject (),
473
491
listOf(SubscriptionObject (remoteSubscriptionId1, SubscriptionObjectType .ANDROID_PUSH ), SubscriptionObject (remoteSubscriptionId2, SubscriptionObjectType .EMAIL )),
492
+ rywData,
474
493
)
475
494
// Given
476
495
val mockIdentityOperationExecutor = mockk<IdentityOperationExecutor >()
@@ -504,6 +523,7 @@ class LoginUserOperationExecutorTests : FunSpec({
504
523
mockSubscriptionsModelStore,
505
524
MockHelper .configModelStore(),
506
525
MockHelper .languageContext(),
526
+ mockConsistencyManager,
507
527
)
508
528
val operations =
509
529
listOf<Operation >(
@@ -557,6 +577,7 @@ class LoginUserOperationExecutorTests : FunSpec({
557
577
mapOf(IdentityConstants .ONESIGNAL_ID to remoteOneSignalId),
558
578
PropertiesObject (),
559
579
listOf(SubscriptionObject (remoteSubscriptionId1, SubscriptionObjectType .ANDROID_PUSH ), SubscriptionObject (remoteSubscriptionId2, SubscriptionObjectType .EMAIL )),
580
+ rywData,
560
581
)
561
582
// Given
562
583
val mockIdentityOperationExecutor = mockk<IdentityOperationExecutor >()
@@ -590,6 +611,7 @@ class LoginUserOperationExecutorTests : FunSpec({
590
611
mockSubscriptionsModelStore,
591
612
MockHelper .configModelStore(),
592
613
MockHelper .languageContext(),
614
+ mockConsistencyManager,
593
615
)
594
616
val operations =
595
617
listOf<Operation >(
@@ -643,6 +665,7 @@ class LoginUserOperationExecutorTests : FunSpec({
643
665
mapOf(IdentityConstants .ONESIGNAL_ID to remoteOneSignalId),
644
666
PropertiesObject (),
645
667
listOf(SubscriptionObject (remoteSubscriptionId1, SubscriptionObjectType .ANDROID_PUSH ), SubscriptionObject (remoteSubscriptionId2, SubscriptionObjectType .EMAIL )),
668
+ rywData,
646
669
)
647
670
// Given
648
671
val mockIdentityOperationExecutor = mockk<IdentityOperationExecutor >()
@@ -662,6 +685,7 @@ class LoginUserOperationExecutorTests : FunSpec({
662
685
mockSubscriptionsModelStore,
663
686
MockHelper .configModelStore(),
664
687
MockHelper .languageContext(),
688
+ mockConsistencyManager,
665
689
)
666
690
val operations =
667
691
listOf<Operation >(
@@ -706,7 +730,7 @@ class LoginUserOperationExecutorTests : FunSpec({
706
730
// Given
707
731
val mockUserBackendService = mockk<IUserBackendService >()
708
732
coEvery { mockUserBackendService.createUser(any(), any(), any(), any()) } returns
709
- CreateUserResponse (mapOf(IdentityConstants .ONESIGNAL_ID to remoteOneSignalId), PropertiesObject (), listOf())
733
+ CreateUserResponse (mapOf(IdentityConstants .ONESIGNAL_ID to remoteOneSignalId), PropertiesObject (), listOf(), rywData )
710
734
711
735
val mockIdentityOperationExecutor = mockk<IdentityOperationExecutor >()
712
736
@@ -725,6 +749,7 @@ class LoginUserOperationExecutorTests : FunSpec({
725
749
mockSubscriptionsModelStore,
726
750
MockHelper .configModelStore(),
727
751
MockHelper .languageContext(),
752
+ mockConsistencyManager,
728
753
)
729
754
// anonymous Login request
730
755
val operations = listOf<Operation >(LoginUserOperation (appId, localOneSignalId, null, null))
0 commit comments