Skip to content

Commit c015c04

Browse files
More tests. Remove warning for Codable.
1 parent 6cf7a9e commit c015c04

File tree

3 files changed

+22
-39
lines changed

3 files changed

+22
-39
lines changed

Tests/swift-sdk-swift-tests/InAppHelperTests.swift

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -518,31 +518,38 @@ class InAppHelperTests: XCTestCase {
518518
}
519519

520520
// nil host
521-
func testCallbackUrlParsingCustomScheme1() {
521+
func testCallbackUrlParsingAppleWebdataScheme1() {
522522
let url = URL(string: "applewebdata://")!
523-
XCTAssertNil(InAppHelper.getCallbackAndDestinationUrl(url: url))
523+
XCTAssertNil(InAppHelper.parse(inAppUrl: url))
524524
}
525525

526526

527-
func testCallbackUrlParsingCustomScheme2() {
527+
func testCallbackUrlParsingAppleWebdataScheme2() {
528528
let url = URL(string: "applewebdata://this-is-uuid/the-real-url")!
529-
let (callbackUrl, destinationUrl) = InAppHelper.getCallbackAndDestinationUrl(url: url)!
530-
XCTAssertEqual(callbackUrl, "the-real-url")
531-
XCTAssertEqual(destinationUrl, "the-real-url")
529+
let parsed = InAppHelper.parse(inAppUrl: url)!
530+
if case let InAppHelper.InAppClickedUrl.localResource(name: name) = parsed {
531+
XCTAssertEqual(name, "the-real-url")
532+
} else {
533+
XCTFail("could not parse")
534+
}
532535
}
533536

534-
func testCallbackUrlParsingIterableScheme() {
535-
let url = URL(string: "itbl://buyProduct")!
536-
let (callbackUrl, destinationUrl) = InAppHelper.getCallbackAndDestinationUrl(url: url)!
537-
XCTAssertEqual(callbackUrl, "buyProduct")
538-
XCTAssertEqual(destinationUrl, "itbl://buyProduct")
537+
func testCallbackUrlParsingCustomActionScheme() {
538+
let url = URL(string: "action://buyProduct")!
539+
if case let InAppHelper.InAppClickedUrl.customAction(name: name) = InAppHelper.parse(inAppUrl: url)! {
540+
XCTAssertEqual(name, "buyProduct")
541+
} else {
542+
XCTFail("Could not parse")
543+
}
539544
}
540545

541546
func testCallbackUrlParsingRegularScheme() {
542547
let url = URL(string: "https://host/path")!
543-
let (callbackUrl, destinationUrl) = InAppHelper.getCallbackAndDestinationUrl(url: url)!
544-
XCTAssertEqual(callbackUrl, "https://host/path")
545-
XCTAssertEqual(destinationUrl, "https://host/path")
548+
if case let InAppHelper.InAppClickedUrl.regularUrl(parsedUrl) = InAppHelper.parse(inAppUrl: url)! {
549+
XCTAssertEqual(parsedUrl, url)
550+
} else {
551+
XCTFail("Could not parse")
552+
}
546553
}
547554

548555
private static let apiKey = "zeeApiKey"

swift-sdk/Internal/InAppHelper.swift

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -281,30 +281,6 @@ struct InAppHelper {
281281
}
282282
}
283283

284-
// Given the clicked url in inApp get the callbackUrl and destinationUrl
285-
static func getCallbackAndDestinationUrl(url: URL) -> (callbackUrl: String, destinationUrl: String)? {
286-
if url.scheme == UrlScheme.applewebdata.rawValue {
287-
// Since we are calling loadHTMLString with a nil baseUrl, any request url without a valid scheme get treated as a local resource.
288-
// Url looks like applewebdata://abc-def/something
289-
// Removes the extra applewebdata scheme/host data that is appended to the original url.
290-
// So in this case (callback = something, destination = something)
291-
// Warn the client that the request url does not contain a valid scheme
292-
ITBError("Request url contains an invalid scheme: \(url)")
293-
294-
guard let urlPath = getUrlPath(url: url) else {
295-
return nil
296-
}
297-
return (callbackUrl: urlPath, destinationUrl: urlPath)
298-
} else if url.scheme == UrlScheme.itbl.rawValue {
299-
// itbl://something => (callback = something, destination = itbl://something)
300-
let callbackUrl = dropScheme(urlString: url.absoluteString, scheme: UrlScheme.itbl.rawValue)
301-
return (callbackUrl: callbackUrl, destinationUrl: url.absoluteString)
302-
} else {
303-
// http, https etc, return unchanged
304-
return (url.absoluteString, url.absoluteString)
305-
}
306-
}
307-
308284
static func getInAppMessagesFromServer(internalApi: IterableAPIInternal, number: Int) -> Future<[IterableInAppMessage]> {
309285
return internalApi.getInAppMessages(NSNumber(value: number)).map {
310286
inAppMessages(fromPayload: $0, internalApi: internalApi)

swift-sdk/Internal/InAppPersistence.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import Foundation
88

99
// Adhering to Codable
10-
extension UIEdgeInsets : Codable {
10+
extension UIEdgeInsets {
1111
enum CodingKeys: String, CodingKey {
1212
case top
1313
case left

0 commit comments

Comments
 (0)