Skip to content

Commit c3c66bf

Browse files
committed
Add passwordless login OTP verification to desktop and mobile e2e tests
1 parent eb027e7 commit c3c66bf

File tree

2 files changed

+68
-4
lines changed

2 files changed

+68
-4
lines changed

e2e/tests/desktop/extra-features.spec.js

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,49 @@ test('Verify passwordless login request', async ({page}) => {
3838
'**/mobify/slas/private/shopper/auth/v1/organizations/*/oauth2/passwordless/login'
3939
)
4040

41+
// Verify the passwordless login request
4142
expect(interceptedRequest).toBeTruthy()
4243
expect(interceptedRequest.method()).toBe('POST')
4344

44-
const postData = interceptedRequest.postData()
45+
let postData = interceptedRequest.postData()
4546
expect(postData).toBeTruthy()
4647

47-
const params = new URLSearchParams(postData)
48+
let params = new URLSearchParams(postData)
4849

4950
expect(params.get('user_id')).toBe(config.PWA_E2E_USER_EMAIL)
5051
expect(params.get('mode')).toBe('email')
5152
expect(params.get('channel_id')).toBe(config.EXTRA_FEATURES_E2E_RETAIL_APP_HOME_SITE)
53+
54+
await page.route(
55+
'**/mobify/slas/private/shopper/auth/v1/organizations/*/oauth2/passwordless/token',
56+
(route) => {
57+
interceptedRequest = route.request()
58+
route.continue()
59+
}
60+
)
61+
62+
// Wait for OTP input fields to appear and fill the 8-digit code
63+
const otpCode = '12345678' // Replace with actual OTP code
64+
const otpInputs = page.locator('input[inputmode="numeric"][maxlength="1"]')
65+
await otpInputs.first().waitFor()
66+
67+
// Fill each input field with one digit
68+
for (let i = 0; i < 8; i++) {
69+
await otpInputs.nth(i).fill(otpCode[i])
70+
}
71+
72+
await page.waitForResponse(
73+
'**/mobify/slas/private/shopper/auth/v1/organizations/*/oauth2/passwordless/token'
74+
)
75+
76+
// Verify the passwordless login token request
77+
expect(interceptedRequest).toBeTruthy()
78+
expect(interceptedRequest.method()).toBe('POST')
79+
postData = interceptedRequest.postData()
80+
expect(postData).toBeTruthy()
81+
params = new URLSearchParams(postData)
82+
expect(params.get('pwdless_login_token')).toBe(otpCode)
83+
expect(params.get('hint')).toBe('pwdless_login')
5284
})
5385

5486
test('Verify password reset request', async ({page}) => {

e2e/tests/mobile/extra-features.spec.js

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,49 @@ test('Verify passwordless login request on mobile', async ({page}) => {
4040
'**/mobify/slas/private/shopper/auth/v1/organizations/*/oauth2/passwordless/login'
4141
)
4242

43+
// Verify the passwordless login request
4344
expect(interceptedRequest).toBeTruthy()
4445
expect(interceptedRequest.method()).toBe('POST')
4546

46-
const postData = interceptedRequest.postData()
47+
let postData = interceptedRequest.postData()
4748
expect(postData).toBeTruthy()
4849

49-
const params = new URLSearchParams(postData)
50+
let params = new URLSearchParams(postData)
5051

5152
expect(params.get('user_id')).toBe(config.PWA_E2E_USER_EMAIL)
5253
expect(params.get('mode')).toBe('email')
5354
expect(params.get('channel_id')).toBe(config.EXTRA_FEATURES_E2E_RETAIL_APP_HOME_SITE)
55+
56+
await page.route(
57+
'**/mobify/slas/private/shopper/auth/v1/organizations/*/oauth2/passwordless/token',
58+
(route) => {
59+
interceptedRequest = route.request()
60+
route.continue()
61+
}
62+
)
63+
64+
// Wait for OTP input fields to appear and fill the 8-digit code
65+
const otpCode = '12345678' // Replace with actual OTP code
66+
const otpInputs = page.locator('input[inputmode="numeric"][maxlength="1"]')
67+
await otpInputs.first().waitFor()
68+
69+
// Fill each input field with one digit
70+
for (let i = 0; i < 8; i++) {
71+
await otpInputs.nth(i).fill(otpCode[i])
72+
}
73+
74+
await page.waitForResponse(
75+
'**/mobify/slas/private/shopper/auth/v1/organizations/*/oauth2/passwordless/token'
76+
)
77+
78+
// Verify the passwordless login token request
79+
expect(interceptedRequest).toBeTruthy()
80+
expect(interceptedRequest.method()).toBe('POST')
81+
postData = interceptedRequest.postData()
82+
expect(postData).toBeTruthy()
83+
params = new URLSearchParams(postData)
84+
expect(params.get('pwdless_login_token')).toBe(otpCode)
85+
expect(params.get('hint')).toBe('pwdless_login')
5486
})
5587

5688
test('Verify password reset request on mobile (extra features enabled)', async ({page}) => {

0 commit comments

Comments
 (0)