Skip to content

Commit dee1e68

Browse files
hrishileanplume7mac
authored andcommitted
extra tests (#253)
1 parent 3c0e5d0 commit dee1e68

File tree

4 files changed

+116
-4
lines changed

4 files changed

+116
-4
lines changed

Example/Leanplum-SDK.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,8 @@
100100
A84527FD215C3035001FA20D /* LPRequestTest.m in Sources */ = {isa = PBXBuildFile; fileRef = A84527FC215C3035001FA20D /* LPRequestTest.m */; };
101101
A8EEA1AB20E44B0B00FF9A4D /* start_with_variant_debug_info_response.json in Resources */ = {isa = PBXBuildFile; fileRef = A8EEA1AA20E44B0A00FF9A4D /* start_with_variant_debug_info_response.json */; };
102102
A8EEA1AC20E44B0B00FF9A4D /* start_with_variant_debug_info_response.json in Resources */ = {isa = PBXBuildFile; fileRef = A8EEA1AA20E44B0A00FF9A4D /* start_with_variant_debug_info_response.json */; };
103+
B449EB2A21F27AB2005C93B6 /* TiedPrioritiesDifferentDelay.json in Resources */ = {isa = PBXBuildFile; fileRef = B449EB2921F27AB2005C93B6 /* TiedPrioritiesDifferentDelay.json */; };
104+
B449EB2B21F27B0B005C93B6 /* TiedPrioritiesDifferentDelay.json in Resources */ = {isa = PBXBuildFile; fileRef = B449EB2921F27AB2005C93B6 /* TiedPrioritiesDifferentDelay.json */; };
103105
B5CCCA2D1D74B64D005ADEE1 /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = B5CCCA2C1D74B64D005ADEE1 /* main.m */; };
104106
B5CCCA301D74B64D005ADEE1 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = B5CCCA2F1D74B64D005ADEE1 /* AppDelegate.m */; };
105107
B5CCCA331D74B64D005ADEE1 /* ViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = B5CCCA321D74B64D005ADEE1 /* ViewController.m */; };
@@ -207,6 +209,7 @@
207209
A54ACCFCB36AE8C874708A7F /* libPods-Leanplum-SDK_Example-Leanplum-SDK_Tests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-Leanplum-SDK_Example-Leanplum-SDK_Tests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
208210
A84527FC215C3035001FA20D /* LPRequestTest.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = LPRequestTest.m; sourceTree = "<group>"; };
209211
A8EEA1AA20E44B0A00FF9A4D /* start_with_variant_debug_info_response.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = start_with_variant_debug_info_response.json; sourceTree = "<group>"; };
212+
B449EB2921F27AB2005C93B6 /* TiedPrioritiesDifferentDelay.json */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.json; path = TiedPrioritiesDifferentDelay.json; sourceTree = "<group>"; };
210213
B5CCCA291D74B64D005ADEE1 /* Leanplum-tvOS-SDK_Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = "Leanplum-tvOS-SDK_Example.app"; sourceTree = BUILT_PRODUCTS_DIR; };
211214
B5CCCA2C1D74B64D005ADEE1 /* main.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = main.m; sourceTree = "<group>"; };
212215
B5CCCA2E1D74B64D005ADEE1 /* AppDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = AppDelegate.h; sourceTree = "<group>"; };
@@ -360,6 +363,7 @@
360363
07E5C8A01F052B7800A4B092 /* TestData */ = {
361364
isa = PBXGroup;
362365
children = (
366+
B449EB2921F27AB2005C93B6 /* TiedPrioritiesDifferentDelay.json */,
363367
07E5C8A11F052B7800A4B092 /* ChainedMessage.json */,
364368
07E5C8A21F052B7800A4B092 /* DifferentPriorities1.json */,
365369
07E5C8A31F052B7800A4B092 /* DifferentPriorities2.json */,
@@ -643,6 +647,7 @@
643647
07E5C8EF1F052DD000A4B092 /* DifferentPriorities2.json in Resources */,
644648
07E5C8E61F052DC400A4B092 /* variables_response.json in Resources */,
645649
07E5C8E11F052DC400A4B092 /* simple_start_response.json in Resources */,
650+
B449EB2A21F27AB2005C93B6 /* TiedPrioritiesDifferentDelay.json in Resources */,
646651
07E5C8F41F052DD000A4B092 /* SingleMessage.json in Resources */,
647652
07E5C8EC1F052DCC00A4B092 /* test.pdf in Resources */,
648653
);
@@ -667,6 +672,7 @@
667672
6003F5BA195388D20070C39A /* InfoPlist.strings in Resources */,
668673
07E5C8D61F052B7800A4B092 /* regionData.json in Resources */,
669674
07E5C8D81F052B7800A4B092 /* SingleMessage.json in Resources */,
675+
B449EB2B21F27B0B005C93B6 /* TiedPrioritiesDifferentDelay.json in Resources */,
670676
07E5C8CB1F052B7800A4B092 /* simple_start_response.json in Resources */,
671677
9CD04D941F8EE7E30033AB4A /* variables_with_newsfeed_response.json in Resources */,
672678
07E5C8C01F052B7800A4B092 /* MainAppIcon.png in Resources */,

Example/Tests/Classes/MessagesTest.m

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,16 @@ - (void) test_tied_priorities_identical
215215
withExpectedMessageIds:[NSSet setWithObjects:@"1", nil]];
216216
}
217217

