From d92966f388e6389e4e17ff9d8d41be9f8fab0f35 Mon Sep 17 00:00:00 2001 From: Kieran Osgood Date: Tue, 18 Aug 2026 10:00:19 +0100 Subject: [PATCH] fix: incorrect merge result enum value --- .../checkoutkit/ShopifyCheckoutKitModule.java | 4 ++-- .../api/checkout-kit-react-native.api.md | 3 +-- .../ios/ShopifyCheckoutKit.swift | 10 ++++------ .../@shopify/checkout-kit-react-native/src/index.d.ts | 3 +-- .../@shopify/checkout-kit-react-native/src/preload.ts | 3 +-- .../checkout-kit-react-native/tests/index.test.ts | 8 ++++---- .../reactnativedemo/ShopifyCheckoutKitModuleTest.java | 7 ++++--- .../ShopifyCheckoutKitTests.swift | 6 ++++++ 8 files changed, 23 insertions(+), 21 deletions(-) diff --git a/platforms/react-native/modules/@shopify/checkout-kit-react-native/android/src/main/java/com/shopify/reactnative/checkoutkit/ShopifyCheckoutKitModule.java b/platforms/react-native/modules/@shopify/checkout-kit-react-native/android/src/main/java/com/shopify/reactnative/checkoutkit/ShopifyCheckoutKitModule.java index 7cbd069f1..87fcb4940 100644 --- a/platforms/react-native/modules/@shopify/checkout-kit-react-native/android/src/main/java/com/shopify/reactnative/checkoutkit/ShopifyCheckoutKitModule.java +++ b/platforms/react-native/modules/@shopify/checkout-kit-react-native/android/src/main/java/com/shopify/reactnative/checkoutkit/ShopifyCheckoutKitModule.java @@ -159,8 +159,8 @@ private void emitPreloadStateChange(String requestId, PreloadState state) { event.put("statusCode", ((PreloadState.FailureReason.HttpError) reason).getStatusCode()); } else if (reason instanceof PreloadState.FailureReason.NavigationFailed) { event.put("reason", "navigationFailed"); - } else if (reason instanceof PreloadState.FailureReason.WebContentProcessTerminated) { - event.put("reason", "webContentProcessTerminated"); + } else if (reason instanceof PreloadState.FailureReason.WebContentUnavailable) { + event.put("reason", "webContentUnavailable"); } else if (reason instanceof PreloadState.FailureReason.ProtocolError) { event.put("reason", "protocolError"); } else { diff --git a/platforms/react-native/modules/@shopify/checkout-kit-react-native/api/checkout-kit-react-native.api.md b/platforms/react-native/modules/@shopify/checkout-kit-react-native/api/checkout-kit-react-native.api.md index d3b5dba6c..1ad253821 100644 --- a/platforms/react-native/modules/@shopify/checkout-kit-react-native/api/checkout-kit-react-native.api.md +++ b/platforms/react-native/modules/@shopify/checkout-kit-react-native/api/checkout-kit-react-native.api.md @@ -274,8 +274,7 @@ export enum LogLevel { export type PreloadFailureReason = | 'httpError' | 'navigationFailed' -| 'keepAliveLost' -| 'webContentProcessTerminated' +| 'webContentUnavailable' | 'protocolError' | 'unknown'; diff --git a/platforms/react-native/modules/@shopify/checkout-kit-react-native/ios/ShopifyCheckoutKit.swift b/platforms/react-native/modules/@shopify/checkout-kit-react-native/ios/ShopifyCheckoutKit.swift index 02d9d4db5..f1251316a 100644 --- a/platforms/react-native/modules/@shopify/checkout-kit-react-native/ios/ShopifyCheckoutKit.swift +++ b/platforms/react-native/modules/@shopify/checkout-kit-react-native/ios/ShopifyCheckoutKit.swift @@ -376,7 +376,7 @@ extension RCTShopifyCheckoutKit { event["type"] = "ready" case .expired: event["type"] = "expired" - case let .failed(reason): + case let .failed(reason, _): event["type"] = "failed" event.merge(serializePreloadFailure(reason)) { _, new in new } } @@ -390,16 +390,14 @@ extension RCTShopifyCheckoutKit { } } - private func serializePreloadFailure(_ reason: PreloadState.FailureReason) -> [String: Any] { + func serializePreloadFailure(_ reason: PreloadState.FailureReason) -> [String: Any] { switch reason { case let .httpError(statusCode): return ["reason": "httpError", "statusCode": statusCode] case .navigationFailed: return ["reason": "navigationFailed"] - case .keepAliveLost: - return ["reason": "keepAliveLost"] - case .webContentProcessTerminated: - return ["reason": "webContentProcessTerminated"] + case .webContentUnavailable: + return ["reason": "webContentUnavailable"] case .protocolError: return ["reason": "protocolError"] } diff --git a/platforms/react-native/modules/@shopify/checkout-kit-react-native/src/index.d.ts b/platforms/react-native/modules/@shopify/checkout-kit-react-native/src/index.d.ts index 418e74db5..3035540f7 100644 --- a/platforms/react-native/modules/@shopify/checkout-kit-react-native/src/index.d.ts +++ b/platforms/react-native/modules/@shopify/checkout-kit-react-native/src/index.d.ts @@ -218,8 +218,7 @@ export interface PresentCallbacks { export type PreloadFailureReason = | 'httpError' | 'navigationFailed' - | 'keepAliveLost' - | 'webContentProcessTerminated' + | 'webContentUnavailable' | 'protocolError' | 'unknown'; diff --git a/platforms/react-native/modules/@shopify/checkout-kit-react-native/src/preload.ts b/platforms/react-native/modules/@shopify/checkout-kit-react-native/src/preload.ts index 3529b727e..90e32e32f 100644 --- a/platforms/react-native/modules/@shopify/checkout-kit-react-native/src/preload.ts +++ b/platforms/react-native/modules/@shopify/checkout-kit-react-native/src/preload.ts @@ -16,8 +16,7 @@ type NativePreloadStateEvent = { const failureReasons = new Set([ 'httpError', 'navigationFailed', - 'keepAliveLost', - 'webContentProcessTerminated', + 'webContentUnavailable', 'protocolError', 'unknown', ]); diff --git a/platforms/react-native/modules/@shopify/checkout-kit-react-native/tests/index.test.ts b/platforms/react-native/modules/@shopify/checkout-kit-react-native/tests/index.test.ts index 0713e5753..6148c9889 100644 --- a/platforms/react-native/modules/@shopify/checkout-kit-react-native/tests/index.test.ts +++ b/platforms/react-native/modules/@shopify/checkout-kit-react-native/tests/index.test.ts @@ -300,7 +300,7 @@ describe('ShopifyCheckoutKit', () => { }); }); - it('normalizes terminated web content process preload failures', () => { + it('normalizes unavailable web content preload failures', () => { const onStateChange = jest.fn(); const instance = new ShopifyCheckout(); const subscription = instance.preload(checkoutUrl, {onStateChange}); @@ -309,17 +309,17 @@ describe('ShopifyCheckoutKit', () => { JSON.stringify({ requestId: preloadRequestId(), type: 'failed', - reason: 'webContentProcessTerminated', + reason: 'webContentUnavailable', }), ); expect(onStateChange).toHaveBeenCalledWith({ type: 'failed', - reason: 'webContentProcessTerminated', + reason: 'webContentUnavailable', }); expect(subscription.state).toEqual({ type: 'failed', - reason: 'webContentProcessTerminated', + reason: 'webContentUnavailable', }); }); diff --git a/platforms/react-native/sample/android/app/src/test/java/com/shopify/checkoutkit/reactnativedemo/ShopifyCheckoutKitModuleTest.java b/platforms/react-native/sample/android/app/src/test/java/com/shopify/checkoutkit/reactnativedemo/ShopifyCheckoutKitModuleTest.java index e41c3f174..adb78e178 100644 --- a/platforms/react-native/sample/android/app/src/test/java/com/shopify/checkoutkit/reactnativedemo/ShopifyCheckoutKitModuleTest.java +++ b/platforms/react-native/sample/android/app/src/test/java/com/shopify/checkoutkit/reactnativedemo/ShopifyCheckoutKitModuleTest.java @@ -173,7 +173,7 @@ public void testCanPreloadCheckout() { } @Test - public void testPreloadSerializesWebContentProcessTerminated() { + public void testPreloadSerializesWebContentUnavailable() { try (MockedStatic mockedShopifyCheckoutKit = Mockito .mockStatic(ShopifyCheckoutKit.class)) { String checkoutUrl = "https://shopify.com"; @@ -194,12 +194,13 @@ public void testPreloadSerializesWebContentProcessTerminated() { eq(mockComponentActivity), listenerCaptor.capture())); listenerCaptor.getValue().onStateChanged(new PreloadState.Failed( - PreloadState.FailureReason.WebContentProcessTerminated.INSTANCE)); + PreloadState.FailureReason.WebContentUnavailable.INSTANCE, + "Web content process terminated.")); assertThat(shopifyCheckoutKitModule.preloadStateEvent) .contains("\"requestId\":\"preload-request\"") .contains("\"type\":\"failed\"") - .contains("\"reason\":\"webContentProcessTerminated\""); + .contains("\"reason\":\"webContentUnavailable\""); } } diff --git a/platforms/react-native/test/rct-integration-app/RCTIntegrationAppTests/ShopifyCheckoutKitTests.swift b/platforms/react-native/test/rct-integration-app/RCTIntegrationAppTests/ShopifyCheckoutKitTests.swift index 003599d27..aecefa3cb 100644 --- a/platforms/react-native/test/rct-integration-app/RCTIntegrationAppTests/ShopifyCheckoutKitTests.swift +++ b/platforms/react-native/test/rct-integration-app/RCTIntegrationAppTests/ShopifyCheckoutKitTests.swift @@ -328,6 +328,12 @@ class ShopifyCheckoutKitTests: XCTestCase { XCTAssertEqual(result?["preloading"] as? Bool, false) } + func testSerializePreloadFailureMapsUnavailableWebContent() { + let result = shopifyCheckoutKit.serializePreloadFailure(.webContentUnavailable) + + XCTAssertEqual(result["reason"] as? String, "webContentUnavailable") + } + func testPreloadWithInvalidURLDoesNotRetainCheckoutSheet() { let preloadAttemptCompleted = expectation(description: "preload attempt completed")