From 5f560983e94dafcb453249b465ef325ced23b336 Mon Sep 17 00:00:00 2001 From: Evan Greer Date: Thu, 7 Nov 2024 20:29:16 -0700 Subject: [PATCH 01/12] updates testCriteriaMetEmailDefault --- .../IterableApiMergeUserEmailTests.java | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/iterableapi/src/test/java/com/iterable/iterableapi/IterableApiMergeUserEmailTests.java b/iterableapi/src/test/java/com/iterable/iterableapi/IterableApiMergeUserEmailTests.java index 876be55f3..e32105423 100644 --- a/iterableapi/src/test/java/com/iterable/iterableapi/IterableApiMergeUserEmailTests.java +++ b/iterableapi/src/test/java/com/iterable/iterableapi/IterableApiMergeUserEmailTests.java @@ -512,17 +512,27 @@ public void testCriteriaNotMetEmailReplayFalseMergeTrue() throws Exception { @Test public void testCriteriaMetEmailDefault() throws Exception { while (server.takeRequest(1, TimeUnit.SECONDS) != null) { } + addResponse(IterableConstants.ENDPOINT_TRACK_ANON_SESSION); + addResponse(IterableConstants.ENDPOINT_TRACK_PURCHASE); addResponse(IterableConstants.ENDPOINT_MERGE_USER); + triggerTrackPurchaseEvent("test", "keyboard", 4.67, 3); shadowOf(getMainLooper()).idle(); - assertEquals("", getEventData()); - while (server.takeRequest(1, TimeUnit.SECONDS) != null) { } + + RecordedRequest anonSessionRequest = server.takeRequest(1, TimeUnit.SECONDS); + assertNotNull("Anon session request should not be null", anonSessionRequest); + assertEquals("/" + IterableConstants.ENDPOINT_TRACK_ANON_SESSION, anonSessionRequest.getPath()); + + RecordedRequest purchaseRequest = server.takeRequest(1, TimeUnit.SECONDS); + assertNotNull("Purchase request should not be null", purchaseRequest); + assertEquals("/" + IterableConstants.ENDPOINT_TRACK_PURCHASE, purchaseRequest.getPath()); + final String email = "testUser2@gmail.com"; IterableApi.getInstance().setEmail(email); + RecordedRequest mergeRequest = server.takeRequest(1, TimeUnit.SECONDS); assertNotNull(mergeRequest); - shadowOf(getMainLooper()).idle(); assertEquals("/" + IterableConstants.ENDPOINT_MERGE_USER, mergeRequest.getPath()); assertEquals(email, IterableApi.getInstance().getEmail()); } From 29939800b99722e1c87655d1209838925c5a5c1e Mon Sep 17 00:00:00 2001 From: Evan Greer Date: Fri, 8 Nov 2024 15:02:14 -0700 Subject: [PATCH 02/12] updates unit test --- .../iterable/iterableapi/IterableApiMergeUserEmailTests.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/iterableapi/src/test/java/com/iterable/iterableapi/IterableApiMergeUserEmailTests.java b/iterableapi/src/test/java/com/iterable/iterableapi/IterableApiMergeUserEmailTests.java index e32105423..8071b8542 100644 --- a/iterableapi/src/test/java/com/iterable/iterableapi/IterableApiMergeUserEmailTests.java +++ b/iterableapi/src/test/java/com/iterable/iterableapi/IterableApiMergeUserEmailTests.java @@ -515,7 +515,6 @@ public void testCriteriaMetEmailDefault() throws Exception { addResponse(IterableConstants.ENDPOINT_TRACK_ANON_SESSION); addResponse(IterableConstants.ENDPOINT_TRACK_PURCHASE); - addResponse(IterableConstants.ENDPOINT_MERGE_USER); triggerTrackPurchaseEvent("test", "keyboard", 4.67, 3); shadowOf(getMainLooper()).idle(); @@ -528,6 +527,10 @@ public void testCriteriaMetEmailDefault() throws Exception { assertNotNull("Purchase request should not be null", purchaseRequest); assertEquals("/" + IterableConstants.ENDPOINT_TRACK_PURCHASE, purchaseRequest.getPath()); + while (server.takeRequest(1, TimeUnit.SECONDS) != null) { } + + addResponse(IterableConstants.ENDPOINT_MERGE_USER); + final String email = "testUser2@gmail.com"; IterableApi.getInstance().setEmail(email); From e4b965790de1823536efda82cbee96283dda6b6b Mon Sep 17 00:00:00 2001 From: Evan Greer Date: Fri, 8 Nov 2024 15:45:26 -0700 Subject: [PATCH 03/12] updates testCriteriaNotMetUserIdDefault --- .../IterableApiMergeUserEmailTests.java | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/iterableapi/src/test/java/com/iterable/iterableapi/IterableApiMergeUserEmailTests.java b/iterableapi/src/test/java/com/iterable/iterableapi/IterableApiMergeUserEmailTests.java index 8071b8542..1a2fc50c1 100644 --- a/iterableapi/src/test/java/com/iterable/iterableapi/IterableApiMergeUserEmailTests.java +++ b/iterableapi/src/test/java/com/iterable/iterableapi/IterableApiMergeUserEmailTests.java @@ -182,21 +182,40 @@ private void addResponse(String endPoint) { // all userId tests @Test public void testCriteriaNotMetUserIdDefault() throws Exception { + // clear any pending requests while (server.takeRequest(1, TimeUnit.SECONDS) != null) { } + addResponse(IterableConstants.ENDPOINT_TRACK_ANON_SESSION); + addResponse(IterableConstants.ENDPOINT_TRACK_PURCHASE); + 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); + assertNotNull("Anon session request should not be null", anonSessionRequest); + assertNotEquals("/" + IterableConstants.ENDPOINT_TRACK_ANON_SESSION, anonSessionRequest.getPath()); + + // check that request was not sent to track purchase endpoint + RecordedRequest purchaseRequest = server.takeRequest(1, TimeUnit.SECONDS); + assertNotNull("Purchase request should not be null", purchaseRequest); + assertNotEquals("/" + IterableConstants.ENDPOINT_TRACK_PURCHASE, purchaseRequest.getPath()); + while (server.takeRequest(1, TimeUnit.SECONDS) != null) { } + + // mock merge response + addResponse(IterableConstants.ENDPOINT_MERGE_USER); + final String userId = "testUser2"; IterableApi.getInstance().setUserId(userId); + RecordedRequest mergeRequest = server.takeRequest(1, TimeUnit.SECONDS); assertNotNull(mergeRequest); - shadowOf(getMainLooper()).idle(); assertNotEquals(("/" + IterableConstants.ENDPOINT_MERGE_USER), mergeRequest.getPath()); assertEquals(userId, IterableApi.getInstance().getUserId()); - assertEquals("", getEventData()); } @Test @@ -511,29 +530,38 @@ public void testCriteriaNotMetEmailReplayFalseMergeTrue() throws Exception { @Test public void testCriteriaMetEmailDefault() 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", 4.67, 3); shadowOf(getMainLooper()).idle(); + // check if request was sent to anon session endpoint RecordedRequest anonSessionRequest = server.takeRequest(1, TimeUnit.SECONDS); assertNotNull("Anon session request should not be null", anonSessionRequest); assertEquals("/" + IterableConstants.ENDPOINT_TRACK_ANON_SESSION, anonSessionRequest.getPath()); + // check if request was sent to track purchase endpoint RecordedRequest purchaseRequest = server.takeRequest(1, TimeUnit.SECONDS); assertNotNull("Purchase request should not be null", purchaseRequest); assertEquals("/" + IterableConstants.ENDPOINT_TRACK_PURCHASE, purchaseRequest.getPath()); + // clear any pending requests while (server.takeRequest(1, TimeUnit.SECONDS) != null) { } + // mock merge response addResponse(IterableConstants.ENDPOINT_MERGE_USER); + // set email to trigger merging final String email = "testUser2@gmail.com"; IterableApi.getInstance().setEmail(email); + // check if request was sent to merge endpoint RecordedRequest mergeRequest = server.takeRequest(1, TimeUnit.SECONDS); assertNotNull(mergeRequest); assertEquals("/" + IterableConstants.ENDPOINT_MERGE_USER, mergeRequest.getPath()); From 661441306f69ce1d3f87df7fa9201986de06671a Mon Sep 17 00:00:00 2001 From: Evan Greer Date: Fri, 8 Nov 2024 15:55:10 -0700 Subject: [PATCH 04/12] updates unit test --- .../iterableapi/IterableApiMergeUserEmailTests.java | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/iterableapi/src/test/java/com/iterable/iterableapi/IterableApiMergeUserEmailTests.java b/iterableapi/src/test/java/com/iterable/iterableapi/IterableApiMergeUserEmailTests.java index 1a2fc50c1..7d1159458 100644 --- a/iterableapi/src/test/java/com/iterable/iterableapi/IterableApiMergeUserEmailTests.java +++ b/iterableapi/src/test/java/com/iterable/iterableapi/IterableApiMergeUserEmailTests.java @@ -4,6 +4,7 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import static org.robolectric.Shadows.shadowOf; import android.content.Context; @@ -196,13 +197,11 @@ public void testCriteriaNotMetUserIdDefault() throws Exception { // check that request was not sent to anon session endpoint RecordedRequest anonSessionRequest = server.takeRequest(1, TimeUnit.SECONDS); - assertNotNull("Anon session request should not be null", anonSessionRequest); - assertNotEquals("/" + IterableConstants.ENDPOINT_TRACK_ANON_SESSION, anonSessionRequest.getPath()); + assertNull("There should not be an anon session request", anonSessionRequest); // check that request was not sent to track purchase endpoint RecordedRequest purchaseRequest = server.takeRequest(1, TimeUnit.SECONDS); - assertNotNull("Purchase request should not be null", purchaseRequest); - assertNotEquals("/" + IterableConstants.ENDPOINT_TRACK_PURCHASE, purchaseRequest.getPath()); + assertNull("There should not be a purchase request", purchaseRequest); while (server.takeRequest(1, TimeUnit.SECONDS) != null) { } @@ -213,8 +212,8 @@ public void testCriteriaNotMetUserIdDefault() throws Exception { IterableApi.getInstance().setUserId(userId); RecordedRequest mergeRequest = server.takeRequest(1, TimeUnit.SECONDS); - assertNotNull(mergeRequest); - assertNotEquals(("/" + IterableConstants.ENDPOINT_MERGE_USER), mergeRequest.getPath()); + assertNull("There should not be a merge request", mergeRequest); + assertEquals(userId, IterableApi.getInstance().getUserId()); } From fff257581d6fc6f697a2c7507eba636b9f96a2cb Mon Sep 17 00:00:00 2001 From: Evan Greer Date: Fri, 8 Nov 2024 16:03:58 -0700 Subject: [PATCH 05/12] updates unit test --- .../iterableapi/IterableApiMergeUserEmailTests.java | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/iterableapi/src/test/java/com/iterable/iterableapi/IterableApiMergeUserEmailTests.java b/iterableapi/src/test/java/com/iterable/iterableapi/IterableApiMergeUserEmailTests.java index 7d1159458..4057b1455 100644 --- a/iterableapi/src/test/java/com/iterable/iterableapi/IterableApiMergeUserEmailTests.java +++ b/iterableapi/src/test/java/com/iterable/iterableapi/IterableApiMergeUserEmailTests.java @@ -186,15 +186,14 @@ public void testCriteriaNotMetUserIdDefault() 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); @@ -203,17 +202,22 @@ public void testCriteriaNotMetUserIdDefault() throws Exception { RecordedRequest purchaseRequest = server.takeRequest(1, TimeUnit.SECONDS); assertNull("There should not be a purchase request", purchaseRequest); + // 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"; IterableApi.getInstance().setUserId(userId); + // check that request was not sent to merge endpoint RecordedRequest mergeRequest = server.takeRequest(1, TimeUnit.SECONDS); - assertNull("There should not be a merge request", mergeRequest); + assertNotNull(mergeRequest); + assertNotEquals(("/" + IterableConstants.ENDPOINT_MERGE_USER), mergeRequest.getPath()); + // check that userId was set assertEquals(userId, IterableApi.getInstance().getUserId()); } From 2e73a6b817fad353f3d316e70cb32cbbc57351c6 Mon Sep 17 00:00:00 2001 From: Evan Greer Date: Fri, 8 Nov 2024 16:14:17 -0700 Subject: [PATCH 06/12] updates unit test --- .../IterableApiMergeUserEmailTests.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/iterableapi/src/test/java/com/iterable/iterableapi/IterableApiMergeUserEmailTests.java b/iterableapi/src/test/java/com/iterable/iterableapi/IterableApiMergeUserEmailTests.java index 4057b1455..a41facb8e 100644 --- a/iterableapi/src/test/java/com/iterable/iterableapi/IterableApiMergeUserEmailTests.java +++ b/iterableapi/src/test/java/com/iterable/iterableapi/IterableApiMergeUserEmailTests.java @@ -199,8 +199,8 @@ public void testCriteriaNotMetUserIdDefault() throws Exception { assertNull("There should not be an anon session request", anonSessionRequest); // check that request was not sent to track purchase endpoint - RecordedRequest purchaseRequest = server.takeRequest(1, TimeUnit.SECONDS); - assertNull("There should not be a purchase request", purchaseRequest); + 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) { } @@ -212,10 +212,14 @@ public void testCriteriaNotMetUserIdDefault() throws Exception { final String userId = "testUser2"; IterableApi.getInstance().setUserId(userId); + // 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); - assertNotEquals(("/" + IterableConstants.ENDPOINT_MERGE_USER), mergeRequest.getPath()); + assertNull(mergeRequest); // check that userId was set assertEquals(userId, IterableApi.getInstance().getUserId()); @@ -223,9 +227,14 @@ public void testCriteriaNotMetUserIdDefault() throws Exception { @Test public void testCriteriaNotMetUserIdReplayTrueMergeFalse() throws Exception { + // clear any pending requests while (server.takeRequest(1, TimeUnit.SECONDS) != null) { } + addResponse(IterableConstants.ENDPOINT_TRACK_ANON_SESSION); + addResponse(IterableConstants.ENDPOINT_TRACK_PURCHASE); + triggerTrackPurchaseEvent("test", "keyboard", 5, 1); + shadowOf(getMainLooper()).idle(); assertNotEquals("", getEventData()); while (server.takeRequest(1, TimeUnit.SECONDS) != null) { } From 3698ba32deab379dfe4457e0fd626f9962de7fb8 Mon Sep 17 00:00:00 2001 From: Evan Greer Date: Fri, 8 Nov 2024 16:26:03 -0700 Subject: [PATCH 07/12] updates unit test --- .../iterable/iterableapi/IterableApiMergeUserEmailTests.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/iterableapi/src/test/java/com/iterable/iterableapi/IterableApiMergeUserEmailTests.java b/iterableapi/src/test/java/com/iterable/iterableapi/IterableApiMergeUserEmailTests.java index a41facb8e..b0e9e1c4c 100644 --- a/iterableapi/src/test/java/com/iterable/iterableapi/IterableApiMergeUserEmailTests.java +++ b/iterableapi/src/test/java/com/iterable/iterableapi/IterableApiMergeUserEmailTests.java @@ -219,7 +219,8 @@ public void testCriteriaNotMetUserIdDefault() throws Exception { // check that request was not sent to merge endpoint RecordedRequest mergeRequest = server.takeRequest(1, TimeUnit.SECONDS); - assertNull(mergeRequest); + assertNotNull(mergeRequest); + assertNotEquals(("/" + IterableConstants.ENDPOINT_TRACK_PURCHASE), purchaseRequest2.getPath()); // check that userId was set assertEquals(userId, IterableApi.getInstance().getUserId()); From 65ca7dff2356e313acb643433d2c357b8f50f6dc Mon Sep 17 00:00:00 2001 From: Evan Greer Date: Fri, 8 Nov 2024 16:27:18 -0700 Subject: [PATCH 08/12] updates unit test --- .../iterable/iterableapi/IterableApiMergeUserEmailTests.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/iterableapi/src/test/java/com/iterable/iterableapi/IterableApiMergeUserEmailTests.java b/iterableapi/src/test/java/com/iterable/iterableapi/IterableApiMergeUserEmailTests.java index b0e9e1c4c..6bf0fb12a 100644 --- a/iterableapi/src/test/java/com/iterable/iterableapi/IterableApiMergeUserEmailTests.java +++ b/iterableapi/src/test/java/com/iterable/iterableapi/IterableApiMergeUserEmailTests.java @@ -220,7 +220,7 @@ public void testCriteriaNotMetUserIdDefault() throws Exception { // check that request was not sent to merge endpoint RecordedRequest mergeRequest = server.takeRequest(1, TimeUnit.SECONDS); assertNotNull(mergeRequest); - assertNotEquals(("/" + IterableConstants.ENDPOINT_TRACK_PURCHASE), purchaseRequest2.getPath()); + assertNotEquals(("/" + IterableConstants.ENDPOINT_MERGE_USER), mergeRequest.getPath()); // check that userId was set assertEquals(userId, IterableApi.getInstance().getUserId()); From 4e5c6b0e4151744d34fc22e148f8660c253761a3 Mon Sep 17 00:00:00 2001 From: Evan Greer Date: Fri, 8 Nov 2024 17:34:01 -0700 Subject: [PATCH 09/12] updates unit tests for user id criteria not met --- .../IterableApiMergeUserEmailTests.java | 88 +++++++++++++++---- 1 file changed, 73 insertions(+), 15 deletions(-) diff --git a/iterableapi/src/test/java/com/iterable/iterableapi/IterableApiMergeUserEmailTests.java b/iterableapi/src/test/java/com/iterable/iterableapi/IterableApiMergeUserEmailTests.java index 6bf0fb12a..27ba5dd0e 100644 --- a/iterableapi/src/test/java/com/iterable/iterableapi/IterableApiMergeUserEmailTests.java +++ b/iterableapi/src/test/java/com/iterable/iterableapi/IterableApiMergeUserEmailTests.java @@ -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 From c3ed8bb8a2a88af069fd39af93e88d65fb8c8245 Mon Sep 17 00:00:00 2001 From: Evan Greer Date: Fri, 8 Nov 2024 17:59:09 -0700 Subject: [PATCH 10/12] updates unit tests for user id paths --- .../IterableApiMergeUserEmailTests.java | 142 ++++++++++++++---- 1 file changed, 115 insertions(+), 27 deletions(-) diff --git a/iterableapi/src/test/java/com/iterable/iterableapi/IterableApiMergeUserEmailTests.java b/iterableapi/src/test/java/com/iterable/iterableapi/IterableApiMergeUserEmailTests.java index 27ba5dd0e..b92af8ba6 100644 --- a/iterableapi/src/test/java/com/iterable/iterableapi/IterableApiMergeUserEmailTests.java +++ b/iterableapi/src/test/java/com/iterable/iterableapi/IterableApiMergeUserEmailTests.java @@ -208,7 +208,7 @@ public void testCriteriaNotMetUserIdDefault() throws Exception { // mock merge response addResponse(IterableConstants.ENDPOINT_MERGE_USER); - // set email + // set user id final String userId = "testUser2"; IterableApi.getInstance().setUserId(userId); @@ -222,7 +222,7 @@ public void testCriteriaNotMetUserIdDefault() throws Exception { assertNotNull(mergeRequest); assertNotEquals(("/" + IterableConstants.ENDPOINT_MERGE_USER), mergeRequest.getPath()); - // check that userId was set + // check that user id was set assertEquals(userId, IterableApi.getInstance().getUserId()); } @@ -253,7 +253,7 @@ public void testCriteriaNotMetUserIdReplayTrueMergeFalse() throws Exception { // mock merge response addResponse(IterableConstants.ENDPOINT_MERGE_USER); - // set email + // set user id final String userId = "testUser2"; IterableIdentityResolution identityResolution = new IterableIdentityResolution(true, false); IterableApi.getInstance().setUserId(userId, identityResolution); @@ -268,7 +268,7 @@ public void testCriteriaNotMetUserIdReplayTrueMergeFalse() throws Exception { assertNotNull(mergeRequest); assertNotEquals(("/" + IterableConstants.ENDPOINT_MERGE_USER), mergeRequest.getPath()); - // check that userId was set + // check that user id was set assertEquals(userId, IterableApi.getInstance().getUserId()); } @@ -299,7 +299,7 @@ public void testCriteriaNotMetUserIdReplayFalseMergeFalse() throws Exception { // mock merge response addResponse(IterableConstants.ENDPOINT_MERGE_USER); - // set email + // set user id final String userId = "testUser2"; IterableIdentityResolution identityResolution = new IterableIdentityResolution(false, false); IterableApi.getInstance().setUserId(userId, identityResolution); @@ -309,7 +309,7 @@ public void testCriteriaNotMetUserIdReplayFalseMergeFalse() throws Exception { assertNotNull(mergeRequest); assertNotEquals(("/" + IterableConstants.ENDPOINT_MERGE_USER), mergeRequest.getPath()); - // check that userId was set + // check that user id was set assertEquals(userId, IterableApi.getInstance().getUserId()); } @@ -340,7 +340,7 @@ public void testCriteriaNotMetUserIdReplayFalseMergeTrue() throws Exception { // mock merge response addResponse(IterableConstants.ENDPOINT_MERGE_USER); - // set email + // set user id final String userId = "testUser2"; IterableIdentityResolution identityResolution = new IterableIdentityResolution(false, true); IterableApi.getInstance().setUserId(userId, identityResolution); @@ -350,105 +350,185 @@ public void testCriteriaNotMetUserIdReplayFalseMergeTrue() throws Exception { assertNotNull(mergeRequest); assertNotEquals(("/" + IterableConstants.ENDPOINT_MERGE_USER), mergeRequest.getPath()); - // check that userId was set + // check that user id was set assertEquals(userId, IterableApi.getInstance().getUserId()); } @Test public void testCriteriaMetUserIdDefault() 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_MERGE_USER); + addResponse(IterableConstants.ENDPOINT_TRACK_PURCHASE); + + // trigger track purchase event triggerTrackPurchaseEvent("test", "keyboard", 4.67, 3); shadowOf(getMainLooper()).idle(); - assertEquals("", getEventData()); + + // check if request was sent to anon session endpoint + RecordedRequest anonSessionRequest = server.takeRequest(1, TimeUnit.SECONDS); + assertNotNull("Anon session request should not be null", anonSessionRequest); + assertEquals("/" + IterableConstants.ENDPOINT_TRACK_ANON_SESSION, anonSessionRequest.getPath()); + + // check if request was sent to track purchase endpoint + RecordedRequest purchaseRequest = server.takeRequest(1, TimeUnit.SECONDS); + assertNotNull("Purchase request should not be null", purchaseRequest); + assertEquals("/" + IterableConstants.ENDPOINT_TRACK_PURCHASE, purchaseRequest.getPath()); + + // clear any pending requests while (server.takeRequest(1, TimeUnit.SECONDS) != null) { } + + // mock merge response + addResponse(IterableConstants.ENDPOINT_MERGE_USER); + + // set user id final String userId = "testUser2"; IterableApi.getInstance().setUserId(userId); + + // check that request was sent to merge endpoint RecordedRequest mergeRequest = server.takeRequest(1, TimeUnit.SECONDS); assertNotNull(mergeRequest); - shadowOf(getMainLooper()).idle(); assertEquals("/" + IterableConstants.ENDPOINT_MERGE_USER, mergeRequest.getPath()); + + // check that user id was set assertEquals(userId, IterableApi.getInstance().getUserId()); } @Test public void testCriteriaMetUserIdMergeFalse() 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_MERGE_USER); + addResponse(IterableConstants.ENDPOINT_TRACK_PURCHASE); + + // trigger track purchase event triggerTrackPurchaseEvent("test", "keyboard", 4.67, 3); shadowOf(getMainLooper()).idle(); - String eventData = getEventData(); - assertEquals("", eventData); + + // check if request was sent to anon session endpoint + RecordedRequest anonSessionRequest = server.takeRequest(1, TimeUnit.SECONDS); + assertNotNull("Anon session request should not be null", anonSessionRequest); + assertEquals("/" + IterableConstants.ENDPOINT_TRACK_ANON_SESSION, anonSessionRequest.getPath()); + + // check if request was sent to track purchase endpoint + RecordedRequest purchaseRequest = server.takeRequest(1, TimeUnit.SECONDS); + assertNotNull("Purchase request should not be null", purchaseRequest); + assertEquals("/" + IterableConstants.ENDPOINT_TRACK_PURCHASE, purchaseRequest.getPath()); + + // clear any pending requests while (server.takeRequest(1, TimeUnit.SECONDS) != null) { } - final String userId = "testUser2"; + // set user id + final String userId = "testUser2"; IterableIdentityResolution identityResolution = new IterableIdentityResolution(true, 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 user id was set assertEquals(userId, IterableApi.getInstance().getUserId()); } @Test public void testCriteriaMetUserIdMergeTrue() 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_MERGE_USER); + addResponse(IterableConstants.ENDPOINT_TRACK_PURCHASE); + + // trigger track purchase event triggerTrackPurchaseEvent("test", "keyboard", 4.67, 3); shadowOf(getMainLooper()).idle(); - String eventData = getEventData(); - assertEquals("", eventData); + + // check if request was sent to anon session endpoint + RecordedRequest anonSessionRequest = server.takeRequest(1, TimeUnit.SECONDS); + assertNotNull("Anon session request should not be null", anonSessionRequest); + assertEquals("/" + IterableConstants.ENDPOINT_TRACK_ANON_SESSION, anonSessionRequest.getPath()); + + // check if request was sent to track purchase endpoint + RecordedRequest purchaseRequest = server.takeRequest(1, TimeUnit.SECONDS); + assertNotNull("Purchase request should not be null", purchaseRequest); + assertEquals("/" + IterableConstants.ENDPOINT_TRACK_PURCHASE, purchaseRequest.getPath()); + + // clear any pending requests while (server.takeRequest(1, TimeUnit.SECONDS) != null) { } - final String userId = "testUser2"; + // set user id + final String userId = "testUser2"; IterableIdentityResolution identityResolution = new IterableIdentityResolution(false, true); IterableApi.getInstance().setUserId(userId, identityResolution); + // check that request was sent to merge endpoint RecordedRequest mergeRequest = server.takeRequest(1, TimeUnit.SECONDS); assertNotNull(mergeRequest); - shadowOf(getMainLooper()).idle(); assertEquals("/" + IterableConstants.ENDPOINT_MERGE_USER, mergeRequest.getPath()); + + // check that user id was set assertEquals(userId, IterableApi.getInstance().getUserId()); } @Test public void testIdentifiedUserIdDefault() throws Exception { + addResponse(IterableConstants.ENDPOINT_MERGE_USER); + + // set user id final String userId1 = "testUser1"; IterableApi.getInstance().setUserId(userId1); - shadowOf(getMainLooper()).idle(); + + // check that user id was set assertEquals(userId1, IterableApi.getInstance().getUserId()); + + // clear any pending requests while (server.takeRequest(1, TimeUnit.SECONDS) != null) { } + + // set different user id final String userId2 = "testUser2"; IterableApi.getInstance().setUserId(userId2); + + // 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 user id was set assertEquals(userId2, IterableApi.getInstance().getUserId()); } @Test public void testIdentifiedUserIdMergeFalse() throws Exception { + addResponse(IterableConstants.ENDPOINT_MERGE_USER); + // set user id final String userId1 = "testUser1"; IterableIdentityResolution identityResolution = new IterableIdentityResolution(true, false); IterableApi.getInstance().setUserId(userId1, identityResolution); - shadowOf(getMainLooper()).idle(); + + // check that user id was set assertEquals(userId1, IterableApi.getInstance().getUserId()); + + // clear any pending requests while (server.takeRequest(1, TimeUnit.SECONDS) != null) { } + // set different user id final String userId2 = "testUser2"; IterableIdentityResolution identityResolution2 = new IterableIdentityResolution(true, false); IterableApi.getInstance().setUserId(userId2, identityResolution2); + + // 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 user id was set assertEquals(userId2, IterableApi.getInstance().getUserId()); } @@ -456,20 +536,28 @@ public void testIdentifiedUserIdMergeFalse() throws Exception { public void testIdentifiedUserIdMergeTrue() throws Exception { addResponse(IterableConstants.ENDPOINT_MERGE_USER); + // set user id final String userId1 = "testUser1"; IterableIdentityResolution identityResolution = new IterableIdentityResolution(true, false); IterableApi.getInstance().setUserId(userId1, identityResolution); - shadowOf(getMainLooper()).idle(); + + // check that user id was set assertEquals(userId1, IterableApi.getInstance().getUserId()); + + // clear any pending requests while (server.takeRequest(1, TimeUnit.SECONDS) != null) { } + // set different user id final String userId2 = "testUser2"; IterableIdentityResolution identityResolution2 = new IterableIdentityResolution(true, true); IterableApi.getInstance().setUserId(userId2, identityResolution2); + + // 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 user id was set assertEquals(userId2, IterableApi.getInstance().getUserId()); } From eab14b1db69d1dfd1c2b7dc1d3290170f3446b67 Mon Sep 17 00:00:00 2001 From: Evan Greer Date: Fri, 8 Nov 2024 18:45:14 -0700 Subject: [PATCH 11/12] updates remaining email unit tests --- .../IterableApiMergeUserEmailTests.java | 275 +++++++++++++----- 1 file changed, 202 insertions(+), 73 deletions(-) diff --git a/iterableapi/src/test/java/com/iterable/iterableapi/IterableApiMergeUserEmailTests.java b/iterableapi/src/test/java/com/iterable/iterableapi/IterableApiMergeUserEmailTests.java index b92af8ba6..76e6ca1a4 100644 --- a/iterableapi/src/test/java/com/iterable/iterableapi/IterableApiMergeUserEmailTests.java +++ b/iterableapi/src/test/java/com/iterable/iterableapi/IterableApiMergeUserEmailTests.java @@ -563,128 +563,176 @@ public void testIdentifiedUserIdMergeTrue() throws Exception { // all email tests @Test - public void testCriteriaNotMetEmailMergeFalse() throws Exception { - while (server.takeRequest(1, TimeUnit.SECONDS) != null) { } - addResponse(IterableConstants.ENDPOINT_TRACK_ANON_SESSION); - triggerTrackPurchaseEvent("test", "keyboard", 5, 1); - shadowOf(getMainLooper()).idle(); - String eventData = getEventData(); - assertNotEquals("", eventData); + public void testCriteriaNotMetEmailDefault() throws Exception { + // clear any pending requests while (server.takeRequest(1, TimeUnit.SECONDS) != null) { } - final String email = "testUser@gmail.com"; - IterableIdentityResolution identityResolution = new IterableIdentityResolution(false, false); - IterableApi.getInstance().setEmail(email, identityResolution); - RecordedRequest mergeRequest = server.takeRequest(1, TimeUnit.SECONDS); - assertNotNull(mergeRequest); - shadowOf(getMainLooper()).idle(); - assertNotEquals(("/" + IterableConstants.ENDPOINT_MERGE_USER), mergeRequest.getPath()); - assertEquals(email, IterableApi.getInstance().getEmail()); - assertEquals("", getEventData()); - } - @Test - public void testCriteriaNotMetEmailMergeTrue() throws Exception { - while (server.takeRequest(1, TimeUnit.SECONDS) != null) { } + // mock anon session response and track purchase response addResponse(IterableConstants.ENDPOINT_TRACK_ANON_SESSION); - triggerTrackPurchaseEvent("test", "keyboard", 5, 1); - shadowOf(getMainLooper()).idle(); - String eventData = getEventData(); - assertNotEquals("", eventData); - while (server.takeRequest(1, TimeUnit.SECONDS) != null) { } - final String email = "testUser@gmail.com"; - IterableApi.getInstance().setEmail(email); - RecordedRequest mergeRequest = server.takeRequest(1, TimeUnit.SECONDS); - assertNotNull(mergeRequest); - shadowOf(getMainLooper()).idle(); - assertNotEquals(("/" + IterableConstants.ENDPOINT_MERGE_USER), mergeRequest.getPath()); - assertEquals(email, IterableApi.getInstance().getEmail()); - assertEquals("", getEventData()); - } + addResponse(IterableConstants.ENDPOINT_TRACK_PURCHASE); - @Test - public void testCriteriaNotMetEmailDefault() throws Exception { - while (server.takeRequest(1, TimeUnit.SECONDS) != null) { } - addResponse(IterableConstants.ENDPOINT_TRACK_ANON_SESSION); + // 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) { } + + // mock merge response + addResponse(IterableConstants.ENDPOINT_MERGE_USER); + + // set email final String email = "testUser2@gmail.com"; IterableApi.getInstance().setEmail(email); + + // 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 email was set assertEquals(email, IterableApi.getInstance().getEmail()); - assertEquals("", getEventData()); } @Test public void testCriteriaNotMetEmailReplayTrueMergeFalse() 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 email = "testUser@gmail.com"; + // mock merge response + addResponse(IterableConstants.ENDPOINT_MERGE_USER); + + // set email + final String email = "testUser@gmail.com"; IterableIdentityResolution identityResolution = new IterableIdentityResolution(true, false); IterableApi.getInstance().setEmail(email, 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 email was set assertEquals(email, IterableApi.getInstance().getEmail()); - assertEquals("", getEventData()); } @Test public void testCriteriaNotMetEmailReplayFalseMergeFalse() 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 email = "testUser@gmail.com"; + // mock merge response + addResponse(IterableConstants.ENDPOINT_MERGE_USER); + + // set email + final String email = "testUser@gmail.com"; IterableIdentityResolution identityResolution = new IterableIdentityResolution(false, false); IterableApi.getInstance().setEmail(email, 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 email was set assertEquals(email, IterableApi.getInstance().getEmail()); - assertEquals("", getEventData()); } @Test public void testCriteriaNotMetEmailReplayFalseMergeTrue() 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 email = "testUser@gmail.com"; + // mock merge response + addResponse(IterableConstants.ENDPOINT_MERGE_USER); + + // set email + final String email = "testUser@gmail.com"; IterableIdentityResolution identityResolution = new IterableIdentityResolution(false, true); IterableApi.getInstance().setEmail(email, 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 email was set assertEquals(email, IterableApi.getInstance().getEmail()); - assertEquals("", getEventData()); } @Test @@ -724,76 +772,149 @@ public void testCriteriaMetEmailDefault() throws Exception { RecordedRequest mergeRequest = server.takeRequest(1, TimeUnit.SECONDS); assertNotNull(mergeRequest); assertEquals("/" + IterableConstants.ENDPOINT_MERGE_USER, mergeRequest.getPath()); + + // check that email was set assertEquals(email, IterableApi.getInstance().getEmail()); } @Test public void testCriteriaMetEmailMergeFalse() 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", 4.67, 3); shadowOf(getMainLooper()).idle(); - assertEquals("", getEventData()); + + // check if request was sent to anon session endpoint + RecordedRequest anonSessionRequest = server.takeRequest(1, TimeUnit.SECONDS); + assertNotNull("Anon session request should not be null", anonSessionRequest); + assertEquals("/" + IterableConstants.ENDPOINT_TRACK_ANON_SESSION, anonSessionRequest.getPath()); + + // check if request was sent to track purchase endpoint + RecordedRequest purchaseRequest = server.takeRequest(1, TimeUnit.SECONDS); + assertNotNull("Purchase request should not be null", purchaseRequest); + assertEquals("/" + IterableConstants.ENDPOINT_TRACK_PURCHASE, purchaseRequest.getPath()); + + // clear any pending requests while (server.takeRequest(1, TimeUnit.SECONDS) != null) { } + + // mock merge response + addResponse(IterableConstants.ENDPOINT_MERGE_USER); + + // set email final String email = "testUser@gmail.com"; IterableIdentityResolution identityResolution = new IterableIdentityResolution(true, false); IterableApi.getInstance().setEmail(email, identityResolution); + + // check if 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 email was set assertEquals(email, IterableApi.getInstance().getEmail()); } @Test public void testCriteriaMetEmailMergeTrue() 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_MERGE_USER); + addResponse(IterableConstants.ENDPOINT_TRACK_PURCHASE); + + // trigger track purchase event triggerTrackPurchaseEvent("test", "keyboard", 4.67, 3); shadowOf(getMainLooper()).idle(); - assertEquals("", getEventData()); + + // check if request was sent to anon session endpoint + RecordedRequest anonSessionRequest = server.takeRequest(1, TimeUnit.SECONDS); + assertNotNull("Anon session request should not be null", anonSessionRequest); + assertEquals("/" + IterableConstants.ENDPOINT_TRACK_ANON_SESSION, anonSessionRequest.getPath()); + + // check if request was sent to track purchase endpoint + RecordedRequest purchaseRequest = server.takeRequest(1, TimeUnit.SECONDS); + assertNotNull("Purchase request should not be null", purchaseRequest); + assertEquals("/" + IterableConstants.ENDPOINT_TRACK_PURCHASE, purchaseRequest.getPath()); + + // clear any pending requests while (server.takeRequest(1, TimeUnit.SECONDS) != null) { } + + // mock merge response + addResponse(IterableConstants.ENDPOINT_MERGE_USER); + + // set email final String email = "testUser@gmail.com"; - IterableApi.getInstance().setEmail(email); + IterableIdentityResolution identityResolution = new IterableIdentityResolution(true, true); + IterableApi.getInstance().setEmail(email, identityResolution); + + // check if request was sent to merge endpoint RecordedRequest mergeRequest = server.takeRequest(1, TimeUnit.SECONDS); assertNotNull(mergeRequest); - shadowOf(getMainLooper()).idle(); assertEquals("/" + IterableConstants.ENDPOINT_MERGE_USER, mergeRequest.getPath()); + + // check that email was set assertEquals(email, IterableApi.getInstance().getEmail()); } @Test public void testIdentifiedEmailDefault() throws Exception { + addResponse(IterableConstants.ENDPOINT_MERGE_USER); + + // set email final String email1 = "testUser1@gmail.com"; IterableApi.getInstance().setEmail(email1); - shadowOf(getMainLooper()).idle(); + + // check that email was set assertEquals(email1, IterableApi.getInstance().getEmail()); + + // clear any pending requests while (server.takeRequest(1, TimeUnit.SECONDS) != null) { } + + // set different email final String email2 = "testUser2@gmail.com"; IterableApi.getInstance().setEmail(email2); + + // 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 email was set assertEquals(email2, IterableApi.getInstance().getEmail()); } @Test public void testIdentifiedEmailMergeFalse() throws Exception { + addResponse(IterableConstants.ENDPOINT_MERGE_USER); + + // set email final String email1 = "testUser1@gmail.com"; IterableIdentityResolution identityResolution = new IterableIdentityResolution(true, false); IterableApi.getInstance().setEmail(email1, identityResolution); - shadowOf(getMainLooper()).idle(); + + // check that email was set assertEquals(email1, IterableApi.getInstance().getEmail()); + + // clear any pending requests while (server.takeRequest(1, TimeUnit.SECONDS) != null) { } + + // set different email final String email2 = "testUser2@gmail.com"; - IterableIdentityResolution identityResolution2 = new IterableIdentityResolution(true, false); - IterableApi.getInstance().setEmail(email2, identityResolution2); + IterableApi.getInstance().setEmail(email2, 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 email was set assertEquals(email2, IterableApi.getInstance().getEmail()); } @@ -801,19 +922,27 @@ public void testIdentifiedEmailMergeFalse() throws Exception { public void testIdentifiedEmailMergeTrue() throws Exception { addResponse(IterableConstants.ENDPOINT_MERGE_USER); + // set email final String email1 = "testUser1@gmail.com"; - IterableIdentityResolution identityResolution = new IterableIdentityResolution(true, false); + IterableIdentityResolution identityResolution = new IterableIdentityResolution(true, true); IterableApi.getInstance().setEmail(email1, identityResolution); - shadowOf(getMainLooper()).idle(); + + // check that email was set assertEquals(email1, IterableApi.getInstance().getEmail()); + + // clear any pending requests while (server.takeRequest(1, TimeUnit.SECONDS) != null) { } + // set different email final String email2 = "testUser2@gmail.com"; - IterableApi.getInstance().setEmail(email2); + IterableApi.getInstance().setEmail(email2, 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 email was set assertEquals(email2, IterableApi.getInstance().getEmail()); } } From 5aed92ba5f95ea96adca2f22916feb00dc19fe25 Mon Sep 17 00:00:00 2001 From: Evan Greer Date: Mon, 11 Nov 2024 12:40:29 -0700 Subject: [PATCH 12/12] updates identity resolution parameters --- .../iterable/iterableapi/IterableApiMergeUserEmailTests.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/iterableapi/src/test/java/com/iterable/iterableapi/IterableApiMergeUserEmailTests.java b/iterableapi/src/test/java/com/iterable/iterableapi/IterableApiMergeUserEmailTests.java index 76e6ca1a4..b5d8839f4 100644 --- a/iterableapi/src/test/java/com/iterable/iterableapi/IterableApiMergeUserEmailTests.java +++ b/iterableapi/src/test/java/com/iterable/iterableapi/IterableApiMergeUserEmailTests.java @@ -464,7 +464,7 @@ public void testCriteriaMetUserIdMergeTrue() throws Exception { // set user id final String userId = "testUser2"; - IterableIdentityResolution identityResolution = new IterableIdentityResolution(false, true); + IterableIdentityResolution identityResolution = new IterableIdentityResolution(true, true); IterableApi.getInstance().setUserId(userId, identityResolution); // check that request was sent to merge endpoint @@ -538,7 +538,7 @@ public void testIdentifiedUserIdMergeTrue() throws Exception { // set user id final String userId1 = "testUser1"; - IterableIdentityResolution identityResolution = new IterableIdentityResolution(true, false); + IterableIdentityResolution identityResolution = new IterableIdentityResolution(true, true); IterableApi.getInstance().setUserId(userId1, identityResolution); // check that user id was set