Skip to content

Commit

Permalink
fix(e2e): fix tests after cleeng api update (#606)
Browse files Browse the repository at this point in the history
  • Loading branch information
AntonLantukh authored Sep 6, 2024
1 parent 2268447 commit 9062dba
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 3 deletions.
3 changes: 2 additions & 1 deletion packages/common/src/controllers/CheckoutController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import { useCheckoutStore } from '../stores/CheckoutStore';
import { useAccountStore } from '../stores/AccountStore';
import { FormValidationError } from '../errors/FormValidationError';
import { determineSwitchDirection } from '../utils/subscription';
import { findDefaultCardMethodId } from '../utils/payments';

@injectable()
export default class CheckoutController {
Expand Down Expand Up @@ -70,7 +71,7 @@ export default class CheckoutController {
const { customer } = getAccountInfo();

const paymentMethods = await this.getPaymentMethods();
const paymentMethodId = paymentMethods[0]?.id;
const paymentMethodId = parseInt(findDefaultCardMethodId(paymentMethods));

const createOrderArgs: CreateOrderArgs = {
offer,
Expand Down
3 changes: 3 additions & 0 deletions packages/common/src/utils/payments.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import type { PaymentMethod } from '@jwp/ott-common/types/checkout';

export const findDefaultCardMethodId = (paymentMethods: PaymentMethod[] | null) => paymentMethods?.find((el) => el.methodName === 'card')?.id?.toString() || '';
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import useForm from '@jwp/ott-hooks-react/src/useForm';
import { FormValidationError } from '@jwp/ott-common/src/errors/FormValidationError';
import { useTranslation } from 'react-i18next';
import { createURL } from '@jwp/ott-common/src/utils/urlFormatting';
import { findDefaultCardMethodId } from '@jwp/ott-common/src/utils/payments';

import CheckoutForm from '../../../components/CheckoutForm/CheckoutForm';
import LoadingOverlay from '../../../components/LoadingOverlay/LoadingOverlay';
Expand Down Expand Up @@ -53,7 +54,7 @@ const Checkout = () => {
handleChange,
handleSubmit,
} = useForm({
initialValues: { couponCode: '', paymentMethodId: paymentMethods?.[0]?.id?.toString() || '' },
initialValues: { couponCode: '', paymentMethodId: findDefaultCardMethodId(paymentMethods) },
onSubmit: ({ couponCode, paymentMethodId }) => {
setShowCouponCodeSuccess(false);

Expand Down Expand Up @@ -84,7 +85,7 @@ const Checkout = () => {
useEffect(() => {
if (!paymentMethods?.length) return;

setValue('paymentMethodId', paymentMethods[0].id.toString());
setValue('paymentMethodId', findDefaultCardMethodId(paymentMethods));
}, [paymentMethods, setValue]);

// clear after closing the checkout modal
Expand Down

0 comments on commit 9062dba

Please sign in to comment.