forked from fastapi/full-stack-fastapi-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreset-password.spec.ts
125 lines (94 loc) · 3.88 KB
/
reset-password.spec.ts
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
121
122
123
124
125
import { expect, test } from "@playwright/test"
import { findLastEmail } from "./utils/mailcatcher"
import { randomEmail, randomPassword } from "./utils/random"
import { logInUser, signUpNewUser } from "./utils/user"
test.use({ storageState: { cookies: [], origins: [] } })
test("Password Recovery title is visible", async ({ page }) => {
await page.goto("/recover-password")
await expect(
page.getByRole("heading", { name: "Password Recovery" }),
).toBeVisible()
})
test("Input is visible, empty and editable", async ({ page }) => {
await page.goto("/recover-password")
await expect(page.getByPlaceholder("Email")).toBeVisible()
await expect(page.getByPlaceholder("Email")).toHaveText("")
await expect(page.getByPlaceholder("Email")).toBeEditable()
})
test("Continue button is visible", async ({ page }) => {
await page.goto("/recover-password")
await expect(page.getByRole("button", { name: "Continue" })).toBeVisible()
})
test("User can reset password successfully using the link", async ({
page,
request,
}) => {
const fullName = "Test User"
const email = randomEmail()
const password = randomPassword()
const newPassword = randomPassword()
// Sign up a new user
await signUpNewUser(page, fullName, email, password)
await page.goto("/recover-password")
await page.getByPlaceholder("Email").fill(email)
await page.getByRole("button", { name: "Continue" }).click()
const emailData = await findLastEmail({
request,
filter: (e) => e.recipients.includes(`<${email}>`),
timeout: 5000,
})
await page.goto(
`${process.env.MAILCATCHER_HOST}/messages/${emailData.id}.html`,
)
const selector = 'a[href*="/reset-password?token="]'
let url = await page.getAttribute(selector, "href")
// TODO: update var instead of doing a replace
url = url!.replace("http://localhost/", "http://localhost:5173/")
// Set the new password and confirm it
await page.goto(url)
await page.getByPlaceholder("New Password").fill(newPassword)
await page.getByPlaceholder("Confirm Password").fill(newPassword)
await page.getByRole("button", { name: "Reset Password" }).click()
await expect(page.getByText("Password updated successfully")).toBeVisible()
// Check if the user is able to login with the new password
await logInUser(page, email, newPassword)
})
test("Expired or invalid reset link", async ({ page }) => {
const password = randomPassword()
const invalidUrl = "/reset-password?token=invalidtoken"
await page.goto(invalidUrl)
await page.getByPlaceholder("New Password").fill(password)
await page.getByPlaceholder("Confirm Password").fill(password)
await page.getByRole("button", { name: "Reset Password" }).click()
await expect(page.getByText("Invalid token")).toBeVisible()
})
test("Weak new password validation", async ({ page, request }) => {
const fullName = "Test User"
const email = randomEmail()
const password = randomPassword()
const weakPassword = "123"
// Sign up a new user
await signUpNewUser(page, fullName, email, password)
await page.goto("/recover-password")
await page.getByPlaceholder("Email").fill(email)
await page.getByRole("button", { name: "Continue" }).click()
const emailData = await findLastEmail({
request,
filter: (e) => e.recipients.includes(`<${email}>`),
timeout: 5000,
})
await page.goto(
`${process.env.MAILCATCHER_HOST}/messages/${emailData.id}.html`,
)
const selector = 'a[href*="/reset-password?token="]'
let url = await page.getAttribute(selector, "href")
url = url!.replace("http://localhost/", "http://localhost:5173/")
// Set a weak new password
await page.goto(url)
await page.getByPlaceholder("New Password").fill(weakPassword)
await page.getByPlaceholder("Confirm Password").fill(weakPassword)
await page.getByRole("button", { name: "Reset Password" }).click()
await expect(
page.getByText("Password must be at least 8 characters"),
).toBeVisible()
})