-
Notifications
You must be signed in to change notification settings - Fork 214
Expand file tree
/
Copy pathlogin.spec.js
More file actions
120 lines (87 loc) · 4.99 KB
/
login.spec.js
File metadata and controls
120 lines (87 loc) · 4.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
/*
* Copyright (c) 2025, Salesforce, Inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
const {test, expect} = require('@playwright/test')
const config = require('../../config')
const {generateUserCredentials} = require('../../scripts/utils.js')
const {answerConsentTrackingForm} = require('../../scripts/pageHelpers.js')
const GUEST_USER_CREDENTIALS = generateUserCredentials()
/**
* Test that a user can login with passwordless login on mobile. There is no programmatic way to check the email,
* so we will check that the necessary API call is being made and expected UI is shown
*/
test('Verify passwordless login request on mobile', async ({page}) => {
let interceptedRequest = null
await page.route('**/mobify/slas/private/shopper/auth/v1/organizations/*/oauth2/passwordless/login', (route) => {
interceptedRequest = route.request()
route.continue()
})
await page.goto(config.MORE_LOGIN_OPTIONS_RETAIL_APP_HOME + '/login')
await answerConsentTrackingForm(page)
await page.locator('#email').scrollIntoViewIfNeeded()
await page.fill('#email', config.PWA_E2E_USER_EMAIL)
await page.getByRole('button', {name: 'Continue Securely'}).scrollIntoViewIfNeeded()
await page.getByRole('button', {name: 'Continue Securely'}).click()
await page.waitForResponse('**/mobify/slas/private/shopper/auth/v1/organizations/*/oauth2/passwordless/login')
expect(interceptedRequest).toBeTruthy()
expect(interceptedRequest.method()).toBe('POST')
const postData = interceptedRequest.postData()
expect(postData).toBeTruthy()
const params = new URLSearchParams(postData)
expect(params.get('user_id')).toBe(config.PWA_E2E_USER_EMAIL)
expect(params.get('mode')).toBe('callback')
expect(params.get('channel_id')).toBe('RefArchGlobal')
expect(params.get('callback_uri')).toMatch(/.*\/passwordless-login-callback$/)
})
test('Verify password reset callback request on mobile', async ({page}) => {
let interceptedRequest = null
await page.route('**/mobify/slas/private/shopper/auth/v1/organizations/*/oauth2/password/reset', (route) => {
interceptedRequest = route.request()
route.continue()
})
await page.goto(config.MORE_LOGIN_OPTIONS_RETAIL_APP_HOME + '/login')
await answerConsentTrackingForm(page)
await page.locator('#email').scrollIntoViewIfNeeded()
await page.fill('#email', config.PWA_E2E_USER_EMAIL)
await page.getByRole('button', {name: 'Password'}).scrollIntoViewIfNeeded()
await page.getByRole('button', {name: 'Password'}).click()
await page.getByRole('button', {name: 'Forgot password?'}).scrollIntoViewIfNeeded()
await page.getByRole('button', {name: 'Forgot password?'}).click()
await page.locator('#email').scrollIntoViewIfNeeded()
await page.fill('#email', config.PWA_E2E_USER_EMAIL)
await page.getByRole('button', {name: 'Reset Password'}).scrollIntoViewIfNeeded()
await page.getByRole('button', {name: 'Reset Password'}).click()
await page.waitForResponse('**/mobify/slas/private/shopper/auth/v1/organizations/*/oauth2/password/reset')
expect(interceptedRequest).toBeTruthy()
expect(interceptedRequest.method()).toBe('POST')
const postData = interceptedRequest.postData()
expect(postData).toBeTruthy()
const params = new URLSearchParams(postData)
expect(params.get('user_id')).toBe(config.PWA_E2E_USER_EMAIL)
expect(params.get('mode')).toBe('callback')
expect(params.get('channel_id')).toBe('RefArchGlobal')
expect(params.get('callback_uri')).toMatch(/.*\/reset-password-callback$/)
expect(params.get('hint')).toBe('cross_device')
})
test('Verify password reset request on mobile', async ({page}) => {
let interceptedRequest = null
await page.route('**/mobify/slas/private/shopper/auth/v1/organizations/*/oauth2/password/action', (route) => {
interceptedRequest = route.request()
route.continue()
})
await page.goto(config.MORE_LOGIN_OPTIONS_RETAIL_APP_HOME + `/reset-password-landing?token=1234567&email=${GUEST_USER_CREDENTIALS.email}`)
await answerConsentTrackingForm(page)
await page.locator('#password').scrollIntoViewIfNeeded()
await page.fill('#password', GUEST_USER_CREDENTIALS.password)
await page.locator('#confirmPassword').scrollIntoViewIfNeeded()
await page.fill('#confirmPassword', GUEST_USER_CREDENTIALS.password)
expect(await page.inputValue('#password')).toBe(GUEST_USER_CREDENTIALS.password)
expect(await page.inputValue('#confirmPassword')).toBe(GUEST_USER_CREDENTIALS.password)
await page.getByRole('button', {name: 'Reset Password'}).scrollIntoViewIfNeeded()
await page.getByRole('button', {name: 'Reset Password'}).click()
await page.waitForResponse('**/mobify/slas/private/shopper/auth/v1/organizations/*/oauth2/password/action')
expect(interceptedRequest).toBeTruthy()
})