|
1 | | -import { expect, test as setup } from "@playwright/test"; |
2 | | -import { env } from "./env"; |
| 1 | +import { nanoid } from "@dub/utils"; |
| 2 | +import { expect, test } from "@playwright/test"; |
| 3 | +import { extractOtp, waitForEmail } from "./mailhog"; |
| 4 | + |
| 5 | +// Must satisfy: 8+ chars, uppercase, lowercase, digit |
| 6 | +const SIGNUP_PASSWORD = "Password123"; |
3 | 7 |
|
4 | 8 | const authFile = "playwright/.auth/partner.json"; |
5 | 9 |
|
6 | | -setup("authenticate as partner", async ({ page }) => { |
7 | | - await page.goto("/login"); |
8 | | - await page.locator('input[name="email"]').fill(env.E2E_PARTNER_EMAIL); |
9 | | - await page.getByRole("button", { name: "Log in with email" }).click(); |
10 | | - await expect(page.locator('input[type="password"]')).toBeVisible(); |
11 | | - await page.locator('input[type="password"]').fill(env.E2E_PARTNER_PASSWORD); |
12 | | - await page.getByRole("button", { name: "Log in with password" }).click(); |
13 | | - await page.waitForURL((url) => |
14 | | - /^\/(programs|onboarding)/.test(new URL(url).pathname), |
15 | | - ); |
| 10 | +test("sign up and verify new partner", async ({ page }) => { |
| 11 | + const email = `${nanoid(10)}@dub-internal-test.com`; |
| 12 | + |
| 13 | + // Go to registration page |
| 14 | + await page.goto("/register"); |
| 15 | + |
| 16 | + // Step 1: Enter email and reveal password field |
| 17 | + await page.locator('input[name="email"]').fill(email); |
| 18 | + await page.getByRole("button", { name: "Sign Up" }).click(); |
| 19 | + |
| 20 | + // Step 2: Enter password and submit |
| 21 | + const passwordInput = page.locator('input[name="password"]'); |
| 22 | + await expect(passwordInput).toBeVisible(); |
| 23 | + await passwordInput.fill(SIGNUP_PASSWORD); |
| 24 | + await page.getByRole("button", { name: "Sign Up" }).click(); |
| 25 | + |
| 26 | + // Step 3: Verify email via OTP from MailHog |
| 27 | + await expect( |
| 28 | + page.getByRole("heading", { name: "Verify your email address" }), |
| 29 | + ).toBeVisible(); |
| 30 | + |
| 31 | + const message = await waitForEmail(email); |
| 32 | + const otp = extractOtp(message); |
| 33 | + |
| 34 | + // The OTP input auto-focuses on desktop — type the digits directly |
| 35 | + await page.keyboard.type(otp); |
| 36 | + |
| 37 | + // Step 4: Wait for redirect to onboarding after auto-submit |
| 38 | + // CI is slower; use domcontentloaded so we don't wait for full page load (images, etc.) |
| 39 | + await page.waitForURL(/\/onboarding/, { |
| 40 | + timeout: process.env.CI ? 30_000 : 15_000, |
| 41 | + waitUntil: "domcontentloaded", |
| 42 | + }); |
| 43 | + |
| 44 | + // Save authenticated state |
16 | 45 | await page.context().storageState({ path: authFile }); |
17 | 46 | }); |
0 commit comments