@@ -11,186 +11,193 @@ const {generateUserCredentials} = require('../../scripts/utils.js')
1111const { answerConsentTrackingForm} = require ( '../../scripts/pageHelpers.js' )
1212
1313const 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 (
22- '**/mobify/slas/private/shopper/auth/v1/organizations/*/oauth2/passwordless/login' ,
23- ( route ) => {
24- interceptedRequest = route . request ( )
25- route . continue ( )
26- }
27- )
28-
29- await page . goto ( config . EXTRA_FEATURES_E2E_RETAIL_APP_HOME + '/login' )
30- await answerConsentTrackingForm ( page )
31-
32- await page . locator ( '#email' ) . scrollIntoViewIfNeeded ( )
33- await page . fill ( '#email' , config . PWA_E2E_USER_EMAIL )
34-
35- await page . getByRole ( 'button' , { name : 'Continue' } ) . click ( )
36-
37- await page . waitForResponse (
38- '**/mobify/slas/private/shopper/auth/v1/organizations/*/oauth2/passwordless/login'
39- )
40-
41- // Verify the passwordless login request
42- expect ( interceptedRequest ) . toBeTruthy ( )
43- expect ( interceptedRequest . method ( ) ) . toBe ( 'POST' )
44-
45- let postData = interceptedRequest . postData ( )
46- expect ( postData ) . toBeTruthy ( )
47-
48- let params = new URLSearchParams ( postData )
49-
50- expect ( params . get ( 'user_id' ) ) . toBe ( config . PWA_E2E_USER_EMAIL )
51- expect ( params . get ( 'mode' ) ) . toBe ( 'email' )
52- expect ( params . get ( 'channel_id' ) ) . toBe ( config . EXTRA_FEATURES_E2E_RETAIL_APP_HOME_SITE )
5314
54- await page . route (
55- '**/mobify/slas/private/shopper/auth/v1/organizations/*/oauth2/passwordless/token' ,
56- ( route ) => {
57- interceptedRequest = route . request ( )
58- route . continue ( )
15+ describe ( 'Passwordless login' , ( ) => {
16+ /**
17+ * Test that a user can login with passwordless login. There is no programmatic way to check the email,
18+ * so we will check that the necessary API call is being made and expected UI is shown
19+ */
20+ test ( 'Verify passwordless login request' , async ( { page} ) => {
21+ let interceptedRequest = null
22+
23+ await page . route (
24+ '**/mobify/slas/private/shopper/auth/v1/organizations/*/oauth2/passwordless/login' ,
25+ ( route ) => {
26+ interceptedRequest = route . request ( )
27+ route . continue ( )
28+ }
29+ )
30+
31+ await page . goto ( config . EXTRA_FEATURES_E2E_RETAIL_APP_HOME + '/login' )
32+ await answerConsentTrackingForm ( page )
33+
34+ await page . locator ( '#email' ) . scrollIntoViewIfNeeded ( )
35+ await page . fill ( '#email' , config . PWA_E2E_USER_EMAIL )
36+
37+ await page . getByRole ( 'button' , { name : 'Continue' } ) . click ( )
38+
39+ await page . waitForResponse (
40+ '**/mobify/slas/private/shopper/auth/v1/organizations/*/oauth2/passwordless/login'
41+ )
42+
43+ // Verify the passwordless login request
44+ expect ( interceptedRequest ) . toBeTruthy ( )
45+ expect ( interceptedRequest . method ( ) ) . toBe ( 'POST' )
46+
47+ let postData = interceptedRequest . postData ( )
48+ expect ( postData ) . toBeTruthy ( )
49+
50+ let params = new URLSearchParams ( postData )
51+
52+ expect ( params . get ( 'user_id' ) ) . toBe ( config . PWA_E2E_USER_EMAIL )
53+ expect ( params . get ( 'mode' ) ) . toBe ( 'email' )
54+ 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 ] )
5972 }
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' )
84- } )
85-
86- test ( 'Verify password reset request' , async ( { page} ) => {
87- let interceptedRequest = null
88-
89- await page . route (
90- '**/mobify/slas/private/shopper/auth/v1/organizations/*/oauth2/password/reset' ,
91- ( route ) => {
92- interceptedRequest = route . request ( )
93- route . continue ( )
94- }
95- )
96-
97- await page . goto ( config . EXTRA_FEATURES_E2E_RETAIL_APP_HOME + '/login' )
98- await answerConsentTrackingForm ( page )
99-
100- await page . locator ( '#email' ) . scrollIntoViewIfNeeded ( )
101- await page . fill ( '#email' , config . PWA_E2E_USER_EMAIL )
102-
103- await page . getByRole ( 'button' , { name : 'Password' } ) . click ( )
104- await page . getByRole ( 'button' , { name : 'Forgot password?' } ) . click ( )
105-
106- await page . fill ( '#email' , config . PWA_E2E_USER_EMAIL )
107- await page . getByRole ( 'button' , { name : 'Reset Password' } ) . click ( )
108-
109- await page . waitForResponse (
110- '**/mobify/slas/private/shopper/auth/v1/organizations/*/oauth2/password/reset'
111- )
112-
113- expect ( interceptedRequest ) . toBeTruthy ( )
114- expect ( interceptedRequest . method ( ) ) . toBe ( 'POST' )
11573
116- const postData = interceptedRequest . postData ( )
117- expect ( postData ) . toBeTruthy ( )
118-
119- const params = new URLSearchParams ( postData )
120-
121- expect ( params . get ( 'user_id' ) ) . toBe ( config . PWA_E2E_USER_EMAIL )
122- expect ( params . get ( 'mode' ) ) . toBe ( 'email' )
123- expect ( params . get ( 'channel_id' ) ) . toBe ( config . EXTRA_FEATURES_E2E_RETAIL_APP_HOME_SITE )
124- expect ( params . get ( 'hint' ) ) . toBe ( 'cross_device' )
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' )
86+ } )
12587} )
12688
127- // Verify on the login UI that looks different when extra login features are not enabled
128- test ( 'Verify password reset request when extra login features are not enabled' , async ( { page} ) => {
129- let interceptedRequest = null
130-
131- await page . route (
132- '**/mobify/proxy/api/shopper/auth/v1/organizations/*/oauth2/password/reset' ,
133- ( route ) => {
134- interceptedRequest = route . request ( )
135- route . continue ( )
136- }
137- )
138-
139- await page . goto ( config . RETAIL_APP_HOME + '/login' )
140- await answerConsentTrackingForm ( page )
141-
142- await page . locator ( '#email' ) . scrollIntoViewIfNeeded ( )
143- await page . fill ( '#email' , config . PWA_E2E_USER_EMAIL )
144-
145- await page . getByRole ( 'button' , { name : 'Forgot password?' } ) . click ( )
146-
147- await page . waitForSelector ( 'form[data-testid="sf-auth-modal-form"] >> text=Reset Password' )
148- await page . fill ( 'form[data-testid="sf-auth-modal-form"] #email' , config . PWA_E2E_USER_EMAIL )
149- await page . getByRole ( 'button' , { name : / r e s e t p a s s w o r d / i} ) . click ( )
150- await page . waitForResponse (
151- '**/mobify/proxy/api/shopper/auth/v1/organizations/*/oauth2/password/reset'
152- )
153-
154- expect ( interceptedRequest ) . toBeTruthy ( )
155- expect ( interceptedRequest . method ( ) ) . toBe ( 'POST' )
156-
157- const postData = interceptedRequest . postData ( )
158- expect ( postData ) . toBeTruthy ( )
159-
160- const params = new URLSearchParams ( postData )
161-
162- expect ( params . get ( 'user_id' ) ) . toBe ( config . PWA_E2E_USER_EMAIL )
163- expect ( params . get ( 'mode' ) ) . toBe ( 'email' )
164- expect ( params . get ( 'channel_id' ) ) . toBe ( config . RETAIL_APP_HOME_SITE )
165- expect ( params . get ( 'hint' ) ) . toBe ( 'cross_device' )
166- } )
167-
168- test ( 'Verify password reset action request' , async ( { page} ) => {
169- let interceptedRequest = null
170- await page . route (
171- '**/mobify/slas/private/shopper/auth/v1/organizations/*/oauth2/password/action' ,
172- ( route ) => {
173- interceptedRequest = route . request ( )
174- route . continue ( )
175- }
176- )
177-
178- await page . goto (
179- config . EXTRA_FEATURES_E2E_RETAIL_APP_HOME +
180- `/reset-password-landing?token=1234567&email=${ GUEST_USER_CREDENTIALS . email } `
181- )
182- await answerConsentTrackingForm ( page )
183-
184- await page . fill ( '#password' , GUEST_USER_CREDENTIALS . password )
185- await page . fill ( '#confirmPassword' , GUEST_USER_CREDENTIALS . password )
186-
187- expect ( await page . inputValue ( '#password' ) ) . toBe ( GUEST_USER_CREDENTIALS . password )
188- expect ( await page . inputValue ( '#confirmPassword' ) ) . toBe ( GUEST_USER_CREDENTIALS . password )
189- await page . getByRole ( 'button' , { name : 'Reset Password' } ) . click ( )
190-
191- await page . waitForResponse (
192- '**/mobify/slas/private/shopper/auth/v1/organizations/*/oauth2/password/action'
193- )
89+ describe ( 'Password reset' , ( ) => {
90+ test ( 'Verify password reset request' , async ( { page} ) => {
91+ let interceptedRequest = null
92+
93+ await page . route (
94+ '**/mobify/slas/private/shopper/auth/v1/organizations/*/oauth2/password/reset' ,
95+ ( route ) => {
96+ interceptedRequest = route . request ( )
97+ route . continue ( )
98+ }
99+ )
100+
101+ await page . goto ( config . EXTRA_FEATURES_E2E_RETAIL_APP_HOME + '/login' )
102+ await answerConsentTrackingForm ( page )
103+
104+ await page . locator ( '#email' ) . scrollIntoViewIfNeeded ( )
105+ await page . fill ( '#email' , config . PWA_E2E_USER_EMAIL )
106+
107+ await page . getByRole ( 'button' , { name : 'Password' } ) . click ( )
108+ await page . getByRole ( 'button' , { name : 'Forgot password?' } ) . click ( )
109+
110+ await page . fill ( '#email' , config . PWA_E2E_USER_EMAIL )
111+ await page . getByRole ( 'button' , { name : 'Reset Password' } ) . click ( )
112+
113+ await page . waitForResponse (
114+ '**/mobify/slas/private/shopper/auth/v1/organizations/*/oauth2/password/reset'
115+ )
116+
117+ expect ( interceptedRequest ) . toBeTruthy ( )
118+ expect ( interceptedRequest . method ( ) ) . toBe ( 'POST' )
119+
120+ const postData = interceptedRequest . postData ( )
121+ expect ( postData ) . toBeTruthy ( )
122+
123+ const params = new URLSearchParams ( postData )
124+
125+ expect ( params . get ( 'user_id' ) ) . toBe ( config . PWA_E2E_USER_EMAIL )
126+ expect ( params . get ( 'mode' ) ) . toBe ( 'email' )
127+ expect ( params . get ( 'channel_id' ) ) . toBe ( config . EXTRA_FEATURES_E2E_RETAIL_APP_HOME_SITE )
128+ expect ( params . get ( 'hint' ) ) . toBe ( 'cross_device' )
129+ } )
130+
131+ // Verify on the login UI that looks different when extra login features are not enabled
132+ test ( 'Verify password reset request when extra login features are not enabled' , async ( {
133+ page
134+ } ) => {
135+ let interceptedRequest = null
136+
137+ await page . route (
138+ '**/mobify/proxy/api/shopper/auth/v1/organizations/*/oauth2/password/reset' ,
139+ ( route ) => {
140+ interceptedRequest = route . request ( )
141+ route . continue ( )
142+ }
143+ )
144+
145+ await page . goto ( config . RETAIL_APP_HOME + '/login' )
146+ await answerConsentTrackingForm ( page )
147+
148+ await page . locator ( '#email' ) . scrollIntoViewIfNeeded ( )
149+ await page . fill ( '#email' , config . PWA_E2E_USER_EMAIL )
150+
151+ await page . getByRole ( 'button' , { name : 'Forgot password?' } ) . click ( )
152+
153+ await page . waitForSelector ( 'form[data-testid="sf-auth-modal-form"] >> text=Reset Password' )
154+ await page . fill ( 'form[data-testid="sf-auth-modal-form"] #email' , config . PWA_E2E_USER_EMAIL )
155+ await page . getByRole ( 'button' , { name : / r e s e t p a s s w o r d / i} ) . click ( )
156+ await page . waitForResponse (
157+ '**/mobify/proxy/api/shopper/auth/v1/organizations/*/oauth2/password/reset'
158+ )
159+
160+ expect ( interceptedRequest ) . toBeTruthy ( )
161+ expect ( interceptedRequest . method ( ) ) . toBe ( 'POST' )
162+
163+ const postData = interceptedRequest . postData ( )
164+ expect ( postData ) . toBeTruthy ( )
165+
166+ const params = new URLSearchParams ( postData )
167+
168+ expect ( params . get ( 'user_id' ) ) . toBe ( config . PWA_E2E_USER_EMAIL )
169+ expect ( params . get ( 'mode' ) ) . toBe ( 'email' )
170+ expect ( params . get ( 'channel_id' ) ) . toBe ( config . RETAIL_APP_HOME_SITE )
171+ expect ( params . get ( 'hint' ) ) . toBe ( 'cross_device' )
172+ } )
173+
174+ test ( 'Verify password reset action request' , async ( { page} ) => {
175+ let interceptedRequest = null
176+ await page . route (
177+ '**/mobify/slas/private/shopper/auth/v1/organizations/*/oauth2/password/action' ,
178+ ( route ) => {
179+ interceptedRequest = route . request ( )
180+ route . continue ( )
181+ }
182+ )
183+
184+ await page . goto (
185+ config . EXTRA_FEATURES_E2E_RETAIL_APP_HOME +
186+ `/reset-password-landing?token=1234567&email=${ GUEST_USER_CREDENTIALS . email } `
187+ )
188+ await answerConsentTrackingForm ( page )
189+
190+ await page . fill ( '#password' , GUEST_USER_CREDENTIALS . password )
191+ await page . fill ( '#confirmPassword' , GUEST_USER_CREDENTIALS . password )
192+
193+ expect ( await page . inputValue ( '#password' ) ) . toBe ( GUEST_USER_CREDENTIALS . password )
194+ expect ( await page . inputValue ( '#confirmPassword' ) ) . toBe ( GUEST_USER_CREDENTIALS . password )
195+ await page . getByRole ( 'button' , { name : 'Reset Password' } ) . click ( )
196+
197+ await page . waitForResponse (
198+ '**/mobify/slas/private/shopper/auth/v1/organizations/*/oauth2/password/action'
199+ )
194200
195- expect ( interceptedRequest ) . toBeTruthy ( )
201+ expect ( interceptedRequest ) . toBeTruthy ( )
202+ } )
196203} )
0 commit comments