Skip to content

Commit 213b0cc

Browse files
committed
add more test cases for delete subscription
1 parent f189713 commit 213b0cc

File tree

1 file changed

+42
-0
lines changed

1 file changed

+42
-0
lines changed

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

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import com.onesignal.debug.LogLevel
88
import com.onesignal.debug.internal.logging.Logging
99
import com.onesignal.user.internal.backend.impl.SubscriptionBackendService
1010
import com.onesignal.user.internal.subscriptions.SubscriptionStatus
11+
import com.onesignal.user.internal.subscriptions.SubscriptionType
1112
import io.kotest.assertions.throwables.shouldThrowUnit
1213
import io.kotest.core.spec.style.FunSpec
1314
import io.kotest.matchers.shouldBe
@@ -107,4 +108,45 @@ class SubscriptionBackendServiceTests : FunSpec({
107108
)
108109
}
109110
}
111+
112+
test("delete subscription by type and token successfully") {
113+
// Given
114+
val spyHttpClient = mockk<IHttpClient>()
115+
coEvery { spyHttpClient.delete(any(), any()) } returns HttpResponse(200, "")
116+
val subscriptionBackendService = SubscriptionBackendService(spyHttpClient)
117+
118+
// When
119+
subscriptionBackendService.deleteSubscription("appId", SubscriptionType.EMAIL, "test@example.com", "jwt-token")
120+
121+
// Then
122+
coVerify {
123+
spyHttpClient.delete(
124+
"apps/appId/by/type/email/token/test@example.com/subscriptions",
125+
any(),
126+
)
127+
}
128+
}
129+
130+
test("delete subscription throws exception when bad response") {
131+
// Given
132+
val spyHttpClient = mockk<IHttpClient>()
133+
coEvery { spyHttpClient.delete(any(), any()) } returns HttpResponse(404, "NOT FOUND")
134+
val subscriptionBackendService = SubscriptionBackendService(spyHttpClient)
135+
136+
// When
137+
val exception =
138+
shouldThrowUnit<BackendException> {
139+
subscriptionBackendService.deleteSubscription("appId", SubscriptionType.SMS, "+1234567890")
140+
}
141+
142+
// Then
143+
exception.statusCode shouldBe 404
144+
exception.response shouldBe "NOT FOUND"
145+
coVerify {
146+
spyHttpClient.delete(
147+
"apps/appId/by/type/sms/token/+1234567890/subscriptions",
148+
any(),
149+
)
150+
}
151+
}
110152
})

0 commit comments

Comments
 (0)