|
| 1 | +/* |
| 2 | + * Copyright (c) 2025, Salesforce, Inc. |
| 3 | + * All rights reserved. |
| 4 | + * SPDX-License-Identifier: BSD-3-Clause |
| 5 | + * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause |
| 6 | + */ |
| 7 | + |
| 8 | +const {test, expect} = require('@playwright/test') |
| 9 | +const config = require('../../config.js') |
| 10 | +const {generateUserCredentials} = require('../../scripts/utils.js') |
| 11 | +const {answerConsentTrackingForm} = require('../../scripts/pageHelpers.js') |
| 12 | + |
| 13 | +const GUEST_USER_CREDENTIALS = generateUserCredentials() |
| 14 | +/** |
| 15 | + * Test that a user can login with passwordless login on mobile. There is no programmatic way to check the email, |
| 16 | + * so we will check that the necessary API call is being made and expected UI is shown |
| 17 | + */ |
| 18 | +test('Verify passwordless login request', async ({page}) => { |
| 19 | + let interceptedRequest = null |
| 20 | + |
| 21 | + await page.route('**/mobify/slas/private/shopper/auth/v1/organizations/*/oauth2/passwordless/login', (route) => { |
| 22 | + interceptedRequest = route.request() |
| 23 | + route.continue() |
| 24 | + }) |
| 25 | + |
| 26 | + await page.goto(config.EXTRA_FEATURES_E2E_RETAIL_APP_HOME + '/login') |
| 27 | + await answerConsentTrackingForm(page) |
| 28 | + |
| 29 | + await page.locator('#email').scrollIntoViewIfNeeded() |
| 30 | + await page.fill('#email', config.PWA_E2E_USER_EMAIL) |
| 31 | + |
| 32 | + await page.getByRole('button', {name: 'Continue Securely'}).click() |
| 33 | + |
| 34 | + await page.waitForResponse('**/mobify/slas/private/shopper/auth/v1/organizations/*/oauth2/passwordless/login') |
| 35 | + |
| 36 | + expect(interceptedRequest).toBeTruthy() |
| 37 | + expect(interceptedRequest.method()).toBe('POST') |
| 38 | + |
| 39 | + const postData = interceptedRequest.postData() |
| 40 | + expect(postData).toBeTruthy() |
| 41 | + |
| 42 | + const params = new URLSearchParams(postData) |
| 43 | + |
| 44 | + expect(params.get('user_id')).toBe(config.PWA_E2E_USER_EMAIL) |
| 45 | + expect(params.get('mode')).toBe('callback') |
| 46 | + expect(params.get('channel_id')).toBe(config.EXTRA_FEATURES_E2E_RETAIL_APP_HOME_SITE) |
| 47 | + expect(params.get('callback_uri')).toMatch(/.*\/passwordless-login-callback$/) |
| 48 | +}) |
| 49 | + |
| 50 | +test('Verify password reset callback request', async ({page}) => { |
| 51 | + let interceptedRequest = null |
| 52 | + |
| 53 | + await page.route('**/mobify/slas/private/shopper/auth/v1/organizations/*/oauth2/password/reset', (route) => { |
| 54 | + interceptedRequest = route.request() |
| 55 | + route.continue() |
| 56 | + }) |
| 57 | + |
| 58 | + await page.goto(config.EXTRA_FEATURES_E2E_RETAIL_APP_HOME + '/login') |
| 59 | + await answerConsentTrackingForm(page) |
| 60 | + |
| 61 | + await page.locator('#email').scrollIntoViewIfNeeded() |
| 62 | + await page.fill('#email', config.PWA_E2E_USER_EMAIL) |
| 63 | + |
| 64 | + await page.getByRole('button', {name: 'Password'}).click() |
| 65 | + await page.getByRole('button', {name: 'Forgot password?'}).click() |
| 66 | + |
| 67 | + await page.fill('#email', config.PWA_E2E_USER_EMAIL) |
| 68 | + await page.getByRole('button', {name: 'Reset Password'}).click() |
| 69 | + |
| 70 | + await page.waitForResponse('**/mobify/slas/private/shopper/auth/v1/organizations/*/oauth2/password/reset') |
| 71 | + |
| 72 | + expect(interceptedRequest).toBeTruthy() |
| 73 | + expect(interceptedRequest.method()).toBe('POST') |
| 74 | + |
| 75 | + const postData = interceptedRequest.postData() |
| 76 | + expect(postData).toBeTruthy() |
| 77 | + |
| 78 | + const params = new URLSearchParams(postData) |
| 79 | + |
| 80 | + expect(params.get('user_id')).toBe(config.PWA_E2E_USER_EMAIL) |
| 81 | + expect(params.get('mode')).toBe('callback') |
| 82 | + expect(params.get('channel_id')).toBe(config.EXTRA_FEATURES_E2E_RETAIL_APP_HOME_SITE) |
| 83 | + expect(params.get('callback_uri')).toMatch(/.*\/reset-password-callback$/) |
| 84 | + expect(params.get('hint')).toBe('cross_device') |
| 85 | +}) |
| 86 | + |
| 87 | +// Verify on the login UI that looks different when extra login features are not enabled |
| 88 | +test('Verify password reset callback request when extra login features are not enabled', async ({page}) => { |
| 89 | + let interceptedRequest = null |
| 90 | + |
| 91 | + await page.route('**/mobify/proxy/api/shopper/auth/v1/organizations/*/oauth2/password/reset', (route) => { |
| 92 | + interceptedRequest = route.request() |
| 93 | + route.continue() |
| 94 | + }) |
| 95 | + |
| 96 | + await page.goto(config.RETAIL_APP_HOME + '/login') |
| 97 | + await answerConsentTrackingForm(page) |
| 98 | + |
| 99 | + await page.locator('#email').scrollIntoViewIfNeeded() |
| 100 | + await page.fill('#email', config.PWA_E2E_USER_EMAIL) |
| 101 | + |
| 102 | + await page.getByRole('button', {name: 'Forgot password?'}).click() |
| 103 | + |
| 104 | + await page.waitForSelector('form[data-testid="sf-auth-modal-form"] >> text=Reset Password') |
| 105 | + await page.fill('form[data-testid="sf-auth-modal-form"] #email', config.PWA_E2E_USER_EMAIL) |
| 106 | + await page.getByRole('button', {name: /reset password/i}).click() |
| 107 | + await page.waitForResponse('**/mobify/proxy/api/shopper/auth/v1/organizations/*/oauth2/password/reset') |
| 108 | + |
| 109 | + expect(interceptedRequest).toBeTruthy() |
| 110 | + expect(interceptedRequest.method()).toBe('POST') |
| 111 | + |
| 112 | + const postData = interceptedRequest.postData() |
| 113 | + expect(postData).toBeTruthy() |
| 114 | + |
| 115 | + const params = new URLSearchParams(postData) |
| 116 | + |
| 117 | + expect(params.get('user_id')).toBe(config.PWA_E2E_USER_EMAIL) |
| 118 | + expect(params.get('mode')).toBe('callback') |
| 119 | + expect(params.get('channel_id')).toBe(config.RETAIL_APP_HOME_SITE) |
| 120 | + expect(params.get('callback_uri')).toMatch(/.*\/reset-password-callback$/) |
| 121 | + expect(params.get('hint')).toBe('cross_device') |
| 122 | +}) |
| 123 | + |
| 124 | + |
| 125 | +test('Verify password reset request', async ({page}) => { |
| 126 | + let interceptedRequest = null |
| 127 | + await page.route('**/mobify/slas/private/shopper/auth/v1/organizations/*/oauth2/password/action', (route) => { |
| 128 | + interceptedRequest = route.request() |
| 129 | + route.continue() |
| 130 | + }) |
| 131 | + |
| 132 | + await page.goto(config.EXTRA_FEATURES_E2E_RETAIL_APP_HOME + `/reset-password-landing?token=1234567&email=${GUEST_USER_CREDENTIALS.email}`) |
| 133 | + await answerConsentTrackingForm(page) |
| 134 | + |
| 135 | + await page.fill('#password', GUEST_USER_CREDENTIALS.password) |
| 136 | + await page.fill('#confirmPassword', GUEST_USER_CREDENTIALS.password) |
| 137 | + |
| 138 | + expect(await page.inputValue('#password')).toBe(GUEST_USER_CREDENTIALS.password) |
| 139 | + expect(await page.inputValue('#confirmPassword')).toBe(GUEST_USER_CREDENTIALS.password) |
| 140 | + await page.getByRole('button', {name: 'Reset Password'}).click() |
| 141 | + |
| 142 | + await page.waitForResponse('**/mobify/slas/private/shopper/auth/v1/organizations/*/oauth2/password/action') |
| 143 | + |
| 144 | + expect(interceptedRequest).toBeTruthy() |
| 145 | +}) |
0 commit comments