-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
179 additions
and
35 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 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,38 @@ | ||
import { test as setup, expect } from "@playwright/test"; | ||
import { loginAs } from "./utils/auth"; | ||
|
||
setup("create auth states", async ({ browser }) => { | ||
// Setup admin auth | ||
const adminContext = await browser.newContext(); | ||
const adminPage = await adminContext.newPage(); | ||
await loginAs(adminPage, "admin"); | ||
await adminContext.storageState({ path: "admin_auth.json" }); | ||
await adminContext.close(); | ||
|
||
// Setup user auth | ||
const userContext = await browser.newContext(); | ||
const userPage = await userContext.newPage(); | ||
|
||
// Login as admin to create user | ||
await loginAs(userPage, "admin"); | ||
await userPage.goto("http://localhost:3000/admin/indexing/status"); | ||
await userPage.getByRole("button", { name: "Users" }).click(); | ||
await userPage.getByRole("button", { name: "Invite Users" }).click(); | ||
await userPage.locator("#emails").fill("[email protected]"); | ||
await userPage.getByRole("button", { name: "Add!" }).click(); | ||
|
||
// Logout admin | ||
await userPage.getByText("A", { exact: true }).click(); | ||
await userPage.getByText("Log out").click(); | ||
|
||
// Create and login as new user | ||
await userPage.goto("http://localhost:3000/auth/login"); | ||
await userPage.getByRole("link", { name: "Create an account" }).click(); | ||
await userPage.getByTestId("email").fill("[email protected]"); | ||
await userPage.getByTestId("password").fill("test"); | ||
await userPage.getByRole("button", { name: "Sign Up" }).click(); | ||
await userPage.waitForURL("http://localhost:3000/chat"); | ||
|
||
await userContext.storageState({ path: "user_auth.json" }); | ||
await userContext.close(); | ||
}); |
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 |
---|---|---|
|
@@ -2,3 +2,8 @@ export const TEST_CREDENTIALS = { | |
email: "[email protected]", | ||
password: "test", | ||
}; | ||
|
||
export const TEST_USER_CREDENTIALS = { | ||
email: "[email protected]", | ||
password: "test", | ||
}; |
Empty file.
8 changes: 5 additions & 3 deletions
8
...ests/e2e/core_flows/search_update.test.ts → ...core_flows/search_settings_update.test.ts
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { chromium, FullConfig } from "@playwright/test"; | ||
import { loginAs } from "./utils/auth"; | ||
|
||
async function globalSetup(config: FullConfig) { | ||
const browser = await chromium.launch(); | ||
|
||
// Setup admin auth | ||
const adminContext = await browser.newContext(); | ||
const adminPage = await adminContext.newPage(); | ||
await loginAs(adminPage, "admin"); | ||
await adminContext.storageState({ path: "admin_auth.json" }); | ||
await adminContext.close(); | ||
|
||
// Setup user auth | ||
const userContext = await browser.newContext(); | ||
const userPage = await userContext.newPage(); | ||
|
||
// Login as admin to create user | ||
await loginAs(userPage, "admin"); | ||
await userPage.goto("/admin/indexing/status"); | ||
await userPage.getByRole("button", { name: "Users" }).click(); | ||
await userPage.getByRole("button", { name: "Invite Users" }).click(); | ||
await userPage.locator("#emails").fill("[email protected]"); | ||
await userPage.getByRole("button", { name: "Add!" }).click(); | ||
|
||
// Logout admin | ||
await userPage.getByText("A", { exact: true }).click(); | ||
await userPage.getByText("Log out").click(); | ||
|
||
// Create and login as new user | ||
await userPage.goto("/auth/login"); | ||
await userPage.getByRole("link", { name: "Create an account" }).click(); | ||
await userPage.getByTestId("email").fill("[email protected]"); | ||
await userPage.getByTestId("password").fill("test"); | ||
await userPage.getByRole("button", { name: "Sign Up" }).click(); | ||
await userPage.waitForURL("/chat"); | ||
|
||
await userContext.storageState({ path: "user_auth.json" }); | ||
await userContext.close(); | ||
|
||
await browser.close(); | ||
} | ||
|
||
export default globalSetup; |
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,40 @@ | ||
import { test as setup, expect } from "@playwright/test"; | ||
import { loginAs } from "./utils/auth"; | ||
|
||
setup("create test user", async ({ page, context }) => { | ||
// Login as admin | ||
await loginAs(page, "admin"); | ||
|
||
// Create test user | ||
await page.goto("http://localhost:3000/admin/indexing/status"); | ||
await page.getByRole("button", { name: "Users" }).click(); | ||
await page.getByRole("button", { name: "Invite Users" }).click(); | ||
await page.locator("#emails").click(); | ||
await page.locator("#emails").fill("[email protected]"); | ||
await page.getByRole("button", { name: "Add!" }).click(); | ||
|
||
// Logout | ||
await page.getByText("A", { exact: true }).click(); | ||
await page.getByText("Log out").click(); | ||
|
||
// Create account for the invited user | ||
await page.goto("http://localhost:3000/auth/login"); | ||
await page.getByRole("link", { name: "Create an account" }).click(); | ||
await page.getByTestId("email").click(); | ||
await page.waitForTimeout(500); | ||
await page.getByTestId("email").fill("[email protected]"); | ||
await page.waitForTimeout(500); | ||
await page.getByTestId("password").click(); | ||
await page.waitForTimeout(500); | ||
await page.getByTestId("password").fill("test"); | ||
await page.waitForTimeout(500); | ||
await page.getByRole("button", { name: "Sign Up" }).click(); | ||
await page.waitForTimeout(2000); | ||
|
||
// Verify successful account creation | ||
await page.waitForURL("http://localhost:3000/chat"); | ||
await expect(page).toHaveURL("http://localhost:3000/chat"); | ||
|
||
// Save authentication state | ||
await context.storageState({ path: "user_auth.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,19 @@ | ||
import { Page } from "@playwright/test"; | ||
import { TEST_CREDENTIALS, TEST_USER_CREDENTIALS } from "../constants"; | ||
|
||
export async function loginAs(page: Page, userType: "admin" | "user") { | ||
const { email, password } = | ||
userType === "admin" ? TEST_CREDENTIALS : TEST_USER_CREDENTIALS; | ||
|
||
await page.goto("http://localhost:3000/chat"); | ||
|
||
await page.waitForURL("http://localhost:3000/auth/login?next=%2Fchat"); | ||
|
||
await page.fill("#email", email); | ||
await page.fill("#password", password); | ||
|
||
// Click the login button | ||
await page.click('button[type="submit"]'); | ||
|
||
await page.waitForURL("http://localhost:3000/chat"); | ||
} |
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,15 @@ | ||
{ | ||
"cookies": [ | ||
{ | ||
"name": "fastapiusersauth", | ||
"value": "lbgX6spEvhdzvCE6uNugvMQE3AqtSW1JVEZb1hXF79A", | ||
"domain": "localhost", | ||
"path": "/", | ||
"expires": 1734908599.292503, | ||
"httpOnly": true, | ||
"secure": false, | ||
"sameSite": "Lax" | ||
} | ||
], | ||
"origins": [] | ||
} |