From 8948738168e02100b5a76dabe966b58bd0439842 Mon Sep 17 00:00:00 2001 From: Cian Buckley Date: Thu, 5 Oct 2023 09:11:00 +0200 Subject: [PATCH] add test and update bridge - msg not required --- Sources/ShopifyCheckout/CheckoutBridge.swift | 6 +++--- Sources/ShopifyCheckout/CheckoutView.swift | 4 ++-- .../ShopifyCheckoutTests/CheckoutBridgeTests.swift | 14 ++++++++++++++ 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/Sources/ShopifyCheckout/CheckoutBridge.swift b/Sources/ShopifyCheckout/CheckoutBridge.swift index 89b4c7ed..d71e3a69 100644 --- a/Sources/ShopifyCheckout/CheckoutBridge.swift +++ b/Sources/ShopifyCheckout/CheckoutBridge.swift @@ -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 { @@ -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) } diff --git a/Sources/ShopifyCheckout/CheckoutView.swift b/Sources/ShopifyCheckout/CheckoutView.swift index 0257c849..14f0eba7 100644 --- a/Sources/ShopifyCheckout/CheckoutView.swift +++ b/Sources/ShopifyCheckout/CheckoutView.swift @@ -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 { diff --git a/Tests/ShopifyCheckoutTests/CheckoutBridgeTests.swift b/Tests/ShopifyCheckoutTests/CheckoutBridgeTests.swift index 368fce5b..e29cf692 100644 --- a/Tests/ShopifyCheckoutTests/CheckoutBridgeTests.swift +++ b/Tests/ShopifyCheckoutTests/CheckoutBridgeTests.swift @@ -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)") + } + } }