218+
- (void) test_tied_priorities_identical_different_time
219+
{
220+
// Testing three messages with the same priority.
221+
NSString *jsonString = [LeanplumHelper retrieve_string_from_file:@"TiedPrioritiesDifferentDelay"
222+
ofType:@"json"];
223+
NSDictionary *messageConfigs = [LPJSON JSONFromString:jsonString];
224+
[self runInAppMessagePrioritizationTest:messageConfigs
225+
withExpectedMessageIds:[NSSet setWithObjects:@"1", @"2", @"3", nil]];
226+
}
227+
218228
- (void) test_different_priorities_with_missing_values
219229
{
220230
// Testing three messages with priorities of 10, 30, and no value.
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": 10,
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": 20,
38+
"vars": {
39+
"Dismiss action": "",
40+
"Message": "priority-5-c",
41+
"Title": "priority-5-c",
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": 5,
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": 30,
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+
}

Leanplum-SDK/Classes/Internal/Leanplum.m

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1834,15 +1834,15 @@ + (void)maybePerformActions:(NSArray *)whenConditions
18341834
// Make sure to capture the held back.
18351835
[LPActionContext sortByPriority:actionContexts];
18361836
NSNumber *priorityThreshold = [((LPActionContext *) [actionContexts firstObject]) priority];
1837-
NSNumber *countDownThreshold = [self fetchCountDownForContext: (LPActionContext *) [actionContexts firstObject]];
1837+
NSNumber *countDownThreshold = [self fetchCountDownForContext: (LPActionContext *) [actionContexts firstObject] withMessages:messages];
18381838
BOOL isPrioritySame = NO;
18391839
for (LPActionContext *actionContext in actionContexts) {
18401840
NSNumber *priority = [actionContext priority];
18411841
if (priority.intValue > priorityThreshold.intValue) {
18421842
break;
18431843
}
18441844
if (isPrioritySame) {//priority is same
1845-
NSNumber *currentCountDown = [self fetchCountDownForContext:actionContext];
1845+
NSNumber *currentCountDown = [self fetchCountDownForContext:actionContext withMessages:messages];
18461846
//multiple messages have same priority and same countDown, only display one message
18471847
if (currentCountDown == countDownThreshold) {
18481848
break;
@@ -1864,9 +1864,9 @@ + (void)maybePerformActions:(NSArray *)whenConditions
18641864
}
18651865
}
18661866

1867-
+ (NSNumber *)fetchCountDownForContext:(LPActionContext *)actionContext
1867+
+ (NSNumber *)fetchCountDownForContext:(LPActionContext *)actionContext withMessages:(NSDictionary *)messageDict
18681868
{
1869-
NSDictionary *messageConfig = [LPVarCache sharedCache].messageDiffs[actionContext.messageId];
1869+
NSDictionary *messageConfig = messageDict[actionContext.messageId];
18701870
NSNumber *countdown = messageConfig[@"countdown"];
18711871
if (actionContext.isPreview) {
18721872
countdown = @(5.0);

0 commit comments

Comments
 (0)