Skip to content

Commit

Permalink
updates unit tests for user id criteria not met
Browse files Browse the repository at this point in the history
  • Loading branch information
Evan Greer committed Nov 9, 2024
1 parent 65ca7df commit 4e5c6b0
Showing 1 changed file with 73 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -231,69 +231,127 @@ public void testCriteriaNotMetUserIdReplayTrueMergeFalse() throws Exception {
// clear any pending requests
while (server.takeRequest(1, TimeUnit.SECONDS) != null) { }

// mock anon session response and track purchase response
addResponse(IterableConstants.ENDPOINT_TRACK_ANON_SESSION);
addResponse(IterableConstants.ENDPOINT_TRACK_PURCHASE);

// trigger track purchase event
triggerTrackPurchaseEvent("test", "keyboard", 5, 1);

shadowOf(getMainLooper()).idle();
assertNotEquals("", getEventData());

// check that request was not sent to anon session endpoint
RecordedRequest anonSessionRequest = server.takeRequest(1, TimeUnit.SECONDS);
assertNull("There should not be an anon session request", anonSessionRequest);

// check that request was not sent to track purchase endpoint
RecordedRequest purchaseRequest1 = server.takeRequest(1, TimeUnit.SECONDS);
assertNull("There should not be a purchase request", purchaseRequest1);

// clear any pending requests
while (server.takeRequest(1, TimeUnit.SECONDS) != null) { }
final String userId = "testUser2";

// mock merge response
addResponse(IterableConstants.ENDPOINT_MERGE_USER);

// set email
final String userId = "testUser2";
IterableIdentityResolution identityResolution = new IterableIdentityResolution(true, false);
IterableApi.getInstance().setUserId(userId, identityResolution);

// check that request was sent to purchase endpoint on event replay
RecordedRequest purchaseRequest2 = server.takeRequest(1, TimeUnit.SECONDS);
assertNotNull(purchaseRequest2);
assertEquals(("/" + IterableConstants.ENDPOINT_TRACK_PURCHASE), purchaseRequest2.getPath());

// check that request was not sent to merge endpoint
RecordedRequest mergeRequest = server.takeRequest(1, TimeUnit.SECONDS);
assertNotNull(mergeRequest);
shadowOf(getMainLooper()).idle();
assertNotEquals(("/" + IterableConstants.ENDPOINT_MERGE_USER), mergeRequest.getPath());

// check that userId was set
assertEquals(userId, IterableApi.getInstance().getUserId());
assertEquals("", getEventData());
}

@Test
public void testCriteriaNotMetUserIdReplayFalseMergeFalse() throws Exception {
// clear any pending requests
while (server.takeRequest(1, TimeUnit.SECONDS) != null) { }

// mock anon session response and track purchase response
addResponse(IterableConstants.ENDPOINT_TRACK_ANON_SESSION);
addResponse(IterableConstants.ENDPOINT_TRACK_PURCHASE);

// trigger track purchase event
triggerTrackPurchaseEvent("test", "keyboard", 5, 1);
shadowOf(getMainLooper()).idle();
String eventData = getEventData();
assertNotEquals("", eventData);
final String userId = "testUser2";

// check that request was not sent to anon session endpoint
RecordedRequest anonSessionRequest = server.takeRequest(1, TimeUnit.SECONDS);
assertNull("There should not be an anon session request", anonSessionRequest);

// check that request was not sent to track purchase endpoint
RecordedRequest purchaseRequest1 = server.takeRequest(1, TimeUnit.SECONDS);
assertNull("There should not be a purchase request", purchaseRequest1);

// clear any pending requests
while (server.takeRequest(1, TimeUnit.SECONDS) != null) { }

// mock merge response
addResponse(IterableConstants.ENDPOINT_MERGE_USER);

// set email
final String userId = "testUser2";
IterableIdentityResolution identityResolution = new IterableIdentityResolution(false, false);
IterableApi.getInstance().setUserId(userId, identityResolution);

// check that request was not sent to merge endpoint
RecordedRequest mergeRequest = server.takeRequest(1, TimeUnit.SECONDS);
assertNotNull(mergeRequest);
shadowOf(getMainLooper()).idle();
assertNotEquals(("/" + IterableConstants.ENDPOINT_MERGE_USER), mergeRequest.getPath());

// check that userId was set
assertEquals(userId, IterableApi.getInstance().getUserId());
assertEquals("", getEventData());
}

@Test
public void testCriteriaNotMetUserIdReplayFalseMergeTrue() throws Exception {
// clear any pending requests
while (server.takeRequest(1, TimeUnit.SECONDS) != null) { }

// mock anon session response and track purchase response
addResponse(IterableConstants.ENDPOINT_TRACK_ANON_SESSION);
addResponse(IterableConstants.ENDPOINT_TRACK_PURCHASE);

// trigger track purchase event
triggerTrackPurchaseEvent("test", "keyboard", 5, 1);
shadowOf(getMainLooper()).idle();
String eventData = getEventData();
assertNotEquals("", eventData);

// check that request was not sent to anon session endpoint
RecordedRequest anonSessionRequest = server.takeRequest(1, TimeUnit.SECONDS);
assertNull("There should not be an anon session request", anonSessionRequest);

// check that request was not sent to track purchase endpoint
RecordedRequest purchaseRequest1 = server.takeRequest(1, TimeUnit.SECONDS);
assertNull("There should not be a purchase request", purchaseRequest1);

// clear any pending requests
while (server.takeRequest(1, TimeUnit.SECONDS) != null) { }
final String userId = "testUser2";

// mock merge response
addResponse(IterableConstants.ENDPOINT_MERGE_USER);

// set email
final String userId = "testUser2";
IterableIdentityResolution identityResolution = new IterableIdentityResolution(false, true);
IterableApi.getInstance().setUserId(userId, identityResolution);

// check that request was not sent to merge endpoint
RecordedRequest mergeRequest = server.takeRequest(1, TimeUnit.SECONDS);
assertNotNull(mergeRequest);
shadowOf(getMainLooper()).idle();
assertNotEquals(("/" + IterableConstants.ENDPOINT_MERGE_USER), mergeRequest.getPath());

// check that userId was set
assertEquals(userId, IterableApi.getInstance().getUserId());
assertEquals("", getEventData());
}

@Test
Expand Down

0 comments on commit 4e5c6b0

Please sign in to comment.