@lookiero/checkout 10.0.0-beta.4 → 10.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/fake-dependencies/@lookiero/payments-front/index.d.ts +6 -8
- package/dist/fake-dependencies/@lookiero/payments-front/index.js +4 -7
- package/dist/index.d.ts +4 -3
- package/dist/src/ExpoRoot.js +13 -17
- package/dist/src/infrastructure/domain/checkoutBooking/react/useBlockCheckoutBooking.d.ts +1 -1
- package/dist/src/infrastructure/domain/checkoutBooking/react/useBlockCheckoutBooking.js +0 -2
- package/dist/src/infrastructure/projection/pricing/react/useViewPricingByCheckoutId.d.ts +1 -1
- package/dist/src/infrastructure/projection/pricing/react/useViewPricingByCheckoutId.js +1 -2
- package/dist/src/infrastructure/tracking/tracking.d.ts +2 -2
- package/dist/src/infrastructure/tracking/useTrackCheckout.d.ts +17 -10
- package/dist/src/infrastructure/tracking/useTrackCheckout.js +12 -27
- package/dist/src/infrastructure/ui/Root.d.ts +9 -7
- package/dist/src/infrastructure/ui/Root.js +3 -2
- package/dist/src/infrastructure/ui/hooks/usePaymentInstrumentEvents.d.ts +2 -3
- package/dist/src/infrastructure/ui/hooks/usePaymentInstrumentEvents.js +26 -17
- package/dist/src/infrastructure/ui/hooks/useStaticInfo.d.ts +3 -0
- package/dist/src/infrastructure/ui/hooks/useStaticInfo.js +7 -2
- package/dist/src/infrastructure/ui/i18n/i18n.d.ts +0 -1
- package/dist/src/infrastructure/ui/i18n/i18n.js +0 -1
- package/dist/src/infrastructure/ui/routing/CheckoutMiddleware.js +12 -1
- package/dist/src/infrastructure/ui/routing/Routing.d.ts +7 -5
- package/dist/src/infrastructure/ui/routing/Routing.js +11 -3
- package/dist/src/infrastructure/ui/routing/routes.d.ts +1 -0
- package/dist/src/infrastructure/ui/routing/routes.js +1 -0
- package/dist/src/infrastructure/ui/views/App.js +6 -5
- package/dist/src/infrastructure/ui/views/checkout/Checkout.d.ts +2 -7
- package/dist/src/infrastructure/ui/views/checkout/Checkout.js +9 -20
- package/dist/src/infrastructure/ui/views/checkout/Checkout.style.d.ts +0 -3
- package/dist/src/infrastructure/ui/views/checkout/Checkout.style.js +0 -3
- package/dist/src/infrastructure/ui/views/checkout/components/checkoutPaymentModal/CheckoutPaymentModal.js +1 -3
- package/dist/src/infrastructure/ui/views/checkout/components/paymentInstrument/PaymentInstrument.js +7 -7
- package/dist/src/infrastructure/ui/views/summary/Summary.js +1 -2
- package/dist/src/projection/customer/customer.d.ts +0 -2
- package/dist/src/projection/order/order.d.ts +1 -1
- package/dist/src/projection/subscription/subscription.d.ts +1 -1
- package/dist/src/version.d.ts +1 -1
- package/dist/src/version.js +1 -1
- package/fake-dependencies/@lookiero/payments-front/index.tsx +9 -32
- package/index.ts +4 -10
- package/package.json +4 -3
- package/src/ExpoRoot.tsx +37 -42
- package/src/infrastructure/domain/checkoutBooking/react/useBlockCheckoutBooking.ts +1 -4
- package/src/infrastructure/projection/pricing/react/useViewPricingByCheckoutId.ts +2 -3
- package/src/infrastructure/tracking/tracking.ts +2 -2
- package/src/infrastructure/tracking/useTrackCheckout.ts +56 -66
- package/src/infrastructure/ui/Root.tsx +14 -10
- package/src/infrastructure/ui/components/templates/header/itemHeader/ItemHeader.test.tsx +6 -0
- package/src/infrastructure/ui/components/templates/header/itemHeader/ItemHeader.tsx +0 -1
- package/src/infrastructure/ui/hooks/usePaymentInstrumentEvents.ts +60 -18
- package/src/infrastructure/ui/hooks/useStaticInfo.test.tsx +6 -1
- package/src/infrastructure/ui/hooks/useStaticInfo.tsx +13 -2
- package/src/infrastructure/ui/hooks/useSubmitCheckout.test.ts +297 -0
- package/src/infrastructure/ui/hooks/useSubmitCheckout.ts +169 -0
- package/src/infrastructure/ui/i18n/i18n.ts +0 -1
- package/src/infrastructure/ui/routing/CheckoutMiddleware.test.tsx +9 -1
- package/src/infrastructure/ui/routing/CheckoutMiddleware.tsx +15 -1
- package/src/infrastructure/ui/routing/Routing.tsx +29 -15
- package/src/infrastructure/ui/routing/routes.ts +1 -0
- package/src/infrastructure/ui/views/App.tsx +13 -5
- package/src/infrastructure/ui/views/checkout/Checkout.style.ts +0 -3
- package/src/infrastructure/ui/views/checkout/Checkout.test.tsx +43 -51
- package/src/infrastructure/ui/views/checkout/Checkout.tsx +13 -51
- package/src/infrastructure/ui/views/checkout/components/checkoutPaymentModal/CheckoutPaymentModal.test.tsx +134 -0
- package/src/infrastructure/ui/views/checkout/components/checkoutPaymentModal/CheckoutPaymentModal.tsx +124 -0
- package/src/infrastructure/ui/views/checkout/components/paymentInstrument/PaymentInstrument.tsx +8 -8
- package/src/infrastructure/ui/views/return/components/returnQuestionsForm/ReturnQuestionsForm.test.tsx +6 -0
- package/src/infrastructure/ui/views/summary/Summary.tsx +1 -1
- package/src/infrastructure/ui/views/summaryTabs/SummaryTabs.test.tsx +4 -1
- package/src/projection/customer/customer.ts +0 -2
- package/src/projection/order/order.ts +1 -1
- package/src/projection/subscription/subscription.ts +1 -1
- package/dist/public/public/assets/adaptive-icon.png +0 -0
- package/dist/public/public/assets/favicon.png +0 -0
- package/dist/public/public/assets/icon.png +0 -0
- package/dist/public/public/assets/splash.png +0 -0
- package/dist/public/public/images/not-found.png +0 -0
- package/dist/src/infrastructure/ui/hooks/useCheckoutFlow.d.ts +0 -26
- package/dist/src/infrastructure/ui/hooks/useCheckoutFlow.js +0 -127
- package/dist/src/infrastructure/ui/routing/useBasePath.d.ts +0 -8
- package/dist/src/infrastructure/ui/routing/useBasePath.js +0 -9
- package/src/infrastructure/ui/hooks/useCheckoutFlow.test.tsx +0 -302
- package/src/infrastructure/ui/hooks/useCheckoutFlow.tsx +0 -203
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import { ReactNode } from "react";
|
|
2
|
-
import { CheckoutProjection } from "../../../projection/checkout/checkout";
|
|
3
|
-
import { OrderProjection } from "../../../projection/order/order";
|
|
4
|
-
import { SubscriptionProjection } from "../../../projection/subscription/subscription";
|
|
5
|
-
type CheckoutFlowStatus = "idle" | "loading" | "success" | "error";
|
|
6
|
-
interface CheckoutFlowFunction {
|
|
7
|
-
(): Promise<void>;
|
|
8
|
-
}
|
|
9
|
-
type CheckoutFlowReturn = [
|
|
10
|
-
checkoutFlow: CheckoutFlowFunction,
|
|
11
|
-
checkoutFlowStatus: CheckoutFlowStatus,
|
|
12
|
-
paymentFlow: ReactNode
|
|
13
|
-
];
|
|
14
|
-
interface UseCheckoutFlowArgs {
|
|
15
|
-
readonly checkout: CheckoutProjection | undefined;
|
|
16
|
-
readonly order: OrderProjection;
|
|
17
|
-
readonly subscription: SubscriptionProjection;
|
|
18
|
-
readonly getAuthToken: () => Promise<string>;
|
|
19
|
-
readonly onSuccess: () => void;
|
|
20
|
-
}
|
|
21
|
-
interface UseCheckoutFlowFunction {
|
|
22
|
-
(args: UseCheckoutFlowArgs): CheckoutFlowReturn;
|
|
23
|
-
}
|
|
24
|
-
declare const useCheckoutFlow: UseCheckoutFlowFunction;
|
|
25
|
-
export type { CheckoutFlowStatus };
|
|
26
|
-
export { useCheckoutFlow };
|
|
@@ -1,127 +0,0 @@
|
|
|
1
|
-
import React, { useCallback, useEffect, useMemo, useRef, useState } from "react";
|
|
2
|
-
import { CommandStatus } from "@lookiero/messaging-react";
|
|
3
|
-
import { PaymentFlow, Section } from "@lookiero/payments-front";
|
|
4
|
-
import { useLogger } from "@lookiero/sty-psp-logging";
|
|
5
|
-
import { NotificationLevel, useCreateToastNotification } from "@lookiero/sty-psp-notifications";
|
|
6
|
-
import { viewCheckoutBookingById, } from "../../../projection/checkoutBooking/viewCheckoutBookingById";
|
|
7
|
-
import { MESSAGING_CONTEXT_ID } from "../../delivery/baseBootstrap";
|
|
8
|
-
import { useSubmitCheckout } from "../../domain/checkout/react/useSubmitCheckout";
|
|
9
|
-
import { useBlockCheckoutBooking } from "../../domain/checkoutBooking/react/useBlockCheckoutBooking";
|
|
10
|
-
import { useViewIsSizeChangeEnabledByCheckoutId } from "../../projection/checkout/react/useViewIsSizeChangeEnabledByCheckoutId";
|
|
11
|
-
import { useViewPaymentFlowPayloadByCheckoutId } from "../../projection/payment/react/useViewPaymentFlowPayloadByCheckoutId";
|
|
12
|
-
import { useViewPricingByCheckoutId } from "../../projection/pricing/react/useViewPricingByCheckoutId";
|
|
13
|
-
import { useTrackCheckout } from "../../tracking/useTrackCheckout";
|
|
14
|
-
import { I18nMessages } from "../i18n/i18n";
|
|
15
|
-
import { Routes } from "../routing/routes";
|
|
16
|
-
import { usePaymentInstrumentEvents } from "./usePaymentInstrumentEvents";
|
|
17
|
-
import { useQueryBus } from "./useQueryBus";
|
|
18
|
-
import { useStaticInfo } from "./useStaticInfo";
|
|
19
|
-
const useCheckoutFlow = ({ checkout: checkoutProjection, order: orderProjection, subscription: subscriptionProjection, getAuthToken, onSuccess, }) => {
|
|
20
|
-
const logger = useLogger();
|
|
21
|
-
const queryBus = useQueryBus();
|
|
22
|
-
const { customer: { customerId, country, segment, name, email }, basePath, } = useStaticInfo();
|
|
23
|
-
const paymentFlowRef = useRef(null);
|
|
24
|
-
const [paymentFlowPayload] = useViewPaymentFlowPayloadByCheckoutId({
|
|
25
|
-
checkoutId: checkoutProjection?.id,
|
|
26
|
-
});
|
|
27
|
-
const [sizeChangeEnabled] = useViewIsSizeChangeEnabledByCheckoutId({ checkoutId: checkoutProjection?.id });
|
|
28
|
-
const [pricing] = useViewPricingByCheckoutId({
|
|
29
|
-
checkoutId: checkoutProjection?.id,
|
|
30
|
-
queryOptions: { refetchOnMount: true },
|
|
31
|
-
});
|
|
32
|
-
const [submitCheckout, submitCheckoutStatus] = useSubmitCheckout({
|
|
33
|
-
checkoutId: checkoutProjection?.id,
|
|
34
|
-
logger,
|
|
35
|
-
});
|
|
36
|
-
const [blockCheckoutBooking, blockCheckoutBookingStatus] = useBlockCheckoutBooking({
|
|
37
|
-
checkoutBookingId: checkoutProjection?.checkoutBookingId,
|
|
38
|
-
logger,
|
|
39
|
-
});
|
|
40
|
-
const [createNotification] = useCreateToastNotification({ contextId: MESSAGING_CONTEXT_ID, logger });
|
|
41
|
-
const [checkoutBookingExpired, setCheckoutBookingExpired] = useState(false);
|
|
42
|
-
const [startLegacyBoxCheckoutStatus, setStartLegacyBoxCheckoutStatus] = useState("idle");
|
|
43
|
-
const [authToken, setAuthToken] = useState();
|
|
44
|
-
useEffect(() => {
|
|
45
|
-
const loadAuthToken = async () => setAuthToken(await getAuthToken());
|
|
46
|
-
loadAuthToken();
|
|
47
|
-
}, [getAuthToken]);
|
|
48
|
-
const trackCheckout = useTrackCheckout({
|
|
49
|
-
checkout: checkoutProjection,
|
|
50
|
-
order: orderProjection,
|
|
51
|
-
pricing,
|
|
52
|
-
subscription: subscriptionProjection,
|
|
53
|
-
userId: customerId,
|
|
54
|
-
country,
|
|
55
|
-
segment,
|
|
56
|
-
});
|
|
57
|
-
const checkoutFlow = useCallback(async () => {
|
|
58
|
-
try {
|
|
59
|
-
sizeChangeEnabled && (await blockCheckoutBooking());
|
|
60
|
-
}
|
|
61
|
-
catch (error) {
|
|
62
|
-
return;
|
|
63
|
-
}
|
|
64
|
-
if (checkoutProjection?.checkoutBookingId) {
|
|
65
|
-
const checkoutBooking = await queryBus(viewCheckoutBookingById({ checkoutBookingId: checkoutProjection?.checkoutBookingId }));
|
|
66
|
-
if (checkoutBooking?.isExpired) {
|
|
67
|
-
setCheckoutBookingExpired(true);
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
setStartLegacyBoxCheckoutStatus("loading");
|
|
72
|
-
paymentFlowRef.current?.startLegacyBoxCheckout({
|
|
73
|
-
...paymentFlowPayload,
|
|
74
|
-
userInformation: { email, name },
|
|
75
|
-
returnUrl: `${basePath}/${Routes.CHECKOUT}`,
|
|
76
|
-
});
|
|
77
|
-
}, [
|
|
78
|
-
checkoutProjection?.checkoutBookingId,
|
|
79
|
-
paymentFlowPayload,
|
|
80
|
-
email,
|
|
81
|
-
name,
|
|
82
|
-
basePath,
|
|
83
|
-
sizeChangeEnabled,
|
|
84
|
-
blockCheckoutBooking,
|
|
85
|
-
queryBus,
|
|
86
|
-
]);
|
|
87
|
-
const onPaymentSuccess = useCallback(async () => {
|
|
88
|
-
setStartLegacyBoxCheckoutStatus("success");
|
|
89
|
-
await submitCheckout();
|
|
90
|
-
createNotification({
|
|
91
|
-
bodyI18nKey: I18nMessages.CHECKOUT_TOAST_PAYMENT_SUCCESS,
|
|
92
|
-
level: NotificationLevel.SUCCESS,
|
|
93
|
-
});
|
|
94
|
-
trackCheckout();
|
|
95
|
-
onSuccess();
|
|
96
|
-
}, [createNotification, onSuccess, submitCheckout, trackCheckout]);
|
|
97
|
-
const onPaymentError = useCallback((payload) => {
|
|
98
|
-
setStartLegacyBoxCheckoutStatus("error");
|
|
99
|
-
createNotification({
|
|
100
|
-
bodyI18nKey: payload.metadata?.toaster?.id || I18nMessages.CHECKOUT_TOAST_PAYMENT_ERROR,
|
|
101
|
-
level: NotificationLevel.ERROR,
|
|
102
|
-
});
|
|
103
|
-
}, [createNotification]);
|
|
104
|
-
usePaymentInstrumentEvents({ onSuccess: onPaymentSuccess, onError: onPaymentError });
|
|
105
|
-
const checkoutFlowStatus = useMemo(() => {
|
|
106
|
-
if (blockCheckoutBookingStatus === CommandStatus.LOADING ||
|
|
107
|
-
startLegacyBoxCheckoutStatus === "loading" ||
|
|
108
|
-
submitCheckoutStatus === CommandStatus.LOADING) {
|
|
109
|
-
return "loading";
|
|
110
|
-
}
|
|
111
|
-
if (blockCheckoutBookingStatus === CommandStatus.SUCCESS &&
|
|
112
|
-
startLegacyBoxCheckoutStatus === "success" &&
|
|
113
|
-
submitCheckoutStatus === CommandStatus.SUCCESS) {
|
|
114
|
-
return "success";
|
|
115
|
-
}
|
|
116
|
-
if (blockCheckoutBookingStatus === CommandStatus.ERROR ||
|
|
117
|
-
startLegacyBoxCheckoutStatus === "error" ||
|
|
118
|
-
submitCheckoutStatus === CommandStatus.ERROR ||
|
|
119
|
-
checkoutBookingExpired) {
|
|
120
|
-
return "error";
|
|
121
|
-
}
|
|
122
|
-
return "idle";
|
|
123
|
-
}, [blockCheckoutBookingStatus, startLegacyBoxCheckoutStatus, submitCheckoutStatus, checkoutBookingExpired]);
|
|
124
|
-
const paymentFlow = useMemo(() => (authToken ? React.createElement(PaymentFlow, { ref: paymentFlowRef, section: Section.BOX_CHECKOUT, token: authToken }) : null), [authToken]);
|
|
125
|
-
return useMemo(() => [checkoutFlow, checkoutFlowStatus, paymentFlow], [checkoutFlow, paymentFlow, checkoutFlowStatus]);
|
|
126
|
-
};
|
|
127
|
-
export { useCheckoutFlow };
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import React, { createContext, useContext } from "react";
|
|
2
|
-
import invariant from "tiny-invariant";
|
|
3
|
-
const BasePathContext = createContext(null);
|
|
4
|
-
export const BasePathProvider = ({ basePath, children }) => (React.createElement(BasePathContext.Provider, { value: basePath }, children));
|
|
5
|
-
export const useBasePath = () => {
|
|
6
|
-
const basePath = useContext(BasePathContext);
|
|
7
|
-
invariant(basePath !== null, "Your are trying to use the useBasePath hook without wrapping your app with the <BasePathProvider>.");
|
|
8
|
-
return basePath;
|
|
9
|
-
};
|
|
@@ -1,302 +0,0 @@
|
|
|
1
|
-
import { act, render, renderHook, waitFor } from "@testing-library/react-native";
|
|
2
|
-
import React from "react";
|
|
3
|
-
import { CommandStatus, QueryStatus } from "@lookiero/messaging-react";
|
|
4
|
-
import { Country } from "@lookiero/sty-psp-locale";
|
|
5
|
-
import { NotificationLevel, useCreateToastNotification } from "@lookiero/sty-psp-notifications";
|
|
6
|
-
import { Segment } from "@lookiero/sty-psp-segment";
|
|
7
|
-
import { CheckoutItemStatus } from "../../../domain/checkoutItem/model/checkoutItem";
|
|
8
|
-
import { CheckoutBookingProjection } from "../../../projection/checkoutBooking/checkoutBooking";
|
|
9
|
-
import { OrderProjection } from "../../../projection/order/order";
|
|
10
|
-
import { SubscriptionProjection } from "../../../projection/subscription/subscription";
|
|
11
|
-
import { useSubmitCheckout } from "../../domain/checkout/react/useSubmitCheckout";
|
|
12
|
-
import { useBlockCheckoutBooking } from "../../domain/checkoutBooking/react/useBlockCheckoutBooking";
|
|
13
|
-
import { checkout } from "../../projection/checkout/checkout.mock";
|
|
14
|
-
import { useViewIsSizeChangeEnabledByCheckoutId } from "../../projection/checkout/react/useViewIsSizeChangeEnabledByCheckoutId";
|
|
15
|
-
import { paymentFlowPayload as mockPaymentFlowPayload } from "../../projection/payment/paymentFlowPayload.mock";
|
|
16
|
-
import { useViewPaymentFlowPayloadByCheckoutId } from "../../projection/payment/react/useViewPaymentFlowPayloadByCheckoutId";
|
|
17
|
-
import { pricing } from "../../projection/pricing/pricing.mock";
|
|
18
|
-
import { useViewPricingByCheckoutId } from "../../projection/pricing/react/useViewPricingByCheckoutId";
|
|
19
|
-
import { I18nMessages } from "../i18n/i18n";
|
|
20
|
-
import { Routes } from "../routing/routes";
|
|
21
|
-
import { useCheckoutFlow as sut } from "./useCheckoutFlow";
|
|
22
|
-
import { usePaymentInstrumentEvents } from "./usePaymentInstrumentEvents";
|
|
23
|
-
import { useQueryBus } from "./useQueryBus";
|
|
24
|
-
|
|
25
|
-
const getAuthToken = () => Promise.resolve("token");
|
|
26
|
-
const mockCheckout = checkout({
|
|
27
|
-
items: [
|
|
28
|
-
{ status: CheckoutItemStatus.KEPT },
|
|
29
|
-
{ status: CheckoutItemStatus.KEPT },
|
|
30
|
-
{ status: CheckoutItemStatus.KEPT },
|
|
31
|
-
{ status: CheckoutItemStatus.KEPT },
|
|
32
|
-
{ status: CheckoutItemStatus.RETURNED },
|
|
33
|
-
],
|
|
34
|
-
});
|
|
35
|
-
const order: OrderProjection = {
|
|
36
|
-
orderNumber: 12345,
|
|
37
|
-
isFirstOrder: false,
|
|
38
|
-
coupon: null,
|
|
39
|
-
};
|
|
40
|
-
const mockPricing = pricing();
|
|
41
|
-
const subscription: SubscriptionProjection = "o";
|
|
42
|
-
const customerId = "a8fff6d7-708c-41a7-b42a-58c5706d33df";
|
|
43
|
-
const basePath = "/checkout";
|
|
44
|
-
const country = Country.ES;
|
|
45
|
-
const email = "email@example.com";
|
|
46
|
-
const name = "Adèle Léonce Émilie";
|
|
47
|
-
const segment = Segment.WOMEN;
|
|
48
|
-
jest.mock("./useStaticInfo", () => ({
|
|
49
|
-
useStaticInfo: () => ({ customer: { customerId, country, segment, name, email }, basePath }),
|
|
50
|
-
}));
|
|
51
|
-
|
|
52
|
-
// const errorChargeStatuses = Object.values(ChargeStatus).filter((status) => status !== ChargeStatus.EXECUTED);
|
|
53
|
-
const mockStartLegacyBoxCheckout = jest.fn();
|
|
54
|
-
jest.mock("@lookiero/payments-front", () => {
|
|
55
|
-
// eslint-disable-next-line @typescript-eslint/no-var-requires
|
|
56
|
-
const { useImperativeHandle, forwardRef } = require("react");
|
|
57
|
-
|
|
58
|
-
return {
|
|
59
|
-
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
60
|
-
// @ts-ignore
|
|
61
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention, react/display-name
|
|
62
|
-
PaymentFlow: forwardRef((params, ref) => {
|
|
63
|
-
useImperativeHandle(ref, () => ({
|
|
64
|
-
startLegacyBoxCheckout: mockStartLegacyBoxCheckout,
|
|
65
|
-
}));
|
|
66
|
-
|
|
67
|
-
return null;
|
|
68
|
-
}),
|
|
69
|
-
Section: {
|
|
70
|
-
["BOX_CHECKOUT"]: "box-checkout",
|
|
71
|
-
},
|
|
72
|
-
};
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
jest.mock("@lookiero/sty-psp-logging", () => ({
|
|
76
|
-
useLogger: () => jest.fn(),
|
|
77
|
-
}));
|
|
78
|
-
|
|
79
|
-
jest.mock("@lookiero/sty-psp-notifications");
|
|
80
|
-
jest.mock("./useQueryBus");
|
|
81
|
-
jest.mock("../../domain/checkout/react/useSubmitCheckout");
|
|
82
|
-
jest.mock("../../domain/checkoutBooking/react/useBlockCheckoutBooking");
|
|
83
|
-
jest.mock("../../domain/checkout/react/useSubmitCheckout");
|
|
84
|
-
jest.mock("../../projection/payment/react/useViewPaymentFlowPayloadByCheckoutId");
|
|
85
|
-
jest.mock("../../projection/checkout/react/useViewIsSizeChangeEnabledByCheckoutId");
|
|
86
|
-
jest.mock("../../projection/pricing/react/useViewPricingByCheckoutId");
|
|
87
|
-
jest.mock("./usePaymentInstrumentEvents");
|
|
88
|
-
|
|
89
|
-
beforeEach(() => {
|
|
90
|
-
mockStartLegacyBoxCheckout.mockClear();
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
describe("useCheckoutFlow custom hook", () => {
|
|
94
|
-
test("successfully executes 'checkoutFlow'", async () => {
|
|
95
|
-
const mockBlockCheckoutBooking = jest.fn();
|
|
96
|
-
const mockSubmitCheckout = jest.fn();
|
|
97
|
-
const mockCreateToastNotification = jest.fn();
|
|
98
|
-
const mockOnSuccess = jest.fn();
|
|
99
|
-
|
|
100
|
-
(useQueryBus as jest.Mock).mockReturnValue(() => ({ isExpired: false }) as CheckoutBookingProjection);
|
|
101
|
-
(useBlockCheckoutBooking as jest.Mock).mockReturnValue([mockBlockCheckoutBooking, CommandStatus.SUCCESS]);
|
|
102
|
-
(useCreateToastNotification as jest.Mock).mockReturnValue([mockCreateToastNotification, CommandStatus.SUCCESS]);
|
|
103
|
-
(useViewPaymentFlowPayloadByCheckoutId as jest.Mock).mockReturnValue([mockPaymentFlowPayload, QueryStatus.SUCCESS]);
|
|
104
|
-
(useViewIsSizeChangeEnabledByCheckoutId as jest.Mock).mockReturnValue([true, QueryStatus.SUCCESS]);
|
|
105
|
-
(useViewPricingByCheckoutId as jest.Mock).mockReturnValue([mockPricing, QueryStatus.SUCCESS]);
|
|
106
|
-
(useSubmitCheckout as jest.Mock).mockReturnValue([mockSubmitCheckout, "success"]);
|
|
107
|
-
(usePaymentInstrumentEvents as jest.Mock).mockImplementation(({ onSuccess }) => {
|
|
108
|
-
setTimeout(() => onSuccess(), 1000);
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
const { result } = renderHook(() =>
|
|
112
|
-
sut({ checkout: mockCheckout, order, subscription, getAuthToken, onSuccess: mockOnSuccess }),
|
|
113
|
-
);
|
|
114
|
-
|
|
115
|
-
let checkoutFlow: () => void, status, paymentFlowComponent;
|
|
116
|
-
|
|
117
|
-
await waitFor(() => {
|
|
118
|
-
[checkoutFlow, , paymentFlowComponent] = result.current;
|
|
119
|
-
|
|
120
|
-
expect(paymentFlowComponent).not.toBeNull();
|
|
121
|
-
});
|
|
122
|
-
|
|
123
|
-
render(<>{paymentFlowComponent}</>);
|
|
124
|
-
|
|
125
|
-
await act(async () => {
|
|
126
|
-
await checkoutFlow();
|
|
127
|
-
});
|
|
128
|
-
|
|
129
|
-
await waitFor(() => {
|
|
130
|
-
[, status] = result.current;
|
|
131
|
-
|
|
132
|
-
expect(status).toBe("success");
|
|
133
|
-
expect(mockBlockCheckoutBooking).toHaveBeenCalled();
|
|
134
|
-
expect(mockStartLegacyBoxCheckout).toHaveBeenCalledWith(
|
|
135
|
-
expect.objectContaining({
|
|
136
|
-
...mockPaymentFlowPayload,
|
|
137
|
-
userInformation: { email, name },
|
|
138
|
-
returnUrl: `${basePath}/${Routes.CHECKOUT}`,
|
|
139
|
-
}),
|
|
140
|
-
);
|
|
141
|
-
expect(mockSubmitCheckout).toHaveBeenCalled();
|
|
142
|
-
expect(mockCreateToastNotification).toHaveBeenCalledWith({
|
|
143
|
-
bodyI18nKey: I18nMessages.CHECKOUT_TOAST_PAYMENT_SUCCESS,
|
|
144
|
-
level: NotificationLevel.SUCCESS,
|
|
145
|
-
});
|
|
146
|
-
expect(mockOnSuccess).toHaveBeenCalled();
|
|
147
|
-
});
|
|
148
|
-
});
|
|
149
|
-
|
|
150
|
-
test("does not call blockCheckoutBooking if sizeChange is not enabled", async () => {
|
|
151
|
-
const mockBlockCheckoutBooking = jest.fn();
|
|
152
|
-
const mockSubmitCheckout = jest.fn();
|
|
153
|
-
const mockCreateToastNotification = jest.fn();
|
|
154
|
-
const mockOnSuccess = jest.fn();
|
|
155
|
-
|
|
156
|
-
(useQueryBus as jest.Mock).mockReturnValue(() => ({ isExpired: false }) as CheckoutBookingProjection);
|
|
157
|
-
(useBlockCheckoutBooking as jest.Mock).mockReturnValue([mockBlockCheckoutBooking, CommandStatus.SUCCESS]);
|
|
158
|
-
(useCreateToastNotification as jest.Mock).mockReturnValue([mockCreateToastNotification, CommandStatus.SUCCESS]);
|
|
159
|
-
(useViewPaymentFlowPayloadByCheckoutId as jest.Mock).mockReturnValue([mockPaymentFlowPayload, QueryStatus.SUCCESS]);
|
|
160
|
-
(useViewIsSizeChangeEnabledByCheckoutId as jest.Mock).mockReturnValue([false, QueryStatus.SUCCESS]);
|
|
161
|
-
(useViewPricingByCheckoutId as jest.Mock).mockReturnValue([mockPricing, QueryStatus.SUCCESS]);
|
|
162
|
-
(useSubmitCheckout as jest.Mock).mockReturnValue([mockSubmitCheckout, "success"]);
|
|
163
|
-
(usePaymentInstrumentEvents as jest.Mock).mockImplementation(({ onSuccess }) => {
|
|
164
|
-
setTimeout(() => onSuccess(), 1000);
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
const { result } = renderHook(() =>
|
|
168
|
-
sut({ checkout: mockCheckout, order, subscription, getAuthToken, onSuccess: mockOnSuccess }),
|
|
169
|
-
);
|
|
170
|
-
|
|
171
|
-
let checkoutFlow: () => void, status, paymentFlowComponent;
|
|
172
|
-
|
|
173
|
-
await waitFor(() => {
|
|
174
|
-
[checkoutFlow, , paymentFlowComponent] = result.current;
|
|
175
|
-
|
|
176
|
-
expect(paymentFlowComponent).not.toBeNull();
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
render(<>{paymentFlowComponent}</>);
|
|
180
|
-
|
|
181
|
-
await act(async () => {
|
|
182
|
-
await checkoutFlow();
|
|
183
|
-
});
|
|
184
|
-
|
|
185
|
-
await waitFor(() => {
|
|
186
|
-
[, status] = result.current;
|
|
187
|
-
|
|
188
|
-
expect(status).toBe("success");
|
|
189
|
-
expect(mockBlockCheckoutBooking).not.toHaveBeenCalled();
|
|
190
|
-
expect(mockStartLegacyBoxCheckout).toHaveBeenCalledWith(
|
|
191
|
-
expect.objectContaining({
|
|
192
|
-
...mockPaymentFlowPayload,
|
|
193
|
-
userInformation: { email, name },
|
|
194
|
-
returnUrl: `${basePath}/${Routes.CHECKOUT}`,
|
|
195
|
-
}),
|
|
196
|
-
);
|
|
197
|
-
expect(mockSubmitCheckout).toHaveBeenCalled();
|
|
198
|
-
expect(mockCreateToastNotification).toHaveBeenCalledWith({
|
|
199
|
-
bodyI18nKey: I18nMessages.CHECKOUT_TOAST_PAYMENT_SUCCESS,
|
|
200
|
-
level: NotificationLevel.SUCCESS,
|
|
201
|
-
});
|
|
202
|
-
expect(mockOnSuccess).toHaveBeenCalled();
|
|
203
|
-
});
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
test("breaks execution and returns error as the status when blockCheckoutBooking fails", async () => {
|
|
207
|
-
const mockBlockCheckoutBooking = jest.fn().mockRejectedValue("error");
|
|
208
|
-
const mockSubmitCheckout = jest.fn();
|
|
209
|
-
const mockCreateToastNotification = jest.fn();
|
|
210
|
-
const mockOnSuccess = jest.fn();
|
|
211
|
-
|
|
212
|
-
(useQueryBus as jest.Mock).mockReturnValue(() => ({ isExpired: false }) as CheckoutBookingProjection);
|
|
213
|
-
(useBlockCheckoutBooking as jest.Mock).mockReturnValue([mockBlockCheckoutBooking, CommandStatus.ERROR]);
|
|
214
|
-
(useCreateToastNotification as jest.Mock).mockReturnValue([mockCreateToastNotification, CommandStatus.SUCCESS]);
|
|
215
|
-
(useViewPaymentFlowPayloadByCheckoutId as jest.Mock).mockReturnValue([mockPaymentFlowPayload, QueryStatus.SUCCESS]);
|
|
216
|
-
(useViewIsSizeChangeEnabledByCheckoutId as jest.Mock).mockReturnValue([true, QueryStatus.SUCCESS]);
|
|
217
|
-
(useViewPricingByCheckoutId as jest.Mock).mockReturnValue([mockPricing, QueryStatus.SUCCESS]);
|
|
218
|
-
(useSubmitCheckout as jest.Mock).mockReturnValue([mockSubmitCheckout, "success"]);
|
|
219
|
-
(usePaymentInstrumentEvents as jest.Mock).mockImplementation(({ onSuccess }) => {
|
|
220
|
-
setTimeout(() => onSuccess(), 1000);
|
|
221
|
-
});
|
|
222
|
-
|
|
223
|
-
const { result } = renderHook(() =>
|
|
224
|
-
sut({ checkout: mockCheckout, order, subscription, getAuthToken, onSuccess: mockOnSuccess }),
|
|
225
|
-
);
|
|
226
|
-
|
|
227
|
-
let checkoutFlow: () => void, status, paymentFlowComponent;
|
|
228
|
-
|
|
229
|
-
await waitFor(() => {
|
|
230
|
-
[checkoutFlow, , paymentFlowComponent] = result.current;
|
|
231
|
-
|
|
232
|
-
expect(paymentFlowComponent).not.toBeNull();
|
|
233
|
-
});
|
|
234
|
-
|
|
235
|
-
render(<>{paymentFlowComponent}</>);
|
|
236
|
-
|
|
237
|
-
await act(async () => {
|
|
238
|
-
await checkoutFlow();
|
|
239
|
-
});
|
|
240
|
-
|
|
241
|
-
await waitFor(() => {
|
|
242
|
-
[, status] = result.current;
|
|
243
|
-
|
|
244
|
-
expect(status).toBe("error");
|
|
245
|
-
expect(mockBlockCheckoutBooking).toHaveBeenCalled();
|
|
246
|
-
expect(mockStartLegacyBoxCheckout).not.toHaveBeenCalled();
|
|
247
|
-
expect(mockSubmitCheckout).not.toHaveBeenCalled();
|
|
248
|
-
expect(mockCreateToastNotification).not.toHaveBeenCalled();
|
|
249
|
-
expect(mockOnSuccess).not.toHaveBeenCalled();
|
|
250
|
-
});
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
test("shows a notification and returns error as the status when payment fails", async () => {
|
|
254
|
-
const mockBlockCheckoutBooking = jest.fn();
|
|
255
|
-
const mockSubmitCheckout = jest.fn();
|
|
256
|
-
const mockCreateToastNotification = jest.fn();
|
|
257
|
-
const mockOnSuccess = jest.fn();
|
|
258
|
-
|
|
259
|
-
(useQueryBus as jest.Mock).mockReturnValue(() => ({ isExpired: false }) as CheckoutBookingProjection);
|
|
260
|
-
(useBlockCheckoutBooking as jest.Mock).mockReturnValue([mockBlockCheckoutBooking, CommandStatus.SUCCESS]);
|
|
261
|
-
(useCreateToastNotification as jest.Mock).mockReturnValue([mockCreateToastNotification, CommandStatus.SUCCESS]);
|
|
262
|
-
(useViewPaymentFlowPayloadByCheckoutId as jest.Mock).mockReturnValue([mockPaymentFlowPayload, QueryStatus.SUCCESS]);
|
|
263
|
-
(useViewIsSizeChangeEnabledByCheckoutId as jest.Mock).mockReturnValue([true, QueryStatus.SUCCESS]);
|
|
264
|
-
(useViewPricingByCheckoutId as jest.Mock).mockReturnValue([mockPricing, QueryStatus.SUCCESS]);
|
|
265
|
-
(useSubmitCheckout as jest.Mock).mockReturnValue([mockSubmitCheckout, "success"]);
|
|
266
|
-
(usePaymentInstrumentEvents as jest.Mock).mockImplementation(({ onError }) => {
|
|
267
|
-
setTimeout(() => onError({ metadata: null }), 1000);
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
const { result } = renderHook(() =>
|
|
271
|
-
sut({ checkout: mockCheckout, order, subscription, getAuthToken, onSuccess: mockOnSuccess }),
|
|
272
|
-
);
|
|
273
|
-
|
|
274
|
-
let checkoutFlow: () => void, status, paymentFlowComponent;
|
|
275
|
-
|
|
276
|
-
await waitFor(() => {
|
|
277
|
-
[checkoutFlow, , paymentFlowComponent] = result.current;
|
|
278
|
-
|
|
279
|
-
expect(paymentFlowComponent).not.toBeNull();
|
|
280
|
-
});
|
|
281
|
-
|
|
282
|
-
render(<>{paymentFlowComponent}</>);
|
|
283
|
-
|
|
284
|
-
await act(async () => {
|
|
285
|
-
await checkoutFlow();
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
await waitFor(() => {
|
|
289
|
-
[, status] = result.current;
|
|
290
|
-
|
|
291
|
-
expect(status).toBe("error");
|
|
292
|
-
expect(mockBlockCheckoutBooking).toHaveBeenCalled();
|
|
293
|
-
expect(mockStartLegacyBoxCheckout).toHaveBeenCalled();
|
|
294
|
-
expect(mockSubmitCheckout).not.toHaveBeenCalled();
|
|
295
|
-
expect(mockCreateToastNotification).toHaveBeenCalledWith({
|
|
296
|
-
bodyI18nKey: I18nMessages.CHECKOUT_TOAST_PAYMENT_ERROR,
|
|
297
|
-
level: NotificationLevel.ERROR,
|
|
298
|
-
});
|
|
299
|
-
expect(mockOnSuccess).not.toHaveBeenCalled();
|
|
300
|
-
});
|
|
301
|
-
});
|
|
302
|
-
});
|