@@ -32,29 +32,42 @@ class DeepLinkTests: XCTestCase {
32
32
33
33
setupRedirectStubResponse ( location: redirectLocation, campaignId: campaignId, templateId: templateId, messageId: messageId)
34
34
35
- let internalAPI = InternalIterableAPI . initializeForTesting ( )
36
-
37
- internalAPI. getAndTrack ( deepLink: URL ( string: iterableRewriteURL) !) { redirectUrl in
38
- XCTAssertEqual ( redirectUrl, redirectLocation)
35
+ let mockUrlDelegate = MockUrlDelegate ( returnValue: true )
36
+ mockUrlDelegate. callback = { url, context in
37
+ XCTAssertEqual ( url. absoluteString, redirectLocation)
39
38
XCTAssertTrue ( Thread . isMainThread)
39
+ XCTAssertEqual ( context. action. type, IterableAction . actionTypeOpenUrl)
40
40
expectation1. fulfill ( )
41
41
}
42
42
43
+ let deepLinkManager = IterableDeepLinkManager ( )
44
+
45
+ _ = deepLinkManager. handleUniversalLink ( URL ( string: iterableRewriteURL) !,
46
+ urlDelegate: mockUrlDelegate,
47
+ urlOpener: MockUrlOpener ( ) )
48
+
43
49
wait ( for: [ expectation1] , timeout: testExpectationTimeout)
44
50
}
45
51
46
52
func testTrackUniversalDeepLinkNoRewrite( ) {
47
53
let expectation1 = expectation ( description: " testUniversalDeepLinkNoRewrite " )
48
54
49
55
setupStubResponse ( )
50
-
51
- let internalAPI = InternalIterableAPI . initializeForTesting ( )
52
- internalAPI . getAndTrack ( deepLink : URL ( string : iterableNoRewriteURL ) ! ) { redirectUrl in
53
- XCTAssertEqual ( redirectUrl , self . iterableNoRewriteURL)
56
+
57
+ let mockUrlDelegate = MockUrlDelegate ( returnValue : true )
58
+ mockUrlDelegate . callback = { url , context in
59
+ XCTAssertEqual ( url . absoluteString , self . iterableNoRewriteURL)
54
60
XCTAssertTrue ( Thread . isMainThread)
61
+ XCTAssertEqual ( context. action. type, IterableAction . actionTypeOpenUrl)
55
62
expectation1. fulfill ( )
56
63
}
57
64
65
+ let deepLinkManager = IterableDeepLinkManager ( )
66
+
67
+ _ = deepLinkManager. handleUniversalLink ( URL ( string: iterableNoRewriteURL) !,
68
+ urlDelegate: mockUrlDelegate,
69
+ urlOpener: MockUrlOpener ( ) )
70
+
58
71
wait ( for: [ expectation1] , timeout: testExpectationTimeout)
59
72
}
60
73
@@ -84,31 +97,8 @@ class DeepLinkTests: XCTestCase {
84
97
wait ( for: [ expectation1] , timeout: testExpectationTimeout)
85
98
}
86
99
87
- func testDeeplinkAttributionInfo( ) {
88
- let expectation1 = expectation ( description: " testDeeplinkAttributionInfo " )
89
-
90
- let redirectLocation = " https://links.iterable.com/api/docs#!/email "
91
- let campaignId = 83306
92
- let templateId = 124_348
93
- let messageId = " 93125f33ba814b13a882358f8e0852e0 "
94
-
95
- setupRedirectStubResponse ( location: redirectLocation, campaignId: campaignId, templateId: templateId, messageId: messageId)
96
-
97
- let internalAPI = InternalIterableAPI . initializeForTesting ( )
98
- internalAPI. getAndTrack ( deepLink: URL ( string: iterableRewriteURL) !) { resolvedURL in
99
- XCTAssertEqual ( resolvedURL, redirectLocation)
100
- } ? . onSuccess ( block: { _ in
101
- XCTAssertEqual ( internalAPI. attributionInfo? . campaignId, NSNumber ( value: campaignId) )
102
- XCTAssertEqual ( internalAPI. attributionInfo? . templateId, NSNumber ( value: templateId) )
103
- XCTAssertEqual ( internalAPI. attributionInfo? . messageId, messageId)
104
- expectation1. fulfill ( )
105
- } )
106
-
107
- wait ( for: [ expectation1] , timeout: testExpectationTimeout)
108
- }
109
-
110
100
func testHandleUniversalLinkAttributionInfo( ) {
111
- let expectation1 = expectation ( description: " testDeeplinkAttributionInfo " )
101
+ let expectation1 = expectation ( description: " testHandleUniversalLinkAttributionInfo " )
112
102
113
103
let redirectLocation = " https://links.iterable.com/api/docs#!/email "
114
104
let campaignId = 83306
@@ -130,20 +120,26 @@ class DeepLinkTests: XCTestCase {
130
120
wait ( for: [ expectation1] , timeout: testExpectationTimeout)
131
121
}
132
122
133
- // this is a service that automatically redirects if that url is hit, make sure we are not actually hitting the url
134
- // but our servers
123
+ /// this is a service that automatically redirects if that url is hit, make sure we are not actually hitting the url but our servers
135
124
func testNoURLRedirect( ) {
136
125
let expectation1 = expectation ( description: " testNoURLRedirect " )
137
126
138
127
setupStubResponse ( )
139
128
140
- let internalAPI = InternalIterableAPI . initializeForTesting ( )
141
- internalAPI. getAndTrack ( deepLink: URL ( string: redirectRequest) !) { redirectUrl in
142
- XCTAssertNotEqual ( redirectUrl, self . exampleUrl)
143
- XCTAssertEqual ( redirectUrl, self . redirectRequest)
129
+ let mockUrlDelegate = MockUrlDelegate ( returnValue: false )
130
+ mockUrlDelegate. callback = { redirectUrl, context in
131
+ XCTAssertNotEqual ( redirectUrl. absoluteString, self . exampleUrl)
132
+ XCTAssertEqual ( redirectUrl. absoluteString, self . redirectRequest)
133
+
144
134
expectation1. fulfill ( )
145
135
}
146
136
137
+ let deepLinkManager = IterableDeepLinkManager ( )
138
+
139
+ _ = deepLinkManager. handleUniversalLink ( URL ( string: redirectRequest) !,
140
+ urlDelegate: mockUrlDelegate,
141
+ urlOpener: MockUrlOpener ( ) )
142
+
147
143
wait ( for: [ expectation1] , timeout: testExpectationTimeout)
148
144
}
149
145
0 commit comments