From f894122c39e18577835f624b421557d20d7a5b36 Mon Sep 17 00:00:00 2001 From: Najm Sheikh Date: Tue, 25 Aug 2020 15:17:06 -0400 Subject: [PATCH] Clear data on Identity logout --- .../java/com/mparticle/kits/ButtonKit.java | 30 +++++++++++++++++-- .../com/mparticle/kits/ButtonKitTests.java | 8 +++++ 2 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/mparticle/kits/ButtonKit.java b/src/main/java/com/mparticle/kits/ButtonKit.java index 4101108..ba507cf 100755 --- a/src/main/java/com/mparticle/kits/ButtonKit.java +++ b/src/main/java/com/mparticle/kits/ButtonKit.java @@ -19,6 +19,7 @@ import com.mparticle.AttributionResult; import com.mparticle.commerce.CommerceEvent; import com.mparticle.commerce.Product; +import com.mparticle.identity.MParticleUser; import com.mparticle.internal.Logger; import java.math.BigDecimal; @@ -33,8 +34,8 @@ * Learn more at our Developer Docs */ public class ButtonKit extends KitIntegration implements KitIntegration.ActivityListener, - KitIntegration.CommerceListener, ButtonMerchant.AttributionTokenListener, - PostInstallIntentListener { + KitIntegration.CommerceListener, KitIntegration.IdentityListener, + ButtonMerchant.AttributionTokenListener, PostInstallIntentListener { public static final String ATTRIBUTE_REFERRER = "com.usebutton.source_token"; @@ -225,6 +226,31 @@ public List logEvent(CommerceEvent commerceEvent) { return null; } + /* + * Overrides for IdentityListener + */ + + @Override + public void onIdentifyCompleted(MParticleUser mParticleUser, + FilteredIdentityApiRequest filteredIdentityApiRequest) {} + + @Override + public void onLoginCompleted(MParticleUser mParticleUser, + FilteredIdentityApiRequest filteredIdentityApiRequest) {} + + @Override + public void onLogoutCompleted(MParticleUser mParticleUser, + FilteredIdentityApiRequest filteredIdentityApiRequest) { + merchant.clearAllData(applicationContext); + } + + @Override + public void onModifyCompleted(MParticleUser mParticleUser, + FilteredIdentityApiRequest filteredIdentityApiRequest) {} + + @Override + public void onUserIdentified(MParticleUser mParticleUser) {} + /* * Utility methods */ diff --git a/src/test/java/com/mparticle/kits/ButtonKitTests.java b/src/test/java/com/mparticle/kits/ButtonKitTests.java index 2f5277a..bc2c54c 100644 --- a/src/test/java/com/mparticle/kits/ButtonKitTests.java +++ b/src/test/java/com/mparticle/kits/ButtonKitTests.java @@ -17,6 +17,7 @@ import com.mparticle.commerce.CommerceEvent; import com.mparticle.commerce.Product; import com.mparticle.identity.IdentityApi; +import com.mparticle.identity.MParticleUser; import com.mparticle.internal.CoreCallbacks; import org.json.JSONArray; @@ -185,6 +186,13 @@ public void reset_shouldClearAllData() { verify(merchant).clearAllData(context); } + @Test + public void onLogoutCompleted_shouldClearAllData() { + buttonKit.onKitCreate(settings, context); + buttonKit.onLogoutCompleted(mock(MParticleUser.class), mock(FilteredIdentityApiRequest.class)); + verify(merchant).clearAllData(context); + } + @Test public void logEvent_noProductAction_shouldIgnoreCall() { Product product = new Product.Builder("Test", "987", 1).build();