Skip to content

Commit ddec36a

Browse files
Track in-app click tests.
1 parent 45884af commit ddec36a

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

Tests/swift-sdk-swift-tests/IterableInAppNotificationTests.swift

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,4 +162,55 @@ class IterableInAppNotificationTests: XCTestCase {
162162
XCTAssert(IterableInAppManager.getBackgroundAlpha(fromInAppSettings: ["backgroundAlpha" : 0.5]) == 0.5)
163163
XCTAssert(IterableInAppManager.getBackgroundAlpha(fromInAppSettings: ["backgroundAlpha" : 1]) == 1.0)
164164
}
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]"
165216
}

0 commit comments

Comments
 (0)