Skip to content

Commit 60d30dc

Browse files
author
Evan Greer
committed
adds unit test
1 parent 7aabcb2 commit 60d30dc

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

iterableapi/src/test/java/com/iterable/iterableapi/IterableApiMergeUserEmailTests.java

+31
Original file line numberDiff line numberDiff line change
@@ -945,4 +945,35 @@ public void testIdentifiedEmailMergeTrue() throws Exception {
945945
// check that email was set
946946
assertEquals(email2, IterableApi.getInstance().getEmail());
947947
}
948+
949+
@Test
950+
public void testCriteriaMetTwice() throws Exception {
951+
// clear any pending requests
952+
while (server.takeRequest(1, TimeUnit.SECONDS) != null) { }
953+
954+
// mock anon session response and track purchase response
955+
addResponse(IterableConstants.ENDPOINT_TRACK_ANON_SESSION);
956+
addResponse(IterableConstants.ENDPOINT_TRACK_PURCHASE);
957+
addResponse(IterableConstants.ENDPOINT_TRACK_PURCHASE);
958+
959+
// trigger track purchase event
960+
triggerTrackPurchaseEvent("test", "keyboard", 4.67, 3);
961+
triggerTrackPurchaseEvent("test", "keyboard", 4.67, 3);
962+
shadowOf(getMainLooper()).idle();
963+
964+
// check if only one request was sent to anon session endpoint
965+
RecordedRequest anonSessionRequest = server.takeRequest(1, TimeUnit.SECONDS);
966+
assertNotNull("Anon session request should not be null", anonSessionRequest);
967+
assertEquals("/" + IterableConstants.ENDPOINT_TRACK_ANON_SESSION, anonSessionRequest.getPath());
968+
969+
// check if first request was sent to track purchase endpoint
970+
RecordedRequest firstPurchaseRequest = server.takeRequest(1, TimeUnit.SECONDS);
971+
assertNotNull("Purchase request should not be null", firstPurchaseRequest);
972+
assertEquals("/" + IterableConstants.ENDPOINT_TRACK_PURCHASE, firstPurchaseRequest .getPath());
973+
974+
// check if second request was sent to track purchase endpoint
975+
RecordedRequest secondPurchaseRequest = server.takeRequest(1, TimeUnit.SECONDS);
976+
assertNotNull("Purchase request should not be null", secondPurchaseRequest);
977+
assertEquals("/" + IterableConstants.ENDPOINT_TRACK_PURCHASE, secondPurchaseRequest.getPath());
978+
}
948979
}

0 commit comments

Comments
 (0)