@@ -11,7 +11,8 @@ import userEvent from '@testing-library/user-event'
1111import {
1212 renderWithProviders ,
1313 createPathWithDefaults ,
14- guestToken
14+ guestToken ,
15+ registerUserToken
1516} from '@salesforce/retail-react-app/app/utils/test-utils'
1617import { AuthModal , useAuthModal } from '@salesforce/retail-react-app/app/hooks/use-auth-modal'
1718import { BrowserRouter as Router , Route } from 'react-router-dom'
@@ -20,6 +21,12 @@ import {rest} from 'msw'
2021import { mockedRegisteredCustomer } from '@salesforce/retail-react-app/app/mocks/mock-data'
2122import * as ReactHookForm from 'react-hook-form'
2223import { AuthHelpers } from '@salesforce/commerce-sdk-react'
24+ import mockConfig from '@salesforce/retail-react-app/config/mocks/default'
25+ import { getConfig } from '@salesforce/pwa-kit-runtime/utils/ssr-config'
26+
27+ jest . mock ( '@salesforce/pwa-kit-runtime/utils/ssr-config' , ( ) => ( {
28+ getConfig : jest . fn ( )
29+ } ) )
2330
2431jest . setTimeout ( 60000 )
2532
@@ -89,6 +96,8 @@ MockedComponent.propTypes = {
8996// Set up and clean up
9097beforeEach ( ( ) => {
9198 authModal = undefined
99+ // Set default config mock (passkey enabled by default in mockConfig)
100+ getConfig . mockReturnValue ( mockConfig )
92101 global . server . use (
93102 rest . post ( '*/customers' , ( req , res , ctx ) => {
94103 return res ( ctx . delay ( 0 ) , ctx . status ( 200 ) , ctx . json ( mockRegisteredCustomer ) )
@@ -225,6 +234,17 @@ describe('Passwordless enabled', () => {
225234 pathname : '/' ,
226235 origin : 'https://example.com'
227236 } )
237+ // Disable passkey to test passwordless in isolation
238+ getConfig . mockReturnValue ( {
239+ ...mockConfig ,
240+ app : {
241+ ...mockConfig . app ,
242+ login : {
243+ ...mockConfig . app . login ,
244+ passkey : { enabled : false }
245+ }
246+ }
247+ } )
228248 const { user} = renderWithProviders ( < MockedComponent isPasswordlessEnabled = { true } /> )
229249 const validEmail = 'test@salesforce.com'
230250
@@ -274,6 +294,17 @@ describe('Passwordless enabled', () => {
274294 pathname : '/' ,
275295 origin : 'https://example.com'
276296 } )
297+ // Disable passkey to test passwordless in isolation
298+ getConfig . mockReturnValue ( {
299+ ...mockConfig ,
300+ app : {
301+ ...mockConfig . app ,
302+ login : {
303+ ...mockConfig . app . login ,
304+ passkey : { enabled : false }
305+ }
306+ }
307+ } )
277308 const { user} = renderWithProviders ( < MockedComponent isPasswordlessEnabled = { true } /> )
278309 const validEmail = 'test@salesforce.com'
279310
@@ -673,11 +704,14 @@ describe('Passkey login', () => {
673704 await waitFor (
674705 ( ) => {
675706 expect ( mockStartWebauthnAuthentication ) . toHaveBeenCalled ( )
676- expect ( mockFinishWebauthnAuthentication ) . toHaveBeenCalledWith ( {
677- credential : expect . objectContaining ( {
678- id : 'mock-credential-id'
707+ expect ( mockFinishWebauthnAuthentication ) . toHaveBeenCalledWith (
708+ expect . objectContaining ( {
709+ credential : expect . objectContaining ( {
710+ id : 'mock-credential-id'
711+ } ) ,
712+ usid : expect . any ( String )
679713 } )
680- } )
714+ )
681715 } ,
682716 { timeout : 5000 }
683717 )
@@ -797,6 +831,12 @@ describe('Passkey login', () => {
797831 }
798832 }
799833
834+ // Override getConfig to return config with passkey disabled
835+ getConfig . mockReturnValue ( {
836+ ...mockConfig ,
837+ app : mockAppConfig
838+ } )
839+
800840 const { user} = renderWithProviders ( < MockedComponent /> , {
801841 wrapperProps : {
802842 appConfig : mockAppConfig ,
0 commit comments