@@ -30,24 +30,23 @@ class IterableNotificationResponseTests: XCTestCase {
30
30
dateProvider. currentDate = Date ( )
31
31
}
32
32
33
- private static func customActionHandler( fromPromise promise: Promise < String , Error > ) -> CustomActionHandler {
34
- return { ( customActionName) in
35
- promise. resolve ( with: customActionName)
36
- return true
37
- }
38
- }
39
-
40
- private static func contextToCustomActionHandler( fromPromise promise: Promise < String , Error > ) -> ( IterableActionContext ) -> CustomActionHandler {
41
- return { ( context) in
42
- customActionHandler ( fromPromise: promise)
43
- }
44
- }
45
-
46
33
func testTrackOpenPushWithCustomAction( ) {
47
34
guard #available( iOS 10 . 0 , * ) else {
48
35
return
49
36
}
50
37
38
+ // we test with both 'true' and 'false' values below
39
+ // to make sure that it doesn't influence the result
40
+ // the return value is reserved for future use.
41
+ testTrackOpenPushWithCustomAction ( returnValue: true )
42
+ testTrackOpenPushWithCustomAction ( returnValue: false )
43
+ }
44
+
45
+ private func testTrackOpenPushWithCustomAction( returnValue: Bool ) {
46
+ guard #available( iOS 10 . 0 , * ) else {
47
+ return
48
+ }
49
+
51
50
let messageId = UUID ( ) . uuidString
52
51
let userInfo : [ AnyHashable : Any ] = [
53
52
" itbl " : [
@@ -60,31 +59,29 @@ class IterableNotificationResponseTests: XCTestCase {
60
59
]
61
60
]
62
61
]
63
-
62
+
64
63
let response = MockNotificationResponse ( userInfo: userInfo, actionIdentifier: UNNotificationDefaultActionIdentifier)
65
64
let pushTracker = MockPushTracker ( )
66
- let promise = Promise < String , Error > ( )
67
- promise. observe { ( result) in
68
- switch ( result) {
69
- case . error( let error) :
70
- XCTFail ( error. localizedDescription)
71
- case . value( let customActionName) :
72
- XCTAssertEqual ( customActionName, " customAction " )
73
- }
65
+ let expection = XCTestExpectation ( description: " customActionDelegate is called " )
66
+ let customActionDelegate = MockCustomActionDelegate ( returnValue: returnValue)
67
+ customActionDelegate. callback = { ( customActionName, context) in
68
+ XCTAssertEqual ( customActionName, " customAction " )
69
+ expection. fulfill ( )
74
70
}
75
-
71
+
76
72
let appIntegration = IterableAppIntegrationInternal ( tracker: pushTracker,
77
73
versionInfo: MockVersionInfo ( version: 10 ) ,
78
- contextToUrlHandler: nil ,
79
- contextToCustomActionHandler: IterableNotificationResponseTests . contextToCustomActionHandler ( fromPromise: promise) ,
74
+ customActionDelegate: customActionDelegate,
80
75
urlOpener: MockUrlOpener ( ) )
81
76
appIntegration. userNotificationCenter ( nil , didReceive: response, withCompletionHandler: nil )
82
77
78
+ wait ( for: [ expection] , timeout: testExpectationTimeout)
79
+
83
80
XCTAssertEqual ( pushTracker. campaignId, 1234 )
84
81
XCTAssertEqual ( pushTracker. templateId, 4321 )
85
82
XCTAssertEqual ( pushTracker. messageId, messageId)
86
83
XCTAssertFalse ( pushTracker. appAlreadyRunnnig)
87
-
84
+
88
85
XCTAssertEqual ( pushTracker. dataFields ? [ ITBL_KEY_ACTION_IDENTIFIER] as? String , ITBL_VALUE_DEFAULT_PUSH_OPEN_ACTION_ID)
89
86
}
90
87
@@ -113,23 +110,21 @@ class IterableNotificationResponseTests: XCTestCase {
113
110
let response = MockNotificationResponse ( userInfo: userInfo, actionIdentifier: " buttonIdentifier " )
114
111
let pushTracker = MockPushTracker ( )
115
112
116
- let promise = Promise < String , Error > ( )
117
- promise. observe { ( result) in
118
- switch ( result) {
119
- case . error( let error) :
120
- XCTFail ( error. localizedDescription)
121
- case . value( let customActionName) :
122
- XCTAssertEqual ( customActionName, " customAction " )
123
- }
113
+ let expection = XCTestExpectation ( description: " customActionDelegate is called " )
114
+ let customActionDelegate = MockCustomActionDelegate ( returnValue: true )
115
+ customActionDelegate. callback = { ( customActionName, context) in
116
+ XCTAssertEqual ( customActionName, " customAction " )
117
+ expection. fulfill ( )
124
118
}
125
-
119
+
126
120
let appIntegration = IterableAppIntegrationInternal ( tracker: pushTracker,
127
121
versionInfo: MockVersionInfo ( version: 10 ) ,
128
- contextToUrlHandler: nil ,
129
- contextToCustomActionHandler: IterableNotificationResponseTests . contextToCustomActionHandler ( fromPromise: promise) ,
122
+ customActionDelegate: customActionDelegate,
130
123
urlOpener: MockUrlOpener ( ) )
131
124
appIntegration. userNotificationCenter ( nil , didReceive: response, withCompletionHandler: nil )
132
125
126
+ wait ( for: [ expection] , timeout: testExpectationTimeout)
127
+
133
128
XCTAssertEqual ( pushTracker. campaignId, 1234 )
134
129
XCTAssertEqual ( pushTracker. templateId, 4321 )
135
130
XCTAssertEqual ( pushTracker. messageId, messageId)
@@ -152,25 +147,21 @@ class IterableNotificationResponseTests: XCTestCase {
152
147
]
153
148
154
149
let pushTracker = MockPushTracker ( )
155
-
156
- let promise = Promise < String , Error > ( )
157
- promise. observe { ( result) in
158
- switch ( result) {
159
- case . error( let error) :
160
- XCTFail ( error. localizedDescription)
161
- case . value( let customActionName) :
162
- XCTAssertEqual ( customActionName, " customAction " )
163
- }
150
+ let expection = XCTestExpectation ( description: " customActionDelegate is called " )
151
+ let customActionDelegate = MockCustomActionDelegate ( returnValue: true )
152
+ customActionDelegate. callback = { ( customActionName, context) in
153
+ XCTAssertEqual ( customActionName, " customAction " )
154
+ expection. fulfill ( )
164
155
}
165
156
166
157
let appIntegration = IterableAppIntegrationInternal ( tracker: pushTracker,
167
158
versionInfo: MockVersionInfo ( version: 9 ) ,
168
- contextToUrlHandler: nil ,
169
- contextToCustomActionHandler: IterableNotificationResponseTests . contextToCustomActionHandler ( fromPromise: promise) ,
159
+ customActionDelegate: customActionDelegate,
170
160
urlOpener: MockUrlOpener ( ) )
171
161
appIntegration. application ( MockApplicationStateProvider ( applicationState: . inactive) , didReceiveRemoteNotification: userInfo, fetchCompletionHandler: nil )
172
162
173
-
163
+ wait ( for: [ expection] , timeout: testExpectationTimeout)
164
+
174
165
XCTAssertEqual ( pushTracker. campaignId, 1234 )
175
166
XCTAssertEqual ( pushTracker. templateId, 4321 )
176
167
XCTAssertEqual ( pushTracker. messageId, messageId)
@@ -269,8 +260,6 @@ class IterableNotificationResponseTests: XCTestCase {
269
260
let pushTracker = MockPushTracker ( )
270
261
let appIntegration = IterableAppIntegrationInternal ( tracker: pushTracker,
271
262
versionInfo: MockVersionInfo ( version: 10 ) ,
272
- contextToUrlHandler: nil ,
273
- contextToCustomActionHandler: nil ,
274
263
urlOpener: urlOpener)
275
264
appIntegration. userNotificationCenter ( nil , didReceive: response, withCompletionHandler: nil )
276
265
0 commit comments