@@ -162,4 +162,55 @@ class IterableInAppNotificationTests: XCTestCase {
162
162
XCTAssert ( IterableInAppManager . getBackgroundAlpha ( fromInAppSettings: [ " backgroundAlpha " : 0.5 ] ) == 0.5 )
163
163
XCTAssert ( IterableInAppManager . getBackgroundAlpha ( fromInAppSettings: [ " backgroundAlpha " : 1 ] ) == 1.0 )
164
164
}
165
+
166
+ func testTrackInAppClickWithButtonUrl( ) {
167
+ let messageId = " message1 "
168
+ let buttonUrl = " http://somewhere.com "
169
+ let expectation1 = expectation ( description: " track in app messages " )
170
+
171
+ let networkSession = MockNetworkSession ( statusCode: 200 )
172
+ IterableAPI . initialize ( apiKey: IterableInAppNotificationTests . apiKey, networkSession: networkSession)
173
+ IterableAPI . email = IterableInAppNotificationTests . email
174
+ networkSession. callback = { ( _, _, _) in
175
+ TestUtils . validate ( request: networkSession. request!,
176
+ requestType: . post,
177
+ apiEndPoint: . ITBL_ENDPOINT_API,
178
+ path: . ITBL_PATH_TRACK_INAPP_CLICK,
179
+ queryParams: [ ( name: AnyHashable . ITBL_KEY_API_KEY, value: IterableInAppNotificationTests . apiKey) ,
180
+ ] )
181
+ let body = networkSession. getRequestBody ( ) as! [ String : Any ]
182
+ TestUtils . validateMatch ( keyPath: KeyPath ( " messageId " ) , value: messageId, inDictionary: body)
183
+ TestUtils . validateMatch ( keyPath: KeyPath ( " urlClick " ) , value: buttonUrl, inDictionary: body)
184
+ expectation1. fulfill ( )
185
+ }
186
+ IterableAPI . track ( inAppClick: messageId, buttonURL: buttonUrl)
187
+ wait ( for: [ expectation1] , timeout: testExpectationTimeout)
188
+ }
189
+
190
+ func testTrackInAppClickWithButtonIndex( ) {
191
+ let messageId = " message1 "
192
+ let buttonIndex = " 1 "
193
+ let expectation1 = expectation ( description: " track in app messages " )
194
+
195
+ let networkSession = MockNetworkSession ( statusCode: 200 )
196
+ IterableAPI . initialize ( apiKey: IterableInAppNotificationTests . apiKey, networkSession: networkSession)
197
+ IterableAPI . email = IterableInAppNotificationTests . email
198
+ networkSession. callback = { ( _, _, _) in
199
+ TestUtils . validate ( request: networkSession. request!,
200
+ requestType: . post,
201
+ apiEndPoint: . ITBL_ENDPOINT_API,
202
+ path: . ITBL_PATH_TRACK_INAPP_CLICK,
203
+ queryParams: [ ( name: AnyHashable . ITBL_KEY_API_KEY, value: IterableInAppNotificationTests . apiKey) ,
204
+ ] )
205
+ let body = networkSession. getRequestBody ( ) as! [ String : Any ]
206
+ TestUtils . validateMatch ( keyPath: KeyPath ( " messageId " ) , value: messageId, inDictionary: body)
207
+ TestUtils . validateMatch ( keyPath: KeyPath ( " buttonIndex " ) , value: buttonIndex, inDictionary: body)
208
+ expectation1. fulfill ( )
209
+ }
210
+ IterableAPI . track ( inAppClick: messageId, buttonIndex: buttonIndex)
211
+ wait ( for: [ expectation1] , timeout: testExpectationTimeout)
212
+ }
213
+
214
+ private static let apiKey = " zeeApiKey "
215
+ private static let email = " [email protected] "
165
216
}
0 commit comments