Skip to content

Commit

Permalink
Add: new test case for anonymous login with no create subscription an…
Browse files Browse the repository at this point in the history
…d fix some other test cases
  • Loading branch information
jinliu9508 committed Feb 4, 2025
1 parent e842703 commit 5f3df33
Showing 1 changed file with 61 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,16 @@ class LoginUserOperationExecutorTests : FunSpec({
val localSubscriptionId2 = "local-subscriptionId2"
val remoteSubscriptionId1 = "remote-subscriptionId1"
val remoteSubscriptionId2 = "remote-subscriptionId2"
val createSubscriptionOperation =
CreateSubscriptionOperation(
appId,
localOneSignalId,
"subscriptionId1",
SubscriptionType.PUSH,
true,
"pushToken1",
SubscriptionStatus.SUBSCRIBED,
)

test("login anonymous user successfully creates user") {
// Given
Expand All @@ -58,7 +68,7 @@ class LoginUserOperationExecutorTests : FunSpec({
val loginUserOperationExecutor =
LoginUserOperationExecutor(
mockIdentityOperationExecutor,
MockHelper.applicationService(),
AndroidMockHelper.applicationService(),
MockHelper.deviceService(),
mockUserBackendService,
mockIdentityModelStore,
Expand All @@ -67,7 +77,11 @@ class LoginUserOperationExecutorTests : FunSpec({
MockHelper.configModelStore(),
MockHelper.languageContext(),
)
val operations = listOf<Operation>(LoginUserOperation(appId, localOneSignalId, null, null))
val operations =
listOf<Operation>(
LoginUserOperation(appId, localOneSignalId, null, null),
createSubscriptionOperation,
)

// When
val response = loginUserOperationExecutor.execute(operations)
Expand Down Expand Up @@ -98,7 +112,7 @@ class LoginUserOperationExecutorTests : FunSpec({
val loginUserOperationExecutor =
LoginUserOperationExecutor(
mockIdentityOperationExecutor,
MockHelper.applicationService(),
AndroidMockHelper.applicationService(),
MockHelper.deviceService(),
mockUserBackendService,
mockIdentityModelStore,
Expand All @@ -107,7 +121,11 @@ class LoginUserOperationExecutorTests : FunSpec({
MockHelper.configModelStore(),
MockHelper.languageContext(),
)
val operations = listOf<Operation>(LoginUserOperation(appId, localOneSignalId, null, null))
val operations =
listOf<Operation>(
LoginUserOperation(appId, localOneSignalId, null, null),
createSubscriptionOperation,
)

// When
val response = loginUserOperationExecutor.execute(operations)
Expand All @@ -130,7 +148,7 @@ class LoginUserOperationExecutorTests : FunSpec({
val mockSubscriptionsModelStore = mockk<SubscriptionModelStore>()

val loginUserOperationExecutor =
LoginUserOperationExecutor(mockIdentityOperationExecutor, MockHelper.applicationService(), MockHelper.deviceService(), mockUserBackendService, mockIdentityModelStore, mockPropertiesModelStore, mockSubscriptionsModelStore, MockHelper.configModelStore(), MockHelper.languageContext())
LoginUserOperationExecutor(mockIdentityOperationExecutor, AndroidMockHelper.applicationService(), MockHelper.deviceService(), mockUserBackendService, mockIdentityModelStore, mockPropertiesModelStore, mockSubscriptionsModelStore, MockHelper.configModelStore(), MockHelper.languageContext())
val operations = listOf<Operation>(LoginUserOperation(appId, localOneSignalId, null, null))

// When
Expand Down Expand Up @@ -679,4 +697,42 @@ class LoginUserOperationExecutorTests : FunSpec({
)
}
}

test("ensure anonymous login with no other operations will fail with FAIL_NORETRY to release the queue from a bad state") {
// Given
val mockUserBackendService = mockk<IUserBackendService>()
coEvery { mockUserBackendService.createUser(any(), any(), any(), any()) } returns
CreateUserResponse(mapOf(IdentityConstants.ONESIGNAL_ID to remoteOneSignalId), PropertiesObject(), listOf())

val mockIdentityOperationExecutor = mockk<IdentityOperationExecutor>()

val mockIdentityModelStore = MockHelper.identityModelStore()
val mockPropertiesModelStore = MockHelper.propertiesModelStore()
val mockSubscriptionsModelStore = mockk<SubscriptionModelStore>()

val loginUserOperationExecutor =
LoginUserOperationExecutor(
mockIdentityOperationExecutor,
MockHelper.applicationService(),
MockHelper.deviceService(),
mockUserBackendService,
mockIdentityModelStore,
mockPropertiesModelStore,
mockSubscriptionsModelStore,
MockHelper.configModelStore(),
MockHelper.languageContext(),
)
// anonymous Login request
val operations = listOf<Operation>(LoginUserOperation(appId, localOneSignalId, null, null))

// When
val response = loginUserOperationExecutor.execute(operations)

// Then
response.result shouldBe ExecutionResult.FAIL_NORETRY
// ensure user is not created by the bad request
coVerify(
exactly = 0,
) { mockUserBackendService.createUser(appId, any(), any(), any()) }
}
})

0 comments on commit 5f3df33

Please sign in to comment.