-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #461 from Open-Earth-Foundation/feat/login-e2e
feat(e2e): implement integration tests for login
- Loading branch information
Showing
6 changed files
with
102 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import { expect, type Page, APIRequestContext } from "@playwright/test"; | ||
|
||
export async function expectText(page: Page, text: string) { | ||
await expect(page.getByText(text).first()).toBeVisible(); | ||
} | ||
|
||
export async function signup( | ||
request: APIRequestContext, | ||
email: string, | ||
password: string = "Test123", | ||
confirmPassword: string = "Test123", | ||
name: string = "Test Account", | ||
inviteCode: string = "123456", | ||
acceptTerms: boolean = true, | ||
) { | ||
const result = await request.post("/api/v0/auth/signup", { | ||
data: { | ||
email, | ||
password, | ||
confirmPassword, | ||
name, | ||
inviteCode, | ||
acceptTerms, | ||
}, | ||
}); | ||
expect(result.ok()).toBeTruthy(); | ||
return await result.json(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { test, expect, APIRequestContext } from "@playwright/test"; | ||
import { expectText } from "./helpers"; | ||
import { randomUUID } from "node:crypto"; | ||
|
||
async function signup( | ||
request: APIRequestContext, | ||
email: string, | ||
password: string = "Test123!", | ||
confirmPassword: string = "Test123!", | ||
name: string = "Test Account", | ||
inviteCode: string = "123456", | ||
acceptTerms: boolean = true, | ||
) { | ||
const result = await request.post("/api/v0/auth/register", { | ||
data: { | ||
email, | ||
password, | ||
confirmPassword, | ||
name, | ||
inviteCode, | ||
acceptTerms, | ||
}, | ||
}); | ||
console.log("Signup res", await result.text()); | ||
expect(result.ok()).toBeTruthy(); | ||
return await result.json(); | ||
} | ||
|
||
test.beforeEach(async ({ page }) => { | ||
await page.goto("/en/auth/login"); | ||
}); | ||
|
||
test.describe("Login page", () => { | ||
test("redirects to onboarding after entering correct data", async ({ | ||
page, | ||
request, | ||
}) => { | ||
const email = `login-test+${randomUUID()}@openearth.org`; | ||
const password = "Test123!"; | ||
await signup(request, email, password, password); | ||
// await page.route("/api/auth/session", (route) => { | ||
// route.fulfill({ body: JSON.stringify({ ok: true }) }); | ||
// }); | ||
|
||
await expectText(page, "Log In to City Catalyst"); | ||
await page.locator('input[name="email"]').fill(email); | ||
await page.locator('input[name="password"]').fill(password); | ||
await page.locator('button[type="submit"]').click(); | ||
|
||
// TODO how to ensure that session route was called? | ||
await page.waitForResponse("/api/auth/session"); | ||
|
||
await expect(page).toHaveURL("/en/onboarding"); | ||
}); | ||
|
||
test("shows errors when entering invalid data", async ({ page }) => { | ||
await expectText(page, "Log In to City Catalyst"); | ||
|
||
await page.locator('input[name="email"]').fill("testopenearthorg"); | ||
await page.locator('input[name="password"]').fill("pas"); | ||
await page.locator('button[type="submit"]').click(); | ||
|
||
await expect(page).toHaveURL("/en/auth/login"); | ||
await expectText(page, "valid email address"); | ||
await expectText(page, "Minimum length"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters