diff --git a/packages/template-retail-react-app/app/pages/checkout-one-click/partials/one-click-contact-info.jsx b/packages/template-retail-react-app/app/pages/checkout-one-click/partials/one-click-contact-info.jsx index c832d0f8cf..5b73bbd3e6 100644 --- a/packages/template-retail-react-app/app/pages/checkout-one-click/partials/one-click-contact-info.jsx +++ b/packages/template-retail-react-app/app/pages/checkout-one-click/partials/one-click-contact-info.jsx @@ -236,7 +236,6 @@ const ContactInfo = ({isSocialEnabled = false, idps = [], onRegisteredUserChoseG // Handle OTP verification const handleOtpVerification = async (otpCode) => { - let basketId try { // Prevent post-auth recovery effect from also attempting merge in this flow hasAttemptedRecoveryRef.current = true @@ -244,6 +243,7 @@ const ContactInfo = ({isSocialEnabled = false, idps = [], onRegisteredUserChoseG // Successful OTP verification - user is now logged in const hasBasketItem = basket.productItems?.length > 0 + let basketId if (hasBasketItem) { // Mirror legacy checkout flow header and await completion const merged = await mergeBasket.mutateAsync({ @@ -254,20 +254,20 @@ const ContactInfo = ({isSocialEnabled = false, idps = [], onRegisteredUserChoseG createDestinationBasket: true } }) - const mergedBasketId = merged?.basketId - const refreshedBasketId = await currentBasketQuery.refetch() - basketId = refreshedBasketId?.data?.basketId || mergedBasketId || basket.basketId + basketId = merged?.basketId || basket.basketId } // Update basket with email after successful OTP verification const email = form.getValues('email') - try { - await updateCustomerForBasket.mutateAsync({ - parameters: {basketId: basketId}, - body: {email} - }) - } catch (error) { - setError(error.message) + if (basketId && email) { + try { + await updateCustomerForBasket.mutateAsync({ + parameters: {basketId: basketId}, + body: {email} + }) + } catch (error) { + setError(error.message) + } } // Reset guest checkout flag since user is now logged in diff --git a/packages/template-retail-react-app/app/pages/checkout-one-click/partials/one-click-contact-info.test.js b/packages/template-retail-react-app/app/pages/checkout-one-click/partials/one-click-contact-info.test.js index af373d7876..5b572294db 100644 --- a/packages/template-retail-react-app/app/pages/checkout-one-click/partials/one-click-contact-info.test.js +++ b/packages/template-retail-react-app/app/pages/checkout-one-click/partials/one-click-contact-info.test.js @@ -182,7 +182,7 @@ describe('ContactInfo Component', () => { await user.click(emailInput) await user.tab() - expect(screen.getAllByText('Please enter your email address.')).toHaveLength(2) + expect(screen.getByText('Please enter your email address.')).toBeInTheDocument() }) test('validates email format on form submission', async () => { @@ -442,10 +442,9 @@ describe('ContactInfo Component', () => { await screen.findByTestId('otp-verify') await user.click(screen.getByTestId('otp-verify')) - // Assert: merge called, refetch performed, email updated with merged id + // Assert: merge called, email updated with merged id await waitFor(() => { expect(mockMergeBasket.mutateAsync).toHaveBeenCalled() - expect(refetchSpy).toHaveBeenCalled() expect(mockUpdateCustomerForBasket.mutateAsync).toHaveBeenCalledWith({ parameters: {basketId: mergedId}, body: {email: 'test@salesforce.com'}