Skip to content

Commit 4172f8b

Browse files
authored
Merge pull request #1749 from OneSignal/user-model/broken-unit-tests
[User Model] Ensure 100% unit test pass
2 parents f1f7bcb + b62b895 commit 4172f8b

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

OneSignalSDK/onesignal/core/src/main/java/com/onesignal/core/internal/application/impl/ApplicationService.kt

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ class ApplicationService() : IApplicationService, ActivityLifecycleCallbacks, On
102102
if (isCurrentActivityNull && isContextActivity) {
103103
current = context as Activity?
104104
_activityReferences = 1
105-
_nextResumeIsFirstActivity = true
105+
_nextResumeIsFirstActivity = false
106106
}
107107
} else {
108108
_nextResumeIsFirstActivity = true
@@ -138,12 +138,17 @@ class ApplicationService() : IApplicationService, ActivityLifecycleCallbacks, On
138138
override fun onActivityStarted(activity: Activity) {
139139
Logging.debug("ApplicationService.onActivityStarted($_activityReferences,$entryState): $activity")
140140

141+
if (current == activity) {
142+
return
143+
}
144+
141145
current = activity
142-
_activityReferences++
143146

144147
if ((!isInForeground || _nextResumeIsFirstActivity) && !_isActivityChangingConfigurations) {
145148
_activityReferences = 1
146149
handleFocus()
150+
} else {
151+
_activityReferences++
147152
}
148153
}
149154

OneSignalSDK/onesignal/core/src/test/java/com/onesignal/user/internal/operations/RefreshUserOperationExecutorTests.kt

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import org.junit.runner.RunWith
3131
@RunWith(KotestTestRunner::class)
3232
class RefreshUserOperationExecutorTests : FunSpec({
3333
val appId = "appId"
34+
val existingSubscriptionId1 = "existing-subscriptionId1"
3435
val remoteOneSignalId = "remote-onesignalId"
3536
val remoteSubscriptionId1 = "remote-subscriptionId1"
3637
val remoteSubscriptionId2 = "remote-subscriptionId2"
@@ -42,7 +43,7 @@ class RefreshUserOperationExecutorTests : FunSpec({
4243
CreateUserResponse(
4344
mapOf(IdentityConstants.ONESIGNAL_ID to remoteOneSignalId, "aliasLabel1" to "aliasValue1"),
4445
PropertiesObject(country = "US"),
45-
listOf(SubscriptionObject(remoteSubscriptionId1, SubscriptionObjectType.ANDROID_PUSH, enabled = true, token = "pushToken"), SubscriptionObject(remoteSubscriptionId2, SubscriptionObjectType.EMAIL, token = "name@company.com")),
46+
listOf(SubscriptionObject(existingSubscriptionId1, SubscriptionObjectType.ANDROID_PUSH, enabled = true, token = "pushToken1"), SubscriptionObject(remoteSubscriptionId1, SubscriptionObjectType.ANDROID_PUSH, enabled = true, token = "pushToken2"), SubscriptionObject(remoteSubscriptionId2, SubscriptionObjectType.EMAIL, token = "name@company.com")),
4647
)
4748

4849
/* Given */
@@ -63,14 +64,18 @@ class RefreshUserOperationExecutorTests : FunSpec({
6364
val mockSubscriptionsModelStore = mockk<SubscriptionModelStore>()
6465
every { mockSubscriptionsModelStore.replaceAll(any(), any()) } just runs
6566

67+
val mockConfigModelStore = MockHelper.configModelStore {
68+
it.pushSubscriptionId = existingSubscriptionId1
69+
}
70+
6671
val mockBuildUserService = mockk<IRebuildUserService>()
6772

6873
val loginUserOperationExecutor = RefreshUserOperationExecutor(
6974
mockUserBackendService,
7075
mockIdentityModelStore,
7176
mockPropertiesModelStore,
7277
mockSubscriptionsModelStore,
73-
MockHelper.configModelStore(),
78+
mockConfigModelStore,
7479
mockBuildUserService,
7580
)
7681

@@ -99,10 +104,10 @@ class RefreshUserOperationExecutorTests : FunSpec({
99104
mockSubscriptionsModelStore.replaceAll(
100105
withArg {
101106
it.count() shouldBe 2
102-
it[0].id shouldBe remoteSubscriptionId1
107+
it[0].id shouldBe existingSubscriptionId1
103108
it[0].type shouldBe SubscriptionType.PUSH
104109
it[0].optedIn shouldBe true
105-
it[0].address shouldBe "pushToken"
110+
it[0].address shouldBe "pushToken1"
106111
it[1].id shouldBe remoteSubscriptionId2
107112
it[1].type shouldBe SubscriptionType.EMAIL
108113
it[1].optedIn shouldBe true

0 commit comments

Comments
 (0)