Skip to content

Commit bd82d13

Browse files
Add unit tests for DDL.
1 parent d906d6b commit bd82d13

File tree

2 files changed

+113
-0
lines changed

2 files changed

+113
-0
lines changed
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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+
}

swift-sdk.xcodeproj/project.pbxproj

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
objects = {
88

99
/* Begin PBXBuildFile section */
10+
007960EE213F8B2300C53A6A /* DeferredDeeplinkTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 007960ED213F8B2300C53A6A /* DeferredDeeplinkTests.swift */; };
1011
00B6FACC210E8484007535CF /* APNSUtilTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00B6FACB210E8484007535CF /* APNSUtilTests.swift */; };
1112
00B6FACE210E88ED007535CF /* prod-1.mobileprovision in Resources */ = {isa = PBXBuildFile; fileRef = 00B6FACD210E874D007535CF /* prod-1.mobileprovision */; };
1213
00B6FAD1210E8D90007535CF /* dev-1.mobileprovision in Resources */ = {isa = PBXBuildFile; fileRef = 00B6FAD0210E8D90007535CF /* dev-1.mobileprovision */; };
@@ -119,6 +120,7 @@
119120
/* End PBXContainerItemProxy section */
120121

121122
/* Begin PBXFileReference section */
123+
007960ED213F8B2300C53A6A /* DeferredDeeplinkTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DeferredDeeplinkTests.swift; sourceTree = "<group>"; };
122124
00B6FACB210E8484007535CF /* APNSUtilTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = APNSUtilTests.swift; sourceTree = "<group>"; };
123125
00B6FACD210E874D007535CF /* prod-1.mobileprovision */ = {isa = PBXFileReference; lastKnownFileType = file; path = "prod-1.mobileprovision"; sourceTree = "<group>"; };
124126
00B6FAD0210E8D90007535CF /* dev-1.mobileprovision */ = {isa = PBXFileReference; lastKnownFileType = file; path = "dev-1.mobileprovision"; sourceTree = "<group>"; };
@@ -411,6 +413,7 @@
411413
AC2C668320D3370600D46CC9 /* Mocks.swift */,
412414
AC89661D2124FBCE0051A6CD /* IterableAutoRegistrationTests.swift */,
413415
ACE34AB4213776CB00691224 /* LocalStorageTests.swift */,
416+
007960ED213F8B2300C53A6A /* DeferredDeeplinkTests.swift */,
414417
);
415418
path = "swift-sdk-swift-tests";
416419
sourceTree = "<group>";
@@ -838,6 +841,7 @@
838841
00CB31B621096129004ACDEC /* TestUtils.swift in Sources */,
839842
AC89661E2124FBCE0051A6CD /* IterableAutoRegistrationTests.swift in Sources */,
840843
00B6FACC210E8484007535CF /* APNSUtilTests.swift in Sources */,
844+
007960EE213F8B2300C53A6A /* DeferredDeeplinkTests.swift in Sources */,
841845
AC776DA4211A17C700C27C27 /* IterableRequestUtilTests.swift in Sources */,
842846
ACE34AB5213776CB00691224 /* LocalStorageTests.swift in Sources */,
843847
AC6FDD8C20F56309005D811E /* IterableInAppNotificationTests.swift in Sources */,

0 commit comments

Comments
 (0)