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
43 changes: 40 additions & 3 deletions src/actions/__tests__/sponsor-cart-actions.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,18 @@ import thunk from "redux-thunk";
import flushPromises from "flush-promises";
import {
getRequest,
postRequest
postRequest,
putRequest
} from "openstack-uicore-foundation/lib/utils/actions";
import { payWithInvoice } from "../sponsor-cart-actions";
import { payWithInvoice, updatePaymentIntent } from "../sponsor-cart-actions";
import * as methods from "../../utils/methods";

jest.mock("openstack-uicore-foundation/lib/utils/actions", () => ({
__esModule: true,
...jest.requireActual("openstack-uicore-foundation/lib/utils/actions"),
getRequest: jest.fn(),
postRequest: jest.fn()
postRequest: jest.fn(),
putRequest: jest.fn()
}));

describe("payWithInvoice", () => {
Expand Down Expand Up @@ -81,3 +83,38 @@ describe("payWithInvoice", () => {
expect(cartUrl).toContain("/sponsors/456/carts/current");
});
});

describe("updatePaymentIntent", () => {
const mockStore = configureStore([thunk]);

beforeEach(() => {
jest.clearAllMocks();
window.PURCHASES_API_URL = "https://purchases.example.com";
jest.spyOn(methods, "getAccessTokenSafely").mockResolvedValue("TOKEN");
});

afterEach(() => {
jest.restoreAllMocks();
delete window.PURCHASES_API_URL;
});

it("resolves when the reprice fails, so a payment method change never leaks an unhandled rejection", async () => {
putRequest.mockImplementation(
() => () => () => Promise.reject(new Error("412"))
);
const store = mockStore({
currentSummitState: { currentSummit: { id: 1 } },
currentSponsorState: { entity: { id: 123 } },
sponsorPageCartListState: { cart: { id: 55 }, paymentIntent: { id: 230 } }
});

await expect(
store.dispatch(updatePaymentIntent("us_bank_account"))
).resolves.toBeUndefined();
const [, , url, payload] = putRequest.mock.calls[0];
expect(url).toBe(
"https://purchases.example.com/api/v1/summits/1/sponsors/123/payments/230/reprice"
);
expect(payload).toEqual({ payment_method: "us_bank_account", cart_id: 55 });
});
});
2 changes: 1 addition & 1 deletion src/actions/sponsor-cart-actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -643,7 +643,7 @@ export const updatePaymentIntent =
`${window.PURCHASES_API_URL}/api/v1/summits/${currentSummit.id}/sponsors/${sponsor.id}/payments/${paymentIntent?.id}/reprice`,
payload,
snackbarErrorHandler
)(params)(dispatch);
)(params)(dispatch).catch(() => {}); // error already shown by snackbarErrorHandler
};

export const confirmPayment = () => async (dispatch, getState) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import React from "react";
import { act, screen } from "@testing-library/react";
import userEvent from "@testing-library/user-event";
import flushPromises from "flush-promises";
import StripePayment from "openstack-uicore-foundation/lib/components/mui/stripe-payment";
import { renderWithRedux } from "../../../../../../../utils/test-utils";
import PaymentView from "../payment-view";
import { payWithInvoice } from "../../../../../../../actions/sponsor-cart-actions";
Expand Down Expand Up @@ -52,7 +53,7 @@ jest.mock(
"openstack-uicore-foundation/lib/components/mui/stripe-payment",
() => ({
__esModule: true,
default: () => <div data-testid="stripe-payment" />
default: jest.fn(() => <div data-testid="stripe-payment" />)
})
);

Expand Down Expand Up @@ -159,3 +160,20 @@ describe("PaymentView - Pay with invoice instead", () => {
expect(history.push).not.toHaveBeenCalled();
});
});

describe("PaymentView - Stripe payment form", () => {
beforeEach(() => {
jest.clearAllMocks();
});

it("hides Link so the admin's own saved card is never offered", () => {
renderPaymentView();

expect(StripePayment).toHaveBeenCalledWith(
expect.objectContaining({
paymentOptions: { wallets: { link: "never" } }
}),
expect.anything()
);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,8 @@ const PaymentView = ({
showBilling
redirectUrl={redirectUrl}
stripeFormTitle={false}
// the admin pays for the sponsor, so never offer the admin's own saved Link card
paymentOptions={{ wallets: { link: "never" } }}
updatePaymentIntent={updatePaymentIntent}
onPaymentSuccess={handlePaymentSuccess}
onPaymentError={handlePaymentError}
Expand Down
Loading