This repository has been archived by the owner on Apr 28, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add custom update subscription events (#7)
Add custom update subscription events
- Loading branch information
Showing
6 changed files
with
202 additions
and
13 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,7 @@ | |
import com.mparticle.sdk.model.registration.UserIdentityPermission; | ||
import org.junit.Test; | ||
import org.mockito.ArgumentCaptor; | ||
import org.mockito.Mock; | ||
import org.mockito.Mockito; | ||
import retrofit2.Call; | ||
import retrofit2.Response; | ||
|
@@ -155,7 +156,6 @@ public void testProcessRegistrationRequest() throws Exception { | |
assertTrue("Iterable should support custom events", eventTypes.contains(Event.Type.CUSTOM_EVENT)); | ||
assertTrue("Iterable should support push subscriptions", eventTypes.contains(Event.Type.PUSH_SUBSCRIPTION)); | ||
assertTrue("Iterable should support push receipts", eventTypes.contains(Event.Type.PUSH_MESSAGE_RECEIPT)); | ||
assertTrue("Iterable should support user attribute changes", eventTypes.contains(Event.Type.USER_ATTRIBUTE_CHANGE)); | ||
assertTrue("Iterable should support user identity changes", eventTypes.contains(Event.Type.USER_IDENTITY_CHANGE)); | ||
|
||
Setting setting = response.getAudienceProcessingRegistration().getAudienceConnectionSettings().get(0); | ||
|
@@ -639,4 +639,71 @@ public void testGetPlaceholderEmailEnvironmentAndroidID() throws Exception { | |
String email = IterableExtension.getPlaceholderEmail(request); | ||
assertEquals("[email protected]", email); | ||
} | ||
|
||
@org.junit.Test | ||
public void testUpdateSubscriptionsEvent() throws Exception { | ||
IterableExtension extension = new IterableExtension(); | ||
extension.iterableService = Mockito.mock(IterableService.class); | ||
Call callMock = Mockito.mock(Call.class); | ||
Mockito.when(extension.iterableService.updateSubscriptions(Mockito.any(), Mockito.any())) | ||
.thenReturn(callMock); | ||
Mockito.when(extension.iterableService.track(Mockito.any(), Mockito.any())) | ||
.thenReturn(callMock); | ||
IterableApiResponse apiResponse = new IterableApiResponse(); | ||
apiResponse.code = IterableApiResponse.SUCCESS_MESSAGE; | ||
Response<IterableApiResponse> response = Response.success(apiResponse); | ||
Mockito.when(callMock.execute()).thenReturn(response); | ||
|
||
long timeStamp = System.currentTimeMillis(); | ||
CustomEvent event = new CustomEvent(); | ||
event.setTimestamp(timeStamp); | ||
event.setName(IterableExtension.UPDATE_SUBSCRIPTIONS_CUSTOM_EVENT_NAME); | ||
EventProcessingRequest request = new EventProcessingRequest(); | ||
Account account = new Account(); | ||
Map<String, String> settings = new HashMap<>(); | ||
settings.put(SETTING_API_KEY, "foo api key 2"); | ||
account.setAccountSettings(settings); | ||
request.setAccount(account); | ||
List<UserIdentity> userIdentities = new LinkedList<>(); | ||
userIdentities.add(new UserIdentity(UserIdentity.Type.EMAIL, Identity.Encoding.RAW, "[email protected]")); | ||
request.setUserIdentities(userIdentities); | ||
Event.Context context = new Event.Context(request); | ||
event.setContext(context); | ||
Map<String, String> attributes = new HashMap<>(); | ||
// Added some random spaces to test it doesn't mess with parsing | ||
attributes.put(IterableExtension.EMAIL_LIST_ID_LIST_KEY, "1, 2, 3, 4 , 5 , 6 , 7 ,8"); | ||
attributes.put(IterableExtension.UNSUBSCRIBE_CHANNEL_ID_LIST_KEY, " 1, 3, 5 ,7 "); | ||
attributes.put(IterableExtension.UNSUBSCRIBE_MESSAGE_TYPE_ID_LIST_KEY, " 1, 3, 5 ,7 ,10"); | ||
attributes.put(IterableExtension.CAMPAIGN_ID_KEY, "2323"); | ||
attributes.put(IterableExtension.TEMPLATE_ID_KEY, " 5555 "); | ||
event.setAttributes(attributes); | ||
List<Integer> expectedEmailListIdList = Arrays.asList(1,2,3,4,5,6,7,8); | ||
List<Integer> expectedChannelIdList = Arrays.asList(1,3,5,7); | ||
List<Integer> expectedMessageTypeIdList = Arrays.asList(1,3,5,7,10); | ||
int expectedCampaignId = 2323; | ||
int expectedTemplateId = 5555; | ||
|
||
extension.processCustomEvent(event); | ||
|
||
ArgumentCaptor<UpdateSubscriptionsRequest> argument = ArgumentCaptor.forClass(UpdateSubscriptionsRequest.class); | ||
ArgumentCaptor<String> stringArgumentCaptor = ArgumentCaptor.forClass(String.class); | ||
Mockito.verify(extension.iterableService).updateSubscriptions(stringArgumentCaptor.capture(), argument.capture()); | ||
assertEquals("foo api key 2", stringArgumentCaptor.getValue()); | ||
assertEquals("[email protected]", argument.getValue().email); | ||
assertEquals(expectedEmailListIdList, argument.getValue().emailListIds); | ||
assertEquals(expectedChannelIdList, argument.getValue().unsubscribedChannelIds); | ||
assertEquals(expectedMessageTypeIdList, argument.getValue().unsubscribedMessageTypeIds); | ||
assertEquals(expectedCampaignId, (int)argument.getValue().campaignId); | ||
assertEquals(expectedTemplateId, (int)argument.getValue().templateId); | ||
|
||
apiResponse.code = "anything but success"; | ||
|
||
IOException exception = null; | ||
try { | ||
extension.processCustomEvent(event); | ||
} catch (IOException ioe) { | ||
exception = ioe; | ||
} | ||
assertNotNull("Iterable extension should have thrown an IOException", exception); | ||
} | ||
} |
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
12 changes: 12 additions & 0 deletions
12
iterable-java-sdk/src/main/java/com/mparticle/iterable/UpdateSubscriptionsRequest.java
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,12 @@ | ||
package com.mparticle.iterable; | ||
|
||
import java.util.List; | ||
|
||
public class UpdateSubscriptionsRequest { | ||
public String email; | ||
public List<Integer> emailListIds; | ||
public List<Integer> unsubscribedChannelIds; | ||
public List<Integer> unsubscribedMessageTypeIds; | ||
public Integer campaignId; | ||
public Integer templateId; | ||
} |
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