Skip to content

Commit 48f9633

Browse files
committed
fixed SubscriptionBackendServiceTests
Test was out-of-date to the production changes we made a while ago.
1 parent f68ec94 commit 48f9633

File tree

1 file changed

+17
-15
lines changed

1 file changed

+17
-15
lines changed

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

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import com.onesignal.core.internal.http.HttpResponse
55
import com.onesignal.core.internal.http.IHttpClient
66
import com.onesignal.debug.LogLevel
77
import com.onesignal.debug.internal.logging.Logging
8-
import com.onesignal.testhelpers.extensions.RobolectricTest
98
import com.onesignal.user.internal.backend.impl.SubscriptionBackendService
109
import com.onesignal.user.internal.subscriptions.SubscriptionStatus
1110
import io.kotest.assertions.throwables.shouldThrowUnit
@@ -17,7 +16,8 @@ import io.mockk.coVerify
1716
import io.mockk.mockk
1817
import org.junit.runner.RunWith
1918

20-
@RobolectricTest
19+
// WARNING: Adding @RobolectricTest will cause JSONObject.map() to stop working
20+
// at runtime.
2121
@RunWith(KotestTestRunner::class)
2222
class SubscriptionBackendServiceTests : FunSpec({
2323
beforeAny {
@@ -29,7 +29,7 @@ class SubscriptionBackendServiceTests : FunSpec({
2929
val aliasLabel = "onesignal_id"
3030
val aliasValue = "11111111-1111-1111-1111-111111111111"
3131
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\" } }")
3333
val subscriptionBackendService = SubscriptionBackendService(spyHttpClient)
3434

3535
// When
@@ -48,13 +48,14 @@ class SubscriptionBackendServiceTests : FunSpec({
4848
response shouldBe "subscriptionId"
4949
coVerify {
5050
spyHttpClient.post(
51-
"apps/appId/user/by/$aliasLabel/$aliasValue/subscription",
51+
"apps/appId/users/by/$aliasLabel/$aliasValue/subscriptions",
5252
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
5859
},
5960
)
6061
}
@@ -92,13 +93,14 @@ class SubscriptionBackendServiceTests : FunSpec({
9293
// Then
9394
coVerify {
9495
spyHttpClient.post(
95-
"apps/appId/user/by/$aliasLabel/$aliasValue/subscription",
96+
"apps/appId/users/by/$aliasLabel/$aliasValue/subscriptions",
9697
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
102104
},
103105
)
104106
}

0 commit comments

Comments
 (0)