-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: modify() call throws an exception when user is not present
When the AdId updates, we will generate a modify() request interanlly with the current user. When the current user is not present/null, this request currently fails with an error log or a thrown exception, if the SDK is running in Development mode. In order to avoid losing this modify request or causing an exception, we will defer the modify request until a user is present, if it is not already
- Loading branch information
1 parent
bdf2476
commit bb8b552
Showing
4 changed files
with
95 additions
and
25 deletions.
There are no files selected for viewing
54 changes: 54 additions & 0 deletions
54
android-core/src/androidTest/kotlin/com.mparticle/internal/UpdateAdIdIdentityTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package com.mparticle.internal | ||
|
||
import com.mparticle.MParticle | ||
import com.mparticle.MParticleOptions | ||
import com.mparticle.identity.BaseIdentityTask | ||
import com.mparticle.identity.IdentityApiRequest | ||
import com.mparticle.testutils.BaseCleanInstallEachTest | ||
import com.mparticle.testutils.MPLatch | ||
import org.junit.Test | ||
import kotlin.test.assertEquals | ||
import kotlin.test.assertNull | ||
|
||
class UpdateAdIdIdentityTest : BaseCleanInstallEachTest() { | ||
|
||
@Test | ||
fun testAdIdModifyNoUser() { | ||
// setup mock server so initial identity request will not set mpid | ||
mServer.setupHappyIdentify(0) | ||
val latch = MPLatch(1) | ||
MParticle.start( | ||
MParticleOptions.builder(mContext) | ||
.credentials("key", "secret") | ||
.identifyTask(BaseIdentityTask().addSuccessListener { latch.countDown() }) | ||
.build() | ||
) | ||
|
||
// execute CheckAdIdRunnable without a current user | ||
AppStateManager.CheckAdIdRunnable("newAdId", "oldAdId").run() | ||
assertNull(MParticle.getInstance()!!.Identity().currentUser) | ||
|
||
// set a current user | ||
mServer.addConditionalIdentityResponse(0, mStartingMpid) | ||
latch.await() | ||
|
||
// force a modify request to ensure that the modify request from the CheckAdIdRunnable is completed | ||
val latch2 = MPLatch(1) | ||
MParticle.getInstance()!!.Identity().modify(IdentityApiRequest.withEmptyUser().customerId("someId").build()) | ||
.addSuccessListener { latch2.countDown() } | ||
latch2.await() | ||
|
||
// check that modify request from CheckAdIdRunnable executed when current user was set | ||
mServer.Requests().modify.count { request -> | ||
request.asIdentityRequest().body.identity_changes.let { | ||
it.size == 1 && | ||
it[0].let { identityChange -> | ||
identityChange["new_value"] == "newAdId" && | ||
identityChange["old_value"] == "oldAdId" | ||
} | ||
} | ||
}.let { | ||
assertEquals(1, it) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters