Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
public void present(String checkoutURL, ReadableArray subscribedMethods) {
releaseCheckoutListener();

Activity currentActivity = getCurrentActivity();

Check warning on line 79 in platforms/react-native/modules/@shopify/checkout-kit-react-native/android/src/main/java/com/shopify/reactnative/checkoutkit/ShopifyCheckoutKitModule.java

View workflow job for this annotation

GitHub Actions / React Native / Run Android Tests

[removal] getCurrentActivity() in ReactContextBaseJavaModule has been deprecated and marked for removal

Check warning on line 79 in platforms/react-native/modules/@shopify/checkout-kit-react-native/android/src/main/java/com/shopify/reactnative/checkoutkit/ShopifyCheckoutKitModule.java

View workflow job for this annotation

GitHub Actions / React Native / Run Android Tests

[removal] getCurrentActivity() in ReactContextBaseJavaModule has been deprecated and marked for removal

Check warning on line 79 in platforms/react-native/modules/@shopify/checkout-kit-react-native/android/src/main/java/com/shopify/reactnative/checkoutkit/ShopifyCheckoutKitModule.java

View workflow job for this annotation

GitHub Actions / React Native / Build Android Sample

[removal] getCurrentActivity() in ReactContextBaseJavaModule has been deprecated and marked for removal
if (currentActivity instanceof ComponentActivity) {
DispatchHandle dispatch = new DispatchHandle(json -> emitOnDispatch(json));
CustomCheckoutListener listener = new CustomCheckoutListener(dispatch);
Expand Down Expand Up @@ -115,7 +115,7 @@
public void preload(String checkoutURL, String requestId) {
releaseCheckoutPreload();

Activity currentActivity = getCurrentActivity();

Check warning on line 118 in platforms/react-native/modules/@shopify/checkout-kit-react-native/android/src/main/java/com/shopify/reactnative/checkoutkit/ShopifyCheckoutKitModule.java

View workflow job for this annotation

GitHub Actions / React Native / Run Android Tests

[removal] getCurrentActivity() in ReactContextBaseJavaModule has been deprecated and marked for removal

Check warning on line 118 in platforms/react-native/modules/@shopify/checkout-kit-react-native/android/src/main/java/com/shopify/reactnative/checkoutkit/ShopifyCheckoutKitModule.java

View workflow job for this annotation

GitHub Actions / React Native / Run Android Tests

[removal] getCurrentActivity() in ReactContextBaseJavaModule has been deprecated and marked for removal

Check warning on line 118 in platforms/react-native/modules/@shopify/checkout-kit-react-native/android/src/main/java/com/shopify/reactnative/checkoutkit/ShopifyCheckoutKitModule.java

View workflow job for this annotation

GitHub Actions / React Native / Build Android Sample

[removal] getCurrentActivity() in ReactContextBaseJavaModule has been deprecated and marked for removal
if (currentActivity instanceof ComponentActivity) {
checkoutPreload = ShopifyCheckoutKit.preload(
checkoutURL,
Expand Down Expand Up @@ -159,8 +159,8 @@
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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,7 @@ export enum LogLevel {
export type PreloadFailureReason =
| 'httpError'
| 'navigationFailed'
| 'keepAliveLost'
| 'webContentProcessTerminated'
| 'webContentUnavailable'
| 'protocolError'
| 'unknown';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
Expand All @@ -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"]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,7 @@ export interface PresentCallbacks {
export type PreloadFailureReason =
| 'httpError'
| 'navigationFailed'
| 'keepAliveLost'
| 'webContentProcessTerminated'
| 'webContentUnavailable'
| 'protocolError'
| 'unknown';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,7 @@ type NativePreloadStateEvent = {
const failureReasons = new Set<PreloadFailureReason>([
'httpError',
'navigationFailed',
'keepAliveLost',
'webContentProcessTerminated',
'webContentUnavailable',
'protocolError',
'unknown',
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Expand All @@ -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',
});
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ public void testCanPreloadCheckout() {
}

@Test
public void testPreloadSerializesWebContentProcessTerminated() {
public void testPreloadSerializesWebContentUnavailable() {
try (MockedStatic<ShopifyCheckoutKit> mockedShopifyCheckoutKit = Mockito
.mockStatic(ShopifyCheckoutKit.class)) {
String checkoutUrl = "https://shopify.com";
Expand All @@ -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\"");
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
Loading