Skip to content
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ class LoginHelper(
currentIdentityExternalId = identityModelStore.model.externalId
currentIdentityOneSignalId = identityModelStore.model.onesignalId

if (currentIdentityExternalId == externalId) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This same behaviour exists in iOS, so we need to figure out what is it thats different we are doing.

is it possible that the login method is called so quickly and identityModelStore is not setup yet?

return
}

// always create a user on login in case of externalId being removed in backend
// TODO: Set JWT Token for all future requests.
userSwitcher.createAndSwitchToNewUser { identityModel, _ ->
identityModel.externalId = externalId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,9 @@ class LoginHelperTests : FunSpec({
Logging.logLevel = LogLevel.NONE
}

test("login with same external id returns early without creating user") {
// in the event of externalId being removed in the backend, SDK needs to send a CreateUser request
// to restore the externalId for the subscription
test("login with same external id still creates a user") {
// Given
val mockIdentityModelStore =
MockHelper.identityModelStore { model ->
Expand All @@ -64,9 +66,9 @@ class LoginHelperTests : FunSpec({
loginHelper.login(currentExternalId)
}

// Then - should return early without any operations
verify(exactly = 0) { mockUserSwitcher.createAndSwitchToNewUser(suppressBackendOperation = any(), modify = any()) }
coVerify(exactly = 0) { mockOperationRepo.enqueueAndWait(any()) }
// Then - should create a user and send a request
verify(exactly = 1) { mockUserSwitcher.createAndSwitchToNewUser(suppressBackendOperation = any(), modify = any()) }
coVerify(exactly = 1) { mockOperationRepo.enqueueAndWait(any()) }
}

test("login with different external id creates and switches to new user") {
Expand Down