|
| 1 | +// |
| 2 | +// DeferredDeeplinkTests.swift |
| 3 | +// swift-sdk-swift-tests |
| 4 | +// |
| 5 | +// Created by Tapash Majumder on 9/4/18. |
| 6 | +// Copyright © 2018 Iterable. All rights reserved. |
| 7 | +// |
| 8 | + |
| 9 | +import XCTest |
| 10 | +@testable import IterableSDK |
| 11 | + |
| 12 | +class DeferredDeeplinkTests: XCTestCase { |
| 13 | + private static let apiKey = "zeeApiKey" |
| 14 | + |
| 15 | + override func setUp() { |
| 16 | + super.setUp() |
| 17 | + TestUtils.clearUserDefaults() |
| 18 | + } |
| 19 | + |
| 20 | + override func tearDown() { |
| 21 | + // Put teardown code here. This method is called after the invocation of each test method in the class. |
| 22 | + super.tearDown() |
| 23 | + } |
| 24 | + |
| 25 | + func testCallCheckForDDL() { |
| 26 | + let expectation = XCTestExpectation(description: "callCheckForDDL") |
| 27 | + |
| 28 | + let json: [AnyHashable : Any] = [ |
| 29 | + "isMatch" : true, |
| 30 | + "destinationUrl" : "zeeDestinationUrl", |
| 31 | + "campaignId" : "1", |
| 32 | + "templateId" : "1", |
| 33 | + "messageId" : "1" |
| 34 | + ] |
| 35 | + let networkSession = MockNetworkSession(statusCode: 200, json: json) |
| 36 | + |
| 37 | + let config = IterableConfig() |
| 38 | + config.checkForDeferredDeeplink = true |
| 39 | + let urlDelegate = MockUrlDelegate(returnValue: true) |
| 40 | + urlDelegate.callback = {(url, context) in |
| 41 | + expectation.fulfill() |
| 42 | + XCTAssertEqual(url.absoluteString, "zeeDestinationUrl") |
| 43 | + } |
| 44 | + config.urlDelegate = urlDelegate |
| 45 | + IterableAPI.initialize(apiKey: DeferredDeeplinkTests.apiKey, config: config, networkSession: networkSession) |
| 46 | + |
| 47 | + wait(for: [expectation], timeout: testExpectationTimeout) |
| 48 | + |
| 49 | + // Test that calling second time does not trigger |
| 50 | + let expectation2 = XCTestExpectation(description: "should not callCheckForDDL") |
| 51 | + expectation2.isInverted = true |
| 52 | + let config2 = IterableConfig() |
| 53 | + config2.checkForDeferredDeeplink = true |
| 54 | + let urlDelegate2 = MockUrlDelegate(returnValue: true) |
| 55 | + urlDelegate2.callback = {(url, context) in |
| 56 | + expectation2.fulfill() |
| 57 | + } |
| 58 | + config.urlDelegate = urlDelegate2 |
| 59 | + IterableAPI.initialize(apiKey: DeferredDeeplinkTests.apiKey, config: config, networkSession: networkSession) |
| 60 | + |
| 61 | + wait(for: [expectation2], timeout: 1.0) |
| 62 | + } |
| 63 | + |
| 64 | + func testDDLNoMatch() { |
| 65 | + let expectation = XCTestExpectation(description: "testDDL No Match") |
| 66 | + expectation.isInverted = true |
| 67 | + |
| 68 | + let json: [AnyHashable : Any] = [ |
| 69 | + "isMatch" : false, |
| 70 | + ] |
| 71 | + let networkSession = MockNetworkSession(statusCode: 200, json: json) |
| 72 | + |
| 73 | + let config = IterableConfig() |
| 74 | + config.checkForDeferredDeeplink = true |
| 75 | + let urlDelegate = MockUrlDelegate(returnValue: true) |
| 76 | + urlDelegate.callback = {(url, context) in |
| 77 | + expectation.fulfill() |
| 78 | + } |
| 79 | + config.urlDelegate = urlDelegate |
| 80 | + IterableAPI.initialize(apiKey: DeferredDeeplinkTests.apiKey, config: config, networkSession: networkSession) |
| 81 | + |
| 82 | + wait(for: [expectation], timeout: 1.0) |
| 83 | + } |
| 84 | + |
| 85 | + func testCheckForDeferredDDLIsSetToFalse() { |
| 86 | + let expectation = XCTestExpectation(description: "testDDL No Match") |
| 87 | + expectation.isInverted = true |
| 88 | + |
| 89 | + let json: [AnyHashable : Any] = [ |
| 90 | + "isMatch" : true, |
| 91 | + "destinationUrl" : "zeeDestinationUrl", |
| 92 | + "campaignId" : "1", |
| 93 | + "templateId" : "1", |
| 94 | + "messageId" : "1" |
| 95 | + ] |
| 96 | + let networkSession = MockNetworkSession(statusCode: 200, json: json) |
| 97 | + |
| 98 | + let config = IterableConfig() |
| 99 | + config.checkForDeferredDeeplink = false |
| 100 | + let urlDelegate = MockUrlDelegate(returnValue: true) |
| 101 | + urlDelegate.callback = {(url, context) in |
| 102 | + expectation.fulfill() |
| 103 | + } |
| 104 | + config.urlDelegate = urlDelegate |
| 105 | + IterableAPI.initialize(apiKey: DeferredDeeplinkTests.apiKey, config: config, networkSession: networkSession) |
| 106 | + |
| 107 | + wait(for: [expectation], timeout: 1.0) |
| 108 | + } |
| 109 | +} |
0 commit comments