Skip to content

Commit 3737c6e

Browse files
committed
Use endsWith() to match passwordless login landing path and add test for localized paths
1 parent 465b813 commit 3737c6e

File tree

2 files changed

+37
-2
lines changed

2 files changed

+37
-2
lines changed

packages/template-retail-react-app/app/pages/login/index.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ const Login = ({initialView = LOGIN_VIEW}) => {
151151
// executing a passwordless login attempt using the token. The process waits for the
152152
// customer baskets to be loaded to guarantee proper basket merging.
153153
useEffect(() => {
154-
if (path === PASSWORDLESS_LOGIN_LANDING_PATH && isSuccessCustomerBaskets) {
154+
if (path.endsWith(PASSWORDLESS_LOGIN_LANDING_PATH) && isSuccessCustomerBaskets) {
155155
const token = decodeURIComponent(queryParams.get('token'))
156156
if (queryParams.get('redirect_url')) {
157157
setRedirectPath(decodeURIComponent(queryParams.get('redirect_url')))

packages/template-retail-react-app/app/pages/login/passwordless-landing.test.js

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,13 @@ const MockedComponent = () => {
4545
)
4646
}
4747

48+
let mockRouteMatchPath = '/passwordless-login-landing'
49+
4850
jest.mock('react-router', () => {
4951
return {
5052
...jest.requireActual('react-router'),
5153
useRouteMatch: () => {
52-
return {path: '/passwordless-login-landing'}
54+
return {path: mockRouteMatchPath}
5355
}
5456
}
5557
})
@@ -72,6 +74,7 @@ jest.mock('@salesforce/commerce-sdk-react', () => {
7274

7375
// Set up and clean up
7476
beforeEach(() => {
77+
mockRouteMatchPath = '/passwordless-login-landing'
7578
global.server.use(
7679
rest.post('*/customers', (req, res, ctx) => {
7780
return res(ctx.delay(0), ctx.status(200), ctx.json(mockedRegisteredCustomer))
@@ -94,6 +97,7 @@ beforeEach(() => {
9497
})
9598
afterEach(() => {
9699
jest.resetModules()
100+
jest.clearAllMocks()
97101
})
98102

99103
describe('Passwordless landing tests', function () {
@@ -149,6 +153,37 @@ describe('Passwordless landing tests', function () {
149153

150154
await waitFor(() => {
151155
expect(window.location.pathname).toBe('/uk/en-GB/womens-tops')
156+
157+
})
158+
})
159+
160+
test('redirects to account page with correct locale when path includes locale', async () => {
161+
const token = '12345678'
162+
const localizedPath = '/us/en-CA/passwordless-login-landing'
163+
mockRouteMatchPath = localizedPath
164+
165+
window.history.pushState(
166+
{},
167+
'Passwordless Login Landing',
168+
`${localizedPath}?token=${token}`
169+
)
170+
171+
renderWithProviders(<MockedComponent />, {
172+
wrapperProps: {
173+
siteAlias: 'us',
174+
locale: {id: 'en-CA'},
175+
appConfig: mockConfig.app
176+
}
177+
})
178+
179+
expect(
180+
mockAuthHelperFunctions[AuthHelpers.LoginPasswordlessUser].mutateAsync
181+
).toHaveBeenCalledWith({
182+
pwdlessLoginToken: token
183+
})
184+
185+
await waitFor(() => {
186+
expect(window.location.pathname).toBe('/us/en-CA/account')
152187
})
153188
})
154189
})

0 commit comments

Comments
 (0)