Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(hosted-buttons): fix an issue where shipping callbacks would not throw #2427

Merged
merged 1 commit into from
Aug 21, 2024

Conversation

rjstires
Copy link
Contributor

The result of calling actions.reject was not being returned, causing the callback to not reject when the consumer passed an action.reject that rejects.

Description

The existing onShippingChange and onShippingOptionsChange callbacks used by hosted buttons do not return the result of calling the client application supplied action.reject method. This allows execution to continue and the callback resolves as if it were successful.

This causes the need for unsightly and hard to test error handling scenarios in the client application.

Why are we making these changes? Include references to any related Jira tasks or GitHub Issues

(ticket incoming) Supporting NCPS shipping callbacks.

Reproduction Steps (if applicable)

Passing { reject: message => Promise.reject(message) } when calling either callback from the client application and the callback will not reject. See original test and changes for confirmation.

Screenshots (if applicable)

Dependent Changes (if applicable)

Groups who should review (if applicable)

❤️ Thank you!

@rjstires rjstires requested a review from a team as a code owner August 21, 2024 14:31
@@ -636,10 +636,20 @@ describe("buildHostedButtonOnShippingAddressChange", () => {
status: 500,
})
);
// $FlowIssue
await onShippingAddressChange(data, actions);
Copy link
Contributor Author

@rjstires rjstires Aug 21, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test is titled, "throws error when shipping-options api doesn't return 200" yet in the original test the callback does not throw. The test only verifies that the actions.reject method was called.

Comment on lines +646 to +648
await expect(onShippingAddressChange(data, localActions)).rejects.toThrow(
errors.ADDRESS_ERROR
);
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We now verify that the callback actually throws its error, which allows for the error to propagate up to the calling client component as expected.

@rjstires rjstires force-pushed the defect/return-rejected-error branch from b448445 to b76c80f Compare August 21, 2024 14:43
@wsbrunson wsbrunson merged commit 8054bc1 into paypal:main Aug 21, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants