Skip to content

Commit 9bc7533

Browse files
committed
Revision 1
1. Updated JSON used by test cases to have read state. 2. Removed syncInApp calls as it is internally triggered when app comes to foreground. 3. Schedule Processing is manually called if the app comes to foreground within 60 seconds of its last sync. 4. Schedule processing is also called when getMessage call fails. It compensates for network being offline
1 parent 6f7f261 commit 9bc7533

File tree

5 files changed

+12
-10
lines changed

5 files changed

+12
-10
lines changed

iterableapi/src/main/java/com/iterable/iterableapi/IterableInAppManager.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,8 @@ public void execute(String payload) {
181181
} catch (JSONException e) {
182182
IterableLogger.e(TAG, e.toString());
183183
}
184+
} else {
185+
scheduleProcessing();
184186
}
185187
}
186188
});
@@ -430,6 +432,8 @@ private void handleIterableCustomAction(String actionName, IterableInAppMessage
430432
public void onSwitchToForeground() {
431433
if (IterableUtil.currentTimeMillis() - lastSyncTime > MOVE_TO_FOREGROUND_SYNC_INTERVAL_MS) {
432434
syncInApp();
435+
} else {
436+
scheduleProcessing();
433437
}
434438
}
435439

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -163,15 +163,14 @@ public void testReset() throws Exception {
163163
@Test
164164
public void testProcessAfterForeground() throws Exception {
165165
dispatcher.enqueueResponse("/inApp/getMessages", new MockResponse().setBody(IterableTestUtils.getResourceString("inapp_payload_single.json")));
166-
IterableInAppManager inAppManager = IterableApi.getInstance().getInAppManager();
167-
assertEquals(0, inAppManager.getMessages().size());
168166

169-
inAppManager.syncInApp();
167+
ActivityController<Activity> activityController = Robolectric.buildActivity(Activity.class).create().start().resume();
170168
shadowOf(getMainLooper()).idle();
171-
assertEquals(1, inAppManager.getMessages().size());
169+
shadowOf(getMainLooper()).runToEndOfTasks();
172170

173-
ActivityController<Activity> activityController = Robolectric.buildActivity(Activity.class).create().start().resume();
171+
IterableInAppManager inAppManager = IterableApi.getInstance().getInAppManager();
174172
shadowOf(getMainLooper()).idle();
173+
assertEquals(1, inAppManager.getMessages().size());
175174

176175
ArgumentCaptor<IterableInAppMessage> inAppMessageCaptor = ArgumentCaptor.forClass(IterableInAppMessage.class);
177176
verify(inAppHandler).onNewInApp(inAppMessageCaptor.capture());

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,13 +127,9 @@ public IterableConfig.Builder run(IterableConfig.Builder builder) {
127127
return builder.setInAppHandler(inAppHandler).setCustomActionHandler(customActionHandler).setUrlHandler(urlHandler);
128128
}
129129
});
130-
inAppManager.syncInApp();
131-
shadowOf(getMainLooper()).idle();
132-
133-
assertEquals(2, inAppManager.getInboxMessages().size());
134-
assertEquals(2, inAppManager.getUnreadInboxMessagesCount());
135130

136131
Robolectric.buildActivity(Activity.class).create().start().resume();
132+
shadowOf(getMainLooper()).idle();
137133

138134
verify(inAppDisplayerMock).showMessage(any(IterableInAppMessage.class), eq(IterableInAppLocation.IN_APP), any(IterableHelper.IterableUrlCallback.class));
139135

iterableapi/src/test/resources/inapp_payload_inbox_show.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
"inAppMessages": [
33
{
44
"messageId": "message1",
5+
"read": false,
56
"trigger": {
67
"type": "immediate"
78
},
@@ -28,6 +29,7 @@
2829
}
2930
},{
3031
"messageId": "message2",
32+
"read": false,
3133
"trigger": {
3234
"type": "immediate"
3335
},

iterableapi/src/test/resources/inapp_payload_single.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
{
44
"messageId": "7kx2MmoGdCpuZao9fDueuQoXVAZuDaVV",
55
"expiresAt": 1949157312395,
6+
"read": false,
67
"trigger": {
78
"type": "immediate"
89
},

0 commit comments

Comments
 (0)