@@ -8,6 +8,7 @@ import com.onesignal.debug.LogLevel
8
8
import com.onesignal.debug.internal.logging.Logging
9
9
import com.onesignal.user.internal.backend.impl.SubscriptionBackendService
10
10
import com.onesignal.user.internal.subscriptions.SubscriptionStatus
11
+ import com.onesignal.user.internal.subscriptions.SubscriptionType
11
12
import io.kotest.assertions.throwables.shouldThrowUnit
12
13
import io.kotest.core.spec.style.FunSpec
13
14
import io.kotest.matchers.shouldBe
@@ -107,4 +108,45 @@ class SubscriptionBackendServiceTests : FunSpec({
107
108
)
108
109
}
109
110
}
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
+ }
110
152
})
0 commit comments