Skip to content

Commit da91c6a

Browse files
committed
Fix tests after create user operation changes
* Delete test `create user with an alias and properties creates a new user` * change arguments to `createUser()` after the `properties` parameter is removed
1 parent f1d204e commit da91c6a

File tree

2 files changed

+19
-68
lines changed

2 files changed

+19
-68
lines changed

OneSignalSDK/onesignal/core/src/test/java/com/onesignal/user/internal/backend/UserBackendServiceTests.kt

Lines changed: 3 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,11 @@ class UserBackendServiceTests : FunSpec({
2828
coEvery { spyHttpClient.post(any(), any()) } returns HttpResponse(403, "FORBIDDEN")
2929
val userBackendService = UserBackendService(spyHttpClient)
3030
val identities = mapOf<String, String>()
31-
val properties = PropertiesObject()
3231
val subscriptions = listOf<SubscriptionObject>()
3332

3433
/* When */
3534
val exception = shouldThrowUnit<BackendException> {
36-
userBackendService.createUser("appId", identities, properties, subscriptions)
35+
userBackendService.createUser("appId", identities, subscriptions)
3736
}
3837

3938
/* Then */
@@ -48,11 +47,10 @@ class UserBackendServiceTests : FunSpec({
4847
coEvery { spyHttpClient.post(any(), any()) } returns HttpResponse(202, "{identity:{onesignal_id: \"$osId\", aliasLabel1: \"aliasValue1\"}}")
4948
val userBackendService = UserBackendService(spyHttpClient)
5049
val identities = mapOf("aliasLabel1" to "aliasValue1")
51-
val properties = PropertiesObject()
5250
val subscriptions = listOf<SubscriptionObject>()
5351

5452
/* When */
55-
val response = userBackendService.createUser("appId", identities, properties, subscriptions)
53+
val response = userBackendService.createUser("appId", identities, subscriptions)
5654

5755
/* Then */
5856
response.identities["onesignal_id"] shouldBe osId
@@ -79,12 +77,11 @@ class UserBackendServiceTests : FunSpec({
7977
coEvery { spyHttpClient.post(any(), any()) } returns HttpResponse(202, "{identity:{onesignal_id: \"$osId\"}, subscriptions:[{id:\"subscriptionId1\", type:\"AndroidPush\"}]}")
8078
val userBackendService = UserBackendService(spyHttpClient)
8179
val identities = mapOf<String, String>()
82-
val properties = PropertiesObject()
8380
val subscriptions = mutableListOf<SubscriptionObject>()
8481
subscriptions.add(SubscriptionObject("SHOULDNOTUSE", SubscriptionObjectType.ANDROID_PUSH))
8582

8683
/* When */
87-
val response = userBackendService.createUser("appId", identities, properties, subscriptions)
84+
val response = userBackendService.createUser("appId", identities, subscriptions)
8885

8986
/* Then */
9087
response.identities["onesignal_id"] shouldBe osId
@@ -107,40 +104,6 @@ class UserBackendServiceTests : FunSpec({
107104
}
108105
}
109106

110-
test("create user with an alias and properties creates a new user") {
111-
/* Given */
112-
val osId = "11111111-1111-1111-1111-111111111111"
113-
val spyHttpClient = mockk<IHttpClient>()
114-
coEvery { spyHttpClient.post(any(), any()) } returns HttpResponse(202, "{identity:{onesignal_id: \"$osId\", aliasLabel1: \"aliasValue1\"}, properties: { tags: {tagKey1: tagValue1}}}")
115-
val userBackendService = UserBackendService(spyHttpClient)
116-
val identities = mapOf("aliasLabel1" to "aliasValue1")
117-
val properties = PropertiesObject(tags = mapOf("tagkey1" to "tagValue1"))
118-
val subscriptions = listOf<SubscriptionObject>()
119-
120-
/* When */
121-
val response = userBackendService.createUser("appId", identities, properties, subscriptions)
122-
123-
/* Then */
124-
response.identities["onesignal_id"] shouldBe osId
125-
response.identities["aliasLabel1"] shouldBe "aliasValue1"
126-
response.subscriptions.count() shouldBe 0
127-
coVerify {
128-
spyHttpClient.post(
129-
"apps/appId/users",
130-
withArg {
131-
it.has("identity") shouldBe true
132-
it.getJSONObject("identity").has("aliasLabel1") shouldBe true
133-
it.getJSONObject("identity").getString("aliasLabel1") shouldBe "aliasValue1"
134-
it.has("properties") shouldBe true
135-
it.getJSONObject("properties").has("tags") shouldBe true
136-
it.getJSONObject("properties").getJSONObject("tags").has("tagkey1") shouldBe true
137-
it.getJSONObject("properties").getJSONObject("tags").getString("tagkey1") shouldBe "tagValue1"
138-
it.has("subscriptions") shouldBe false
139-
},
140-
)
141-
}
142-
}
143-
144107
test("update user tags") {
145108
/* Given */
146109
val aliasLabel = "onesignal_id"

OneSignalSDK/onesignal/core/src/test/java/com/onesignal/user/internal/operations/LoginUserOperationExecutorTests.kt

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class LoginUserOperationExecutorTests : FunSpec({
4646
test("login anonymous user successfully creates user") {
4747
/* Given */
4848
val mockUserBackendService = mockk<IUserBackendService>()
49-
coEvery { mockUserBackendService.createUser(any(), any(), any(), any()) } returns
49+
coEvery { mockUserBackendService.createUser(any(), any(), any()) } returns
5050
CreateUserResponse(
5151
mapOf(IdentityConstants.ONESIGNAL_ID to remoteOneSignalId),
5252
PropertiesObject(),
@@ -80,15 +80,14 @@ class LoginUserOperationExecutorTests : FunSpec({
8080
appId,
8181
mapOf(),
8282
any(),
83-
any(),
8483
)
8584
}
8685
}
8786

8887
test("login anonymous user fails with retry when network condition exists") {
8988
/* Given */
9089
val mockUserBackendService = mockk<IUserBackendService>()
91-
coEvery { mockUserBackendService.createUser(any(), any(), any(), any()) } throws BackendException(408, "TIMEOUT")
90+
coEvery { mockUserBackendService.createUser(any(), any(), any()) } throws BackendException(408, "TIMEOUT")
9291

9392
val mockIdentityOperationExecutor = mockk<IdentityOperationExecutor>()
9493

@@ -104,13 +103,13 @@ class LoginUserOperationExecutorTests : FunSpec({
104103

105104
/* Then */
106105
response.result shouldBe ExecutionResult.FAIL_RETRY
107-
coVerify(exactly = 1) { mockUserBackendService.createUser(appId, mapOf(), any(), any()) }
106+
coVerify(exactly = 1) { mockUserBackendService.createUser(appId, mapOf(), any()) }
108107
}
109108

110109
test("login anonymous user fails with no retry when backend error condition exists") {
111110
/* Given */
112111
val mockUserBackendService = mockk<IUserBackendService>()
113-
coEvery { mockUserBackendService.createUser(any(), any(), any(), any()) } throws BackendException(404, "NOT FOUND")
112+
coEvery { mockUserBackendService.createUser(any(), any(), any()) } throws BackendException(404, "NOT FOUND")
114113

115114
val mockIdentityOperationExecutor = mockk<IdentityOperationExecutor>()
116115

@@ -126,13 +125,13 @@ class LoginUserOperationExecutorTests : FunSpec({
126125

127126
/* Then */
128127
response.result shouldBe ExecutionResult.FAIL_NORETRY
129-
coVerify(exactly = 1) { mockUserBackendService.createUser(appId, mapOf(), any(), any()) }
128+
coVerify(exactly = 1) { mockUserBackendService.createUser(appId, mapOf(), any()) }
130129
}
131130

132131
test("login identified user without association successfully creates user") {
133132
/* Given */
134133
val mockUserBackendService = mockk<IUserBackendService>()
135-
coEvery { mockUserBackendService.createUser(any(), any(), any(), any()) } returns
134+
coEvery { mockUserBackendService.createUser(any(), any(), any()) } returns
136135
CreateUserResponse(mapOf(IdentityConstants.ONESIGNAL_ID to remoteOneSignalId), PropertiesObject(), listOf())
137136

138137
val mockIdentityOperationExecutor = mockk<IdentityOperationExecutor>()
@@ -149,7 +148,7 @@ class LoginUserOperationExecutorTests : FunSpec({
149148

150149
/* Then */
151150
response.result shouldBe ExecutionResult.SUCCESS
152-
coVerify(exactly = 1) { mockUserBackendService.createUser(appId, mapOf(IdentityConstants.EXTERNAL_ID to "externalId"), any(), any()) }
151+
coVerify(exactly = 1) { mockUserBackendService.createUser(appId, mapOf(IdentityConstants.EXTERNAL_ID to "externalId"), any()) }
153152
}
154153

155154
test("login identified user with association succeeds when association is successful") {
@@ -188,7 +187,7 @@ class LoginUserOperationExecutorTests : FunSpec({
188187
test("login identified user with association fails with retry when association fails with retry") {
189188
/* Given */
190189
val mockUserBackendService = mockk<IUserBackendService>()
191-
coEvery { mockUserBackendService.createUser(any(), any(), any(), any()) } returns
190+
coEvery { mockUserBackendService.createUser(any(), any(), any()) } returns
192191
CreateUserResponse(mapOf(IdentityConstants.ONESIGNAL_ID to remoteOneSignalId), PropertiesObject(), listOf())
193192

194193
val mockIdentityOperationExecutor = mockk<IdentityOperationExecutor>()
@@ -223,7 +222,7 @@ class LoginUserOperationExecutorTests : FunSpec({
223222
test("login identified user with association successfully creates user when association fails with no retry") {
224223
/* Given */
225224
val mockUserBackendService = mockk<IUserBackendService>()
226-
coEvery { mockUserBackendService.createUser(any(), any(), any(), any()) } returns
225+
coEvery { mockUserBackendService.createUser(any(), any(), any()) } returns
227226
CreateUserResponse(mapOf(IdentityConstants.ONESIGNAL_ID to remoteOneSignalId), PropertiesObject(), listOf())
228227

229228
val mockIdentityOperationExecutor = mockk<IdentityOperationExecutor>()
@@ -253,13 +252,13 @@ class LoginUserOperationExecutorTests : FunSpec({
253252
},
254253
)
255254
}
256-
coVerify(exactly = 1) { mockUserBackendService.createUser(appId, mapOf(IdentityConstants.EXTERNAL_ID to "externalId"), any(), any()) }
255+
coVerify(exactly = 1) { mockUserBackendService.createUser(appId, mapOf(IdentityConstants.EXTERNAL_ID to "externalId"), any()) }
257256
}
258257

259258
test("login identified user with association fails with retry when association fails with no retry and network condition exists") {
260259
/* Given */
261260
val mockUserBackendService = mockk<IUserBackendService>()
262-
coEvery { mockUserBackendService.createUser(any(), any(), any(), any()) } throws BackendException(408, "TIMEOUT")
261+
coEvery { mockUserBackendService.createUser(any(), any(), any()) } throws BackendException(408, "TIMEOUT")
263262

264263
val mockIdentityOperationExecutor = mockk<IdentityOperationExecutor>()
265264
coEvery { mockIdentityOperationExecutor.execute(any()) } returns ExecutionResponse(ExecutionResult.FAIL_NORETRY)
@@ -288,13 +287,13 @@ class LoginUserOperationExecutorTests : FunSpec({
288287
},
289288
)
290289
}
291-
coVerify(exactly = 1) { mockUserBackendService.createUser(appId, mapOf(IdentityConstants.EXTERNAL_ID to "externalId"), any(), any()) }
290+
coVerify(exactly = 1) { mockUserBackendService.createUser(appId, mapOf(IdentityConstants.EXTERNAL_ID to "externalId"), any()) }
292291
}
293292

294293
test("creating user will merge operations into one backend call") {
295294
/* Given */
296295
val mockUserBackendService = mockk<IUserBackendService>()
297-
coEvery { mockUserBackendService.createUser(any(), any(), any(), any()) } returns
296+
coEvery { mockUserBackendService.createUser(any(), any(), any()) } returns
298297
CreateUserResponse(
299298
mapOf(IdentityConstants.ONESIGNAL_ID to remoteOneSignalId),
300299
PropertiesObject(),
@@ -351,14 +350,6 @@ class LoginUserOperationExecutorTests : FunSpec({
351350
mockUserBackendService.createUser(
352351
appId,
353352
mapOf("aliasLabel1" to "aliasValue1-2"),
354-
withArg {
355-
it.country shouldBe "country"
356-
it.language shouldBe "lang2"
357-
it.timezoneId shouldBe "timezone"
358-
it.latitude shouldBe 123.45
359-
it.longitude shouldBe 678.90
360-
it.tags shouldBe mapOf("tagKey1" to "tagValue1-2")
361-
},
362353
withArg {
363354
it.count() shouldBe 1
364355
it[0].type shouldBe SubscriptionObjectType.ANDROID_PUSH
@@ -373,7 +364,7 @@ class LoginUserOperationExecutorTests : FunSpec({
373364
test("creating user will hydrate when the user hasn't changed") {
374365
/* Given */
375366
val mockUserBackendService = mockk<IUserBackendService>()
376-
coEvery { mockUserBackendService.createUser(any(), any(), any(), any()) } returns
367+
coEvery { mockUserBackendService.createUser(any(), any(), any()) } returns
377368
CreateUserResponse(
378369
mapOf(IdentityConstants.ONESIGNAL_ID to remoteOneSignalId),
379370
PropertiesObject(),
@@ -432,15 +423,14 @@ class LoginUserOperationExecutorTests : FunSpec({
432423
appId,
433424
mapOf(),
434425
any(),
435-
any(),
436426
)
437427
}
438428
}
439429

440430
test("creating user will not hydrate when the user has changed") {
441431
/* Given */
442432
val mockUserBackendService = mockk<IUserBackendService>()
443-
coEvery { mockUserBackendService.createUser(any(), any(), any(), any()) } returns
433+
coEvery { mockUserBackendService.createUser(any(), any(), any()) } returns
444434
CreateUserResponse(
445435
mapOf(IdentityConstants.ONESIGNAL_ID to remoteOneSignalId),
446436
PropertiesObject(),
@@ -499,15 +489,14 @@ class LoginUserOperationExecutorTests : FunSpec({
499489
appId,
500490
mapOf(),
501491
any(),
502-
any(),
503492
)
504493
}
505494
}
506495

507496
test("creating user will provide local to remote translations") {
508497
/* Given */
509498
val mockUserBackendService = mockk<IUserBackendService>()
510-
coEvery { mockUserBackendService.createUser(any(), any(), any(), any()) } returns
499+
coEvery { mockUserBackendService.createUser(any(), any(), any()) } returns
511500
CreateUserResponse(
512501
mapOf(IdentityConstants.ONESIGNAL_ID to remoteOneSignalId),
513502
PropertiesObject(),
@@ -547,7 +536,6 @@ class LoginUserOperationExecutorTests : FunSpec({
547536
appId,
548537
mapOf(),
549538
any(),
550-
any(),
551539
)
552540
}
553541
}

0 commit comments

Comments
 (0)