Skip to content

Commit

Permalink
orderId -> order_id
Browse files Browse the repository at this point in the history
  • Loading branch information
markmur committed Apr 24, 2024
1 parent ad4a009 commit 6be7ae8
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 16 deletions.
5 changes: 3 additions & 2 deletions Sources/ShopifyCheckoutSheetKit/CheckoutBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,17 @@ enum BridgeError: Swift.Error {
enum CheckoutBridge {
static let schemaVersion = "8.1"
static let messageHandler = "mobileCheckoutSdk"
internal static let userAgent = "ShopifyCheckoutSDK/\(ShopifyCheckoutSheetKit.version)"
internal static var logger: ProductionLogger = InternalLogger()

static var applicationName: String {
let theme = ShopifyCheckoutSheetKit.configuration.colorScheme.rawValue
return "ShopifyCheckoutSDK/\(ShopifyCheckoutSheetKit.version) (\(schemaVersion);\(theme);standard)"
return "\(userAgent) (\(schemaVersion);\(theme);standard)"
}

static var recoveryAgent: String {
let theme = ShopifyCheckoutSheetKit.configuration.colorScheme.rawValue
return "ShopifyCheckoutSheetKitRecovery/\(ShopifyCheckoutSheetKit.version) (theme=\(theme))"
return "\(userAgent) (noconnect;\(theme);standard_recovery)"
}

static func instrument(_ webView: WKWebView, _ instrumentation: InstrumentationPayload) {
Expand Down
2 changes: 1 addition & 1 deletion Sources/ShopifyCheckoutSheetKit/CheckoutWebView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -417,7 +417,7 @@ extension CheckoutWebView: WKNavigationDelegate {

let queryItems = urlComponents.queryItems ?? []

for item in queryItems where item.name == "orderId" {
for item in queryItems where item.name == "order_id" {
return item.value
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,6 @@ class CheckoutWebViewController: UIViewController, UIAdaptivePresentationControl
checkoutView.load(checkout: url)
progressBar.startAnimating()
}

}

extension CheckoutWebViewController: CheckoutWebViewDelegate {
Expand Down
31 changes: 19 additions & 12 deletions Tests/ShopifyCheckoutSheetKitTests/CheckoutWebViewTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class CheckoutWebViewTests: XCTestCase {
XCTAssertFalse(recovery.isBridgeAttached)
XCTAssertFalse(recovery.isPreloadingAvailable)
XCTAssertFalse(recovery.isBridgeAvailable)
XCTAssertEqual(recovery.configuration.applicationNameForUserAgent, "ShopifyCheckoutSheetKitRecovery/\(ShopifyCheckoutSheetKit.version) (theme=automatic)")
XCTAssertEqual(recovery.configuration.applicationNameForUserAgent, "ShopifyCheckoutSDK/\(ShopifyCheckoutSheetKit.version) (noconnect;automatic;standard_recovery)")
XCTAssertEqual(recovery.backgroundColor, backgroundColor)
XCTAssertFalse(recovery.isOpaque)
}
Expand Down Expand Up @@ -152,21 +152,28 @@ class CheckoutWebViewTests: XCTestCase {
}

func testObtainsOrderIDFromQuery() {
let url = URL(string: "http://shopify1.shopify.com/checkouts/c/12345/thank-you?orderId=1234")!
recovery = createRecoveryAgent()
recovery.load(checkout: url)
let didCompleteCheckoutExpectation = expectation(description: "checkoutViewDidCompleteCheckout was called")
let urls = [
"http://shopify1.shopify.com/checkouts/c/12345/thank-you?order_id=1234",
"http://shopify1.shopify.com/checkouts/c/12345/thank_you?order_id=1234",
"http://shopify1.shopify.com/checkouts/c/12345/thank_you/completed?order_id=1234"
]

mockDelegate.didEmitCheckoutCompletedEventExpectation = didCompleteCheckoutExpectation
recovery.viewDelegate = mockDelegate
for url in urls {
recovery = createRecoveryAgent()
recovery.load(checkout: URL(string: url)!)
let didCompleteCheckoutExpectation = expectation(description: "checkoutViewDidCompleteCheckout was called")

let urlResponse = HTTPURLResponse(url: url, statusCode: 200, httpVersion: nil, headerFields: nil)!
mockDelegate.didEmitCheckoutCompletedEventExpectation = didCompleteCheckoutExpectation
recovery.viewDelegate = mockDelegate

let policy = recovery.handleResponse(urlResponse)
XCTAssertEqual(policy, .allow)
let urlResponse = HTTPURLResponse(url: URL(string: url)!, statusCode: 200, httpVersion: nil, headerFields: nil)!

waitForExpectations(timeout: 5) { _ in
XCTAssertEqual(self.mockDelegate.completedEventReceived?.orderDetails.id, "1234")
let policy = recovery.handleResponse(urlResponse)
XCTAssertEqual(policy, .allow)

waitForExpectations(timeout: 5) { _ in
XCTAssertEqual(self.mockDelegate.completedEventReceived?.orderDetails.id, "1234")
}
}
}

Expand Down

0 comments on commit 6be7ae8

Please sign in to comment.