Skip to content

Commit

Permalink
fix: delete device token when clear identify
Browse files Browse the repository at this point in the history
  • Loading branch information
levibostian committed May 13, 2022
1 parent 834aca0 commit 72f9753
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
16 changes: 14 additions & 2 deletions sdk/src/main/java/io/customer/sdk/repository/ProfileRepository.kt
Expand Up @@ -72,8 +72,20 @@ class ProfileRepositoryImpl(
}

override fun clearIdentify() {
preferenceRepository.getIdentifier()?.let { identifier ->
preferenceRepository.removeIdentifier(identifier)
logger.debug("clearing identified profile request made")

val currentlyIdentifiedProfileId = preferenceRepository.getIdentifier()

if (currentlyIdentifiedProfileId == null) {
logger.info("no profile is currently identified. ignoring request to clear identified profile")
return
}

// delete token from profile to prevent sending the profile pushes when they are not identified in the SDK.
deviceRepository.deleteDeviceToken()

// delete identified from device storage to not associate future SDK calls to this profile
logger.debug("clearing profile from device storage")
preferenceRepository.removeIdentifier(currentlyIdentifiedProfileId)
}
}
Expand Up @@ -15,6 +15,7 @@ import org.mockito.Mockito.verifyNoInteractions
import org.mockito.kotlin.anyOrNull
import org.mockito.kotlin.inOrder
import org.mockito.kotlin.mock
import org.mockito.kotlin.never
import org.mockito.kotlin.verify
import org.mockito.kotlin.verifyNoMoreInteractions
import org.mockito.kotlin.whenever
Expand Down Expand Up @@ -150,20 +151,22 @@ class ProfileRepositoryTest : BaseTest() {
// clearIdentify

@Test
fun clearIdentify_verifyWhenCustomerIdentifyIsClearedItsRemovedInPrefsRepo() {
fun clearIdentify_verifyWhenCustomerIdentifyIsClearedItsRemovedInPrefsRepo_expectDeleteDeviceToken() {
val givenIdentifier = String.random
prefRepository.saveIdentifier(givenIdentifier)

repository.clearIdentify()

prefRepository.getIdentifier().shouldBeNull()
verify(deviceRepositoryMock).deleteDeviceToken()
}

@Test
fun clearIdentify_givenNoPreviouslyIdentifiedProfile_expectIgnoreRequest() {
fun clearIdentify_givenNoPreviouslyIdentifiedProfile_expectIgnoreRequest_expectDontDeleteDeviceToken() {
repository.clearIdentify()

prefRepository.getIdentifier().shouldBeNull()
verify(deviceRepositoryMock, never()).deleteDeviceToken()
}

// addCustomProfileAttributes
Expand Down

0 comments on commit 72f9753

Please sign in to comment.