|
1 | 1 | import { expect, test } from "@playwright/test" |
2 | | -import { emailUrl, findLastEmail } from "./utils/mailpit" |
| 2 | +import { waitForEmailHtml } from "./utils/mailpit" |
3 | 3 | import { randomEmail, randomPassword } from "./utils/random" |
4 | 4 | import { logInUser, signUpNewUser } from "./utils/user" |
5 | 5 |
|
6 | 6 | test.use({ storageState: { cookies: [], origins: [] } }) |
7 | 7 |
|
| 8 | +const resetPath = "/reset-password?token=" |
| 9 | + |
8 | 10 | test("Password Recovery title is visible", async ({ page }) => { |
9 | 11 | await page.goto("/recover-password") |
10 | 12 |
|
@@ -44,21 +46,17 @@ test("User can reset password successfully using the link", async ({ |
44 | 46 |
|
45 | 47 | await page.getByRole("button", { name: "Continue" }).click() |
46 | 48 |
|
47 | | - const emailData = await findLastEmail({ |
| 49 | + const emailHtml = await waitForEmailHtml({ |
48 | 50 | request, |
49 | 51 | query: `to:${email}`, |
50 | | - timeout: 5000, |
51 | 52 | }) |
52 | 53 |
|
53 | | - await page.goto(emailUrl(emailData)) |
54 | | - |
55 | | - const selector = 'a[href*="/reset-password?token="]' |
56 | | - |
57 | | - const url = await page.getAttribute(selector, "href") |
58 | | - const resetUrl = new URL(url!) |
| 54 | + expect(emailHtml).toContain(resetPath) |
| 55 | + const resetUrl = emailHtml.match(/\/reset-password\?token=[^"]+/)?.[0] |
| 56 | + expect(resetUrl).toBeDefined() |
59 | 57 |
|
60 | 58 | // Set the new password and confirm it |
61 | | - await page.goto(`${resetUrl.pathname}${resetUrl.search}`) |
| 59 | + await page.goto(resetUrl!) |
62 | 60 |
|
63 | 61 | await page.getByTestId("new-password-input").fill(newPassword) |
64 | 62 | await page.getByTestId("confirm-password-input").fill(newPassword) |
@@ -95,20 +93,17 @@ test("Weak new password validation", async ({ page, request }) => { |
95 | 93 | await page.getByTestId("email-input").fill(email) |
96 | 94 | await page.getByRole("button", { name: "Continue" }).click() |
97 | 95 |
|
98 | | - const emailData = await findLastEmail({ |
| 96 | + const emailHtml = await waitForEmailHtml({ |
99 | 97 | request, |
100 | 98 | query: `to:${email}`, |
101 | | - timeout: 5000, |
102 | 99 | }) |
103 | 100 |
|
104 | | - await page.goto(emailUrl(emailData)) |
105 | | - |
106 | | - const selector = 'a[href*="/reset-password?token="]' |
107 | | - const url = await page.getAttribute(selector, "href") |
108 | | - const resetUrl = new URL(url!) |
| 101 | + expect(emailHtml).toContain(resetPath) |
| 102 | + const resetUrl = emailHtml.match(/\/reset-password\?token=[^"]+/)?.[0] |
| 103 | + expect(resetUrl).toBeDefined() |
109 | 104 |
|
110 | 105 | // Set a weak new password |
111 | | - await page.goto(`${resetUrl.pathname}${resetUrl.search}`) |
| 106 | + await page.goto(resetUrl!) |
112 | 107 | await page.getByTestId("new-password-input").fill(weakPassword) |
113 | 108 | await page.getByTestId("confirm-password-input").fill(weakPassword) |
114 | 109 | await page.getByRole("button", { name: "Reset Password" }).click() |
|
0 commit comments