Skip to content

Commit cf5d084

Browse files
Merge pull request #519 from Iterable/tapash/mob-3724-deeplink-return
[MOB-3724] - handleUniversalLink return value
2 parents 2217376 + 1d1dc74 commit cf5d084

File tree

2 files changed

+26
-21
lines changed

2 files changed

+26
-21
lines changed

swift-sdk/Internal/IterableDeepLinkManager.swift

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,17 +42,14 @@ class IterableDeepLinkManager: NSObject {
4242
if let action = IterableAction.actionOpenUrl(fromUrlString: url.absoluteString) {
4343
let context = IterableActionContext(action: action, source: .universalLink)
4444

45-
let result = IterableActionRunner.execute(action: action,
46-
context: context,
47-
urlHandler: IterableUtil.urlHandler(fromUrlDelegate: urlDelegate,
48-
inContext: context),
49-
urlOpener: urlOpener,
50-
allowedProtocols: allowedProtocols)
51-
52-
return (result, Promise<IterableAttributionInfo?, Error>(value: nil))
53-
} else {
54-
return (false, Promise<IterableAttributionInfo?, Error>(value: nil))
45+
IterableActionRunner.execute(action: action,
46+
context: context,
47+
urlHandler: IterableUtil.urlHandler(fromUrlDelegate: urlDelegate,
48+
inContext: context),
49+
urlOpener: urlOpener,
50+
allowedProtocols: allowedProtocols)
5551
}
52+
return (false, Promise<IterableAttributionInfo?, Error>(value: nil))
5653
}
5754
}
5855

tests/unit-tests/DeepLinkTests.swift

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ class DeepLinkTests: XCTestCase {
2323
private let exampleUrl = "http://example.com"
2424

2525
func testTrackUniversalDeepLinkRewrite() {
26-
let expectation1 = expectation(description: "testUniversalDeepLinkRewrite")
26+
let expectation1 = expectation(description: #function)
27+
let expectation2 = expectation(description: "\(#function)-attributionInfo")
2728

2829
let redirectLocation = "https://links.iterable.com/api/docs#!/email"
2930
let campaignId = 83306
@@ -42,18 +43,24 @@ class DeepLinkTests: XCTestCase {
4243

4344
let deepLinkManager = IterableDeepLinkManager()
4445

45-
_ = deepLinkManager.handleUniversalLink(URL(string: iterableRewriteURL)!,
46-
urlDelegate: mockUrlDelegate,
47-
urlOpener: MockUrlOpener())
48-
49-
wait(for: [expectation1], timeout: testExpectationTimeout)
46+
let (isIterableLink, attributionInfoFuture) = deepLinkManager.handleUniversalLink(URL(string: iterableRewriteURL)!,
47+
urlDelegate: mockUrlDelegate,
48+
urlOpener: MockUrlOpener())
49+
XCTAssertTrue(isIterableLink)
50+
attributionInfoFuture.onSuccess { attributionInfo in
51+
XCTAssertEqual(attributionInfo?.campaignId, NSNumber(value: campaignId))
52+
XCTAssertEqual(attributionInfo?.templateId, NSNumber(value: templateId))
53+
XCTAssertEqual(attributionInfo?.messageId, messageId)
54+
expectation2.fulfill()
55+
}
56+
wait(for: [expectation1, expectation2], timeout: testExpectationTimeout)
5057
}
5158

5259
func testTrackUniversalDeepLinkNoRewrite() {
5360
let expectation1 = expectation(description: "testUniversalDeepLinkNoRewrite")
5461

5562
setupStubResponse()
56-
63+
5764
let mockUrlDelegate = MockUrlDelegate(returnValue: true)
5865
mockUrlDelegate.callback = { url, context in
5966
XCTAssertEqual(url.absoluteString, self.iterableNoRewriteURL)
@@ -64,10 +71,11 @@ class DeepLinkTests: XCTestCase {
6471

6572
let deepLinkManager = IterableDeepLinkManager()
6673

67-
_ = deepLinkManager.handleUniversalLink(URL(string: iterableNoRewriteURL)!,
68-
urlDelegate: mockUrlDelegate,
69-
urlOpener: MockUrlOpener())
70-
74+
let (isIterableLink, _) = deepLinkManager.handleUniversalLink(URL(string: iterableNoRewriteURL)!,
75+
urlDelegate: mockUrlDelegate,
76+
urlOpener: MockUrlOpener())
77+
78+
XCTAssertFalse(isIterableLink)
7179
wait(for: [expectation1], timeout: testExpectationTimeout)
7280
}
7381

0 commit comments

Comments
 (0)