Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
- name: "[Test] SDK Unit Tests"
working-directory: OneSignalSDK
run: |
./gradlew test --console=plain
./gradlew testReleaseUnitTest --console=plain --continue
- name: Unit tests results
if: failure()
uses: actions/upload-artifact@v3
Expand Down
4 changes: 2 additions & 2 deletions OneSignalSDK/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ buildscript {

ext {
buildVersions = [
compileSdkVersion: 31,
targetSdkVersion: 31,
compileSdkVersion: 34,
targetSdkVersion: 34,
minSdkVersion: 19
]
androidGradlePluginVersion = '7.2.0'
Expand Down
1 change: 1 addition & 0 deletions OneSignalSDK/onesignal/core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ dependencies {
}
}

testImplementation(project(':OneSignal:testhelpers'))
testImplementation("junit:junit:$junitVersion")
testImplementation("io.kotest:kotest-runner-junit4:$kotestVersion")
testImplementation("io.kotest:kotest-runner-junit4-jvm:$kotestVersion")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ internal class SubscriptionBackendService(
aliasValue: String,
subscription: SubscriptionObject,
): String? {
val requestJSON =
JSONObject()
.put("subscription", JSONConverter.convertToJSON(subscription))
val jsonSubscription = JSONConverter.convertToJSON(subscription)
jsonSubscription.remove("id")
val requestJSON = JSONObject().put("subscription", jsonSubscription)

val response = _httpClient.post("apps/$appId/users/by/$aliasLabel/$aliasValue/subscriptions", requestJSON)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import com.onesignal.common.threading.suspendifyOnThread
import com.onesignal.core.internal.application.impl.ApplicationService
import com.onesignal.debug.LogLevel
import com.onesignal.debug.internal.logging.Logging
import com.onesignal.extensions.RobolectricTest
import com.onesignal.testhelpers.extensions.RobolectricTest
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import io.kotest.runner.junit4.KotestTestRunner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ import com.onesignal.core.internal.database.impl.OSDatabase
import com.onesignal.core.internal.database.impl.OneSignalDbContract
import com.onesignal.debug.LogLevel
import com.onesignal.debug.internal.logging.Logging
import com.onesignal.extensions.RobolectricTest
import com.onesignal.session.internal.outcomes.impl.OutcomeTableProvider
import com.onesignal.testhelpers.extensions.RobolectricTest
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import io.kotest.runner.junit4.KotestTestRunner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ import androidx.test.core.app.ApplicationProvider
import com.onesignal.core.internal.preferences.impl.PreferencesService
import com.onesignal.debug.LogLevel
import com.onesignal.debug.internal.logging.Logging
import com.onesignal.extensions.RobolectricTest
import com.onesignal.mocks.AndroidMockHelper
import com.onesignal.mocks.MockHelper
import com.onesignal.testhelpers.extensions.RobolectricTest
import io.kotest.assertions.throwables.shouldThrowUnit
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.onesignal.session.internal.outcomes

import com.onesignal.debug.LogLevel
import com.onesignal.debug.internal.logging.Logging
import com.onesignal.extensions.RobolectricTest
import com.onesignal.mocks.DatabaseMockHelper
import com.onesignal.session.internal.influence.Influence
import com.onesignal.session.internal.influence.InfluenceChannel
Expand All @@ -13,6 +12,7 @@ import com.onesignal.session.internal.outcomes.impl.OutcomeEventsRepository
import com.onesignal.session.internal.outcomes.impl.OutcomeEventsTable
import com.onesignal.session.internal.outcomes.impl.OutcomeSource
import com.onesignal.session.internal.outcomes.impl.OutcomeSourceBody
import com.onesignal.testhelpers.extensions.RobolectricTest
import io.kotest.core.spec.style.FunSpec
import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe
Expand Down Expand Up @@ -171,13 +171,15 @@ class OutcomeEventsRepositoryTests : FunSpec({
OutcomeEventsTable.COLUMN_NAME_NAME to "outcomeId1",
OutcomeEventsTable.COLUMN_NAME_WEIGHT to 0.2f,
OutcomeEventsTable.COLUMN_NAME_TIMESTAMP to 1111L,
OutcomeEventsTable.COLUMN_NAME_SESSION_TIME to 1L,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Noting this column was added in #1793

OutcomeEventsTable.COLUMN_NAME_NOTIFICATION_INFLUENCE_TYPE to "unattributed",
OutcomeEventsTable.COLUMN_NAME_IAM_INFLUENCE_TYPE to "unattributed",
),
mapOf(
OutcomeEventsTable.COLUMN_NAME_NAME to "outcomeId2",
OutcomeEventsTable.COLUMN_NAME_WEIGHT to 0.4f,
OutcomeEventsTable.COLUMN_NAME_TIMESTAMP to 2222L,
OutcomeEventsTable.COLUMN_NAME_SESSION_TIME to 2L,
OutcomeEventsTable.COLUMN_NAME_NOTIFICATION_INFLUENCE_TYPE to "indirect",
OutcomeEventsTable.COLUMN_NAME_NOTIFICATION_IDS to "[\"notificationId1\",\"notificationId2\"]",
OutcomeEventsTable.COLUMN_NAME_IAM_INFLUENCE_TYPE to "indirect",
Expand All @@ -187,6 +189,7 @@ class OutcomeEventsRepositoryTests : FunSpec({
OutcomeEventsTable.COLUMN_NAME_NAME to "outcomeId3",
OutcomeEventsTable.COLUMN_NAME_WEIGHT to 0.6f,
OutcomeEventsTable.COLUMN_NAME_TIMESTAMP to 3333L,
OutcomeEventsTable.COLUMN_NAME_SESSION_TIME to 3L,
OutcomeEventsTable.COLUMN_NAME_NOTIFICATION_INFLUENCE_TYPE to "direct",
OutcomeEventsTable.COLUMN_NAME_NOTIFICATION_IDS to "[\"notificationId3\"]",
OutcomeEventsTable.COLUMN_NAME_IAM_INFLUENCE_TYPE to "direct",
Expand All @@ -205,12 +208,14 @@ class OutcomeEventsRepositoryTests : FunSpec({
events[0].outcomeId shouldBe "outcomeId1"
events[0].weight shouldBe 0.2f
events[0].timestamp shouldBe 1111L
events[0].sessionTime shouldBe 1L
events[0].outcomeSource shouldNotBe null
events[0].outcomeSource!!.directBody shouldBe null
events[0].outcomeSource!!.indirectBody shouldBe null
events[1].outcomeId shouldBe "outcomeId2"
events[1].weight shouldBe 0.4f
events[1].timestamp shouldBe 2222L
events[1].sessionTime shouldBe 2L
events[1].outcomeSource shouldNotBe null
events[1].outcomeSource!!.directBody shouldBe null
events[1].outcomeSource!!.indirectBody shouldNotBe null
Expand All @@ -223,6 +228,7 @@ class OutcomeEventsRepositoryTests : FunSpec({
events[2].outcomeId shouldBe "outcomeId3"
events[2].weight shouldBe 0.6f
events[2].timestamp shouldBe 3333L
events[2].sessionTime shouldBe 3L
events[2].outcomeSource shouldNotBe null
events[2].outcomeSource!!.indirectBody shouldBe null
events[2].outcomeSource!!.directBody shouldNotBe null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import com.onesignal.core.internal.http.HttpResponse
import com.onesignal.core.internal.http.IHttpClient
import com.onesignal.debug.LogLevel
import com.onesignal.debug.internal.logging.Logging
import com.onesignal.extensions.RobolectricTest
import com.onesignal.user.internal.backend.impl.SubscriptionBackendService
import com.onesignal.user.internal.subscriptions.SubscriptionStatus
import io.kotest.assertions.throwables.shouldThrowUnit
Expand All @@ -17,7 +16,8 @@ import io.mockk.coVerify
import io.mockk.mockk
import org.junit.runner.RunWith

@RobolectricTest
// WARNING: Adding @RobolectricTest will cause JSONObject.map() to stop working
// at runtime.
@RunWith(KotestTestRunner::class)
class SubscriptionBackendServiceTests : FunSpec({
beforeAny {
Expand All @@ -29,7 +29,7 @@ class SubscriptionBackendServiceTests : FunSpec({
val aliasLabel = "onesignal_id"
val aliasValue = "11111111-1111-1111-1111-111111111111"
val spyHttpClient = mockk<IHttpClient>()
coEvery { spyHttpClient.post(any(), any()) } returns HttpResponse(202, "{id: \"subscriptionId\"}")
coEvery { spyHttpClient.post(any(), any()) } returns HttpResponse(202, "{ \"subscription\": { id: \"subscriptionId\" } }")
val subscriptionBackendService = SubscriptionBackendService(spyHttpClient)

// When
Expand All @@ -48,13 +48,14 @@ class SubscriptionBackendServiceTests : FunSpec({
response shouldBe "subscriptionId"
coVerify {
spyHttpClient.post(
"apps/appId/user/by/$aliasLabel/$aliasValue/subscription",
"apps/appId/users/by/$aliasLabel/$aliasValue/subscriptions",
withArg {
it.has("id") shouldBe false
it.getString("type") shouldBe "AndroidPush"
it.getString("token") shouldBe "pushToken"
it.getBoolean("enabled") shouldBe true
it.getInt("notification_types") shouldBe 1
val sub = it.getJSONObject("subscription")
sub.has("id") shouldBe false
sub.getString("type") shouldBe "AndroidPush"
sub.getString("token") shouldBe "pushToken"
sub.getBoolean("enabled") shouldBe true
sub.getInt("notification_types") shouldBe 1
},
)
}
Expand Down Expand Up @@ -92,13 +93,14 @@ class SubscriptionBackendServiceTests : FunSpec({
// Then
coVerify {
spyHttpClient.post(
"apps/appId/user/by/$aliasLabel/$aliasValue/subscription",
"apps/appId/users/by/$aliasLabel/$aliasValue/subscriptions",
withArg {
it.has("id") shouldBe false
it.getString("type") shouldBe "AndroidPush"
it.getString("token") shouldBe "pushToken"
it.getBoolean("enabled") shouldBe true
it.getInt("notification_types") shouldBe 1
val sub = it.getJSONObject("subscription")
sub.has("id") shouldBe false
sub.getString("type") shouldBe "AndroidPush"
sub.getString("token") shouldBe "pushToken"
sub.getBoolean("enabled") shouldBe true
sub.getInt("notification_types") shouldBe 1
},
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import com.onesignal.common.exceptions.BackendException
import com.onesignal.core.internal.operations.ExecutionResponse
import com.onesignal.core.internal.operations.ExecutionResult
import com.onesignal.core.internal.operations.Operation
import com.onesignal.extensions.RobolectricTest
import com.onesignal.mocks.AndroidMockHelper
import com.onesignal.mocks.MockHelper
import com.onesignal.testhelpers.extensions.RobolectricTest
import com.onesignal.user.internal.backend.CreateUserResponse
import com.onesignal.user.internal.backend.IUserBackendService
import com.onesignal.user.internal.backend.IdentityConstants
Expand Down Expand Up @@ -129,7 +129,7 @@ class LoginUserOperationExecutorTests : FunSpec({
val response = loginUserOperationExecutor.execute(operations)

// Then
response.result shouldBe ExecutionResult.FAIL_NORETRY
response.result shouldBe ExecutionResult.FAIL_PAUSE_OPREPO
coVerify(exactly = 1) { mockUserBackendService.createUser(appId, mapOf(), any(), any()) }
}

Expand Down Expand Up @@ -392,13 +392,18 @@ class LoginUserOperationExecutorTests : FunSpec({
coVerify(exactly = 1) {
mockUserBackendService.createUser(
appId,
mapOf("aliasLabel1" to "aliasValue1-2"),
// Aliases omitted intentionally in PR #1794, to avoid failed create user calls.
// - Ideally we batch as much as possible into the create as most of the time it
// should be successful. Then when there are failures omit the "bad data" and try
// again, however this is more complex which is why it wasn't done initially.
mapOf(),
withArg {
it.count() shouldBe 1
it[0].type shouldBe SubscriptionObjectType.ANDROID_PUSH
it[0].enabled shouldBe true
it[0].token shouldBe "pushToken2"
it[0].notificationTypes shouldBe SubscriptionStatus.SUBSCRIBED
val subscription = it[0]
subscription.type shouldBe SubscriptionObjectType.ANDROID_PUSH
subscription.enabled shouldBe true
subscription.token shouldBe "pushToken2"
SubscriptionStatus.fromInt(subscription.notificationTypes!!) shouldBe SubscriptionStatus.SUBSCRIBED
},
any(),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ package com.onesignal.user.internal.operations
import com.onesignal.common.exceptions.BackendException
import com.onesignal.core.internal.operations.ExecutionResult
import com.onesignal.core.internal.operations.Operation
import com.onesignal.extensions.RobolectricTest
import com.onesignal.mocks.AndroidMockHelper
import com.onesignal.mocks.MockHelper
import com.onesignal.testhelpers.extensions.RobolectricTest
import com.onesignal.user.internal.backend.ISubscriptionBackendService
import com.onesignal.user.internal.backend.IdentityConstants
import com.onesignal.user.internal.backend.SubscriptionObjectType
Expand Down Expand Up @@ -149,6 +149,7 @@ class SubscriptionOperationExecutorTests : FunSpec({

val mockSubscriptionsModelStore = mockk<SubscriptionModelStore>()
val mockBuildUserService = mockk<IRebuildUserService>()
every { mockBuildUserService.getRebuildOperationsIfCurrentUser(any(), any()) } answers { null }

val subscriptionOperationExecutor =
SubscriptionOperationExecutor(
Expand Down Expand Up @@ -350,7 +351,6 @@ class SubscriptionOperationExecutorTests : FunSpec({

// Then
response.result shouldBe ExecutionResult.SUCCESS
subscriptionModel1.address shouldBe "pushToken3"
coVerify(exactly = 1) {
mockSubscriptionBackendService.updateSubscription(
appId,
Expand Down Expand Up @@ -539,7 +539,9 @@ class SubscriptionOperationExecutorTests : FunSpec({
coVerify(exactly = 1) { mockSubscriptionBackendService.deleteSubscription(appId, remoteSubscriptionId) }
}

test("delete subscription fails without retry when there is a backend error") {
// If we get a 404 then the subscription has already been deleted,
// so we count it as successful
test("delete subscription is successful if there is a 404") {
// Given
val mockSubscriptionBackendService = mockk<ISubscriptionBackendService>()
coEvery { mockSubscriptionBackendService.deleteSubscription(any(), any()) } throws BackendException(404)
Expand All @@ -566,7 +568,7 @@ class SubscriptionOperationExecutorTests : FunSpec({
val response = subscriptionOperationExecutor.execute(operations)

// Then
response.result shouldBe ExecutionResult.FAIL_NORETRY
response.result shouldBe ExecutionResult.SUCCESS
coVerify(exactly = 1) { mockSubscriptionBackendService.deleteSubscription(appId, remoteSubscriptionId) }
}
})
1 change: 1 addition & 0 deletions OneSignalSDK/onesignal/in-app-messages/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ dependencies {
}
}

testImplementation(project(':OneSignal:testhelpers'))
testImplementation("junit:junit:$junitVersion")
testImplementation("io.kotest:kotest-runner-junit4:$kotestVersion")
testImplementation("io.kotest:kotest-runner-junit4-jvm:$kotestVersion")
Expand Down
Loading