@@ -5,7 +5,6 @@ import com.onesignal.core.internal.http.HttpResponse
5
5
import com.onesignal.core.internal.http.IHttpClient
6
6
import com.onesignal.debug.LogLevel
7
7
import com.onesignal.debug.internal.logging.Logging
8
- import com.onesignal.testhelpers.extensions.RobolectricTest
9
8
import com.onesignal.user.internal.backend.impl.SubscriptionBackendService
10
9
import com.onesignal.user.internal.subscriptions.SubscriptionStatus
11
10
import io.kotest.assertions.throwables.shouldThrowUnit
@@ -17,7 +16,8 @@ import io.mockk.coVerify
17
16
import io.mockk.mockk
18
17
import org.junit.runner.RunWith
19
18
20
- @RobolectricTest
19
+ // WARNING: Adding @RobolectricTest will cause JSONObject.map() to stop working
20
+ // at runtime.
21
21
@RunWith(KotestTestRunner ::class )
22
22
class SubscriptionBackendServiceTests : FunSpec ({
23
23
beforeAny {
@@ -29,7 +29,7 @@ class SubscriptionBackendServiceTests : FunSpec({
29
29
val aliasLabel = " onesignal_id"
30
30
val aliasValue = " 11111111-1111-1111-1111-111111111111"
31
31
val spyHttpClient = mockk<IHttpClient >()
32
- coEvery { spyHttpClient.post(any(), any()) } returns HttpResponse (202, "{id: \"subscriptionId\"}")
32
+ coEvery { spyHttpClient.post(any(), any()) } returns HttpResponse (202, "{ \"subscription\": { id: \"subscriptionId\" } }")
33
33
val subscriptionBackendService = SubscriptionBackendService (spyHttpClient)
34
34
35
35
// When
@@ -48,13 +48,14 @@ class SubscriptionBackendServiceTests : FunSpec({
48
48
response shouldBe " subscriptionId"
49
49
coVerify {
50
50
spyHttpClient.post(
51
- "apps/appId/user /by/$aliasLabel/$aliasValue/subscription ",
51
+ "apps/appId/users /by/$aliasLabel/$aliasValue/subscriptions ",
52
52
withArg {
53
- it.has("id") shouldBe false
54
- it.getString("type") shouldBe "AndroidPush "
55
- it.getString("token") shouldBe "pushToken"
56
- it.getBoolean("enabled") shouldBe true
57
- it.getInt("notification_types") shouldBe 1
53
+ val sub = it.getJSONObject("subscription")
54
+ sub.has("id") shouldBe false
55
+ sub.getString("type") shouldBe "AndroidPush "
56
+ sub.getString("token") shouldBe "pushToken"
57
+ sub.getBoolean("enabled") shouldBe true
58
+ sub.getInt("notification_types") shouldBe 1
58
59
},
59
60
)
60
61
}
@@ -92,13 +93,14 @@ class SubscriptionBackendServiceTests : FunSpec({
92
93
// Then
93
94
coVerify {
94
95
spyHttpClient.post(
95
- "apps/appId/user /by/$aliasLabel/$aliasValue/subscription ",
96
+ "apps/appId/users /by/$aliasLabel/$aliasValue/subscriptions ",
96
97
withArg {
97
- it.has("id") shouldBe false
98
- it.getString("type") shouldBe "AndroidPush "
99
- it.getString("token") shouldBe "pushToken"
100
- it.getBoolean("enabled") shouldBe true
101
- it.getInt("notification_types") shouldBe 1
98
+ val sub = it.getJSONObject("subscription")
99
+ sub.has("id") shouldBe false
100
+ sub.getString("type") shouldBe "AndroidPush "
101
+ sub.getString("token") shouldBe "pushToken"
102
+ sub.getBoolean("enabled") shouldBe true
103
+ sub.getInt("notification_types") shouldBe 1
102
104
},
103
105
)
104
106
}
0 commit comments