Skip to content

Commit 5ae15de

Browse files
Murka notifications (#293)
Fix broken test cases
1 parent b54a5c7 commit 5ae15de

File tree

6 files changed

+233
-8
lines changed

6 files changed

+233
-8
lines changed

AndroidSDKCore/src/main/java/com/leanplum/internal/LeanplumInternal.java

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -245,17 +245,25 @@ public int compare(ActionContext o1, ActionContext o2) {
245245
}
246246
});
247247
int priorityThreshold = actionContexts.get(0).getPriority();
248-
boolean messageActionTriggered = false;
248+
int countDownThreshold = fetchCountDown(actionContexts.get(0), messages);
249+
Boolean isPrioritySame = false;
249250
for (final ActionContext actionContext : actionContexts) {
250251
if (actionContext.getPriority() > priorityThreshold) {
251252
break;
252253
}
253-
254+
// check if priority is same.
255+
if (isPrioritySame) {
256+
int currentCountDown = fetchCountDown(actionContext, messages);
257+
//multiple messages have same priority and same countDown, only display one message
258+
if (currentCountDown == countDownThreshold) {
259+
break;
260+
}
261+
}
262+
isPrioritySame = true;
254263
if (actionContext.actionName().equals(ActionManager.HELD_BACK_ACTION_NAME)) {
255264
ActionManager.getInstance().recordHeldBackImpression(
256265
actionContext.getMessageId(), actionContext.getOriginalMessageId());
257-
} else if (!messageActionTriggered) {
258-
messageActionTriggered = true;
266+
} else {
259267
LeanplumInternal.triggerAction(actionContext, new VariablesChangedCallback() {
260268
@Override
261269
public void variablesChanged() {
@@ -271,6 +279,18 @@ public void variablesChanged() {
271279
}
272280
}
273281

282+
private static int fetchCountDown(ActionContext context, Map<String, Object> messages) {
283+
// Get eta.
284+
Object countdownObj;
285+
if (((BaseActionContext) context).isPreview()) {
286+
countdownObj = 5.0;
287+
} else {
288+
Map<String, Object> messageConfig = CollectionUtil.uncheckedCast(messages.get(context.messageId));
289+
countdownObj = messageConfig.get("countdown");
290+
}
291+
return ((Number) countdownObj).intValue();
292+
}
293+
274294
private static Map<String, Object> makeTrackArgs(final String event, double value, String info,
275295
Map<String, ?> params, Map<String, String> args) {
276296
final Map<String, Object> requestParams = new HashMap<>();

AndroidSDKTests/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ android {
3636
includeAndroidResources = true
3737
}
3838
}
39+
lintOptions {
40+
abortOnError false
41+
}
3942
}
4043

4144
dependencies {

AndroidSDKTests/src/test/java/com/leanplum/LeanplumTest.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,6 +700,40 @@ public void onRequest(String httpMethod, String apiMethod, Map<String, Object> p
700700
Leanplum.trackGeofence(GeofenceEventType.ENTER_REGION, eventInfo);
701701
}
702702

703+
@Test
704+
public void testTrackEventsSamePriority() {
705+
706+
// Setup sdk first.
707+
setupSDK(mContext, "/responses/simple_start_response.json");
708+
709+
// Setup event values.
710+
final String eventName = "pushLocal";
711+
// Validate request for track with event name.
712+
RequestHelper.addRequestHandler(new RequestHelper.RequestHandler() {
713+
@Override
714+
public void onRequest(String httpMethod, String apiMethod, Map<String, Object> params) {
715+
assertEquals(Constants.Methods.TRACK, apiMethod);
716+
String requestEventName = (String) params.get("event");
717+
assertEquals(eventName, requestEventName);
718+
}
719+
});
720+
721+
// Validate response for event with same priority and countdown
722+
ResponseHelper.seedResponse("/responses/simple_start_response.json");
723+
724+
Leanplum.start(mContext, new StartCallback() {
725+
@Override
726+
public void onResponse(boolean success) {
727+
//App successfully starts with local notifications with same priority and countdown
728+
assertTrue(success);
729+
}
730+
});
731+
732+
assertTrue(Leanplum.hasStarted());
733+
Leanplum.track(eventName);
734+
735+
}
736+
703737
@Test
704738
public void testAdvance() throws Exception {
705739
setupSDK(RuntimeEnvironment.application, "/responses/simple_start_response.json");

AndroidSDKTests/src/test/java/com/leanplum/_whitebox/InAppMessagePrioritizationTest.java

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,23 @@ public void testDifferentPriorities() throws Exception {
178178
@Test
179179
public void testTiedPriorities() throws Exception {
180180
// Three messages with priorities of 5, no value, and 5.
181-
// The first one should be triggered.
181+
// 2 messages with same priority and same countdown
182+
// Only 1 should be displayed with highest priority.
182183
InputStream inputStream = getClass().getResourceAsStream("/test_files/tied_priorities_1.json");
183184
String jsonMessages = IOUtil.toString(inputStream);
184185
Set<String> expectedMessageIds = new HashSet<>(Arrays.asList("1"));
185186
assertExpectedMessagesAreTriggered(jsonMessages, expectedMessageIds);
186187

187-
// Three messages with same priority. Only one should be triggered.
188+
// Three messages with priorities of 5, no value, and 5.
189+
// 2 messages with same priority but different countdown
190+
// 2 messages should be displayed
191+
inputStream = getClass().getResourceAsStream("/test_files/tied_priorities_same_priority_different_time.json");
192+
jsonMessages = IOUtil.toString(inputStream);
193+
expectedMessageIds = new HashSet<>(Arrays.asList("1", "3"));
194+
assertExpectedMessagesAreTriggered(jsonMessages, expectedMessageIds);
195+
196+
// Three messages with same priority and same time
197+
// Only 1 should be trigged.
188198
inputStream = getClass().getResourceAsStream("/test_files/tied_priorities_2.json");
189199
jsonMessages = IOUtil.toString(inputStream);
190200
expectedMessageIds = new HashSet<>(Arrays.asList("1"));

AndroidSDKTests/src/test/resources/responses/simple_start_response.json

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,70 @@
44
"uploadUrl": "https:\/\/www.leanplum.com\/_ah\/upload\/AMmfu6by_4mWZUn19c8v_omIeRezDaIfzqCosKTZTY4HnsxrA963YsrYMMnTPd538fmb4Gyx17-evF7X_QBqFIYjwPuTeHzihGM5-FHkW8o1zKxNl8E9yB2ZiumXvOj-gMbotIZYA1I_\/ALBNUaYAAAAAWAZDRSTEVp_wufYkJ7EFVZK_9eVhM32E\/",
55
"interfaceRules": [
66
],
7+
"messages": {
8+
"4982955628167168": {
9+
"countdown": 5,
10+
"action": "__Push Notification",
11+
"whenTriggers": {
12+
"children": [{
13+
"subject": "event",
14+
"objects": [],
15+
"verb": "triggers",
16+
"noun": "pushLocal",
17+
"secondaryVerb": "="
18+
}],
19+
"verb": "OR"
20+
},
21+
"parentCampaignId": null,
22+
"vars": {
23+
"Message": "Push Local #1",
24+
"__name__": "__Push Notification"
25+
},
26+
"hasImpressionCriteria": false,
27+
"priority": 1000,
28+
"whenLimits": {
29+
"children": [],
30+
"subject": null,
31+
"objects": []
32+
},
33+
"unlessTriggers": {
34+
"children": [],
35+
"subject": null,
36+
"objects": []
37+
}
38+
},
39+
"5571264209354752": {
40+
"countdown": 5,
41+
"action": "__Push Notification",
42+
"whenTriggers": {
43+
"children": [{
44+
"subject": "event",
45+
"objects": [],
46+
"verb": "triggers",
47+
"noun": "pushLocal",
48+
"secondaryVerb": "="
49+
}],
50+
"verb": "OR"
51+
},
52+
"parentCampaignId": null,
53+
"vars": {
54+
"Message": "Push Local #2",
55+
"__name__": "__Push Notification"
56+
},
57+
"hasImpressionCriteria": false,
58+
"priority": 1000,
59+
"whenLimits": {
60+
"children": [],
61+
"subject": null,
62+
"objects": []
63+
},
64+
"unlessTriggers": {
65+
"children": [],
66+
"subject": null,
67+
"objects": []
68+
}
69+
}
70+
},
771
"actionDefinitions": {
872
"Confirm": {
973
"values": {
@@ -223,8 +287,6 @@
223287
"isRegistered": false,
224288
"regions": {
225289
},
226-
"messages": {
227-
},
228290
"varsFromCode": {
229291
"emptyDictionary": {
230292
"integerValue": 50
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
{
2+
"1": {
3+
"action": "Alert",
4+
"countdown": 86400,
5+
"vars": {
6+
"Dismiss action": "",
7+
"Message": "priority-5-a",
8+
"Title": "priority-5-a",
9+
"Dismiss text": "OK",
10+
"__name__": "Alert"
11+
},
12+
"whenLimits": {
13+
"verb": "AND",
14+
"children": [
15+
{
16+
"objects": [],
17+
"noun": "999",
18+
"subject": "times",
19+
"verb": "limitUser"
20+
}
21+
]
22+
},
23+
"priority": 5,
24+
"whenTriggers": {
25+
"verb": "OR",
26+
"children": [
27+
{
28+
"objects": [],
29+
"subject": "start",
30+
"verb": ""
31+
}
32+
]
33+
}
34+
},
35+
"2": {
36+
"action": "Alert",
37+
"countdown": 86400,
38+
"vars": {
39+
"Dismiss action": "",
40+
"Message": "NO-priority",
41+
"Title": "NO-priority",
42+
"Dismiss text": "OK",
43+
"__name__": "Alert"
44+
},
45+
"whenLimits": {
46+
"verb": "AND",
47+
"children": [
48+
{
49+
"objects": [],
50+
"noun": "999",
51+
"subject": "times",
52+
"verb": "limitUser"
53+
}
54+
]
55+
},
56+
"priority": 1000,
57+
"whenTriggers": {
58+
"verb": "OR",
59+
"children": [
60+
{
61+
"objects": [],
62+
"subject": "start",
63+
"verb": ""
64+
}
65+
]
66+
}
67+
},
68+
"3": {
69+
"action": "Alert",
70+
"countdown": 10,
71+
"vars": {
72+
"Dismiss action": "",
73+
"Message": "priority-5-b",
74+
"Title": "priority-5-b",
75+
"Dismiss text": "OK",
76+
"__name__": "Alert"
77+
},
78+
"whenLimits": {
79+
"objects": [],
80+
"subject": null,
81+
"children": []
82+
},
83+
"priority": 5,
84+
"whenTriggers": {
85+
"verb": "OR",
86+
"children": [
87+
{
88+
"objects": [],
89+
"noun": "Nowhere",
90+
"subject": "enterRegion",
91+
"verb": ""
92+
}
93+
]
94+
}
95+
}
96+
}

0 commit comments

Comments
 (0)