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(e2e): fix tests after cleeng api update #606

Merged
merged 1 commit into from
Sep 6, 2024
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
fix(e2e): fix tests after cleeng api update
  • Loading branch information
AntonLantukh committed Sep 6, 2024
commit 97dfad801e3dc8a51193bf7431d947773774f28d
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
Loading