Skip to content

Commit

Permalink
add test and update bridge - msg not required
Browse files Browse the repository at this point in the history
  • Loading branch information
cianbuckley committed Oct 5, 2023
1 parent 74bd05c commit 8948738
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 5 deletions.
6 changes: 3 additions & 3 deletions Sources/ShopifyCheckout/CheckoutBridge.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ extension CheckoutBridge {
enum WebEvent: Decodable {
case checkoutComplete
case checkoutCanceled
case checkoutNotAvailable(String)
case checkoutNotAvailable
case unsupported(String)

enum CodingKeys: String, CodingKey {
Expand All @@ -74,8 +74,8 @@ extension CheckoutBridge {
self = .checkoutComplete
case "close":
self = .checkoutCanceled
case "checkout_not_available":
self = .checkoutNotAvailable(name)
case "checkoutNotAvailable":
self = .checkoutNotAvailable
default:
self = .unsupported(name)
}
Expand Down
4 changes: 2 additions & 2 deletions Sources/ShopifyCheckout/CheckoutView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,9 @@ extension CheckoutView: WKScriptMessageHandler {
case .checkoutComplete:
CheckoutView.cache = nil
viewDelegate?.checkoutViewDidCompleteCheckout()
case .checkoutNotAvailable(let message):
case .checkoutNotAvailable:
CheckoutView.cache = nil
viewDelegate?.checkoutViewDidFailWithError(error: .checkoutNotAvailable(message: message))
viewDelegate?.checkoutViewDidFailWithError(error: .checkoutNotAvailable(message: "Checkout not available."))
default: break
}
} catch {
Expand Down
14 changes: 14 additions & 0 deletions Tests/ShopifyCheckoutTests/CheckoutBridgeTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -97,4 +97,18 @@ class CheckoutBridgeTests: XCTestCase {
return XCTFail("expected CheckoutScriptMessage.checkoutComplete, got \(result)")
}
}

func testDecodeSupportsCheckoutNotAvailableEvent() throws {
let mock = WKScriptMessageMock(body: """
{
"name": "checkoutNotAvailable"
}
""")

let result = try CheckoutBridge.decode(mock)

guard case CheckoutBridge.WebEvent.checkoutNotAvailable = result else {
return XCTFail("expected CheckoutScriptMessage.checkoutNotAvailable, got \(result)")
}
}
}

0 comments on commit 8948738

Please sign in to comment.