mirror of
https://github.com/danswer-ai/danswer.git
synced 2025-07-05 04:01:31 +02:00
Non-SMTP password reset (#4031)
* update * validate * k * minor cleanup * nit * finalize * k * fix tests * fix tests * fix tests
This commit is contained in:
@ -1,11 +1,23 @@
|
||||
import { Page } from "@playwright/test";
|
||||
import { TEST_ADMIN_CREDENTIALS, TEST_USER_CREDENTIALS } from "../constants";
|
||||
import {
|
||||
TEST_ADMIN2_CREDENTIALS,
|
||||
TEST_ADMIN_CREDENTIALS,
|
||||
TEST_USER_CREDENTIALS,
|
||||
} from "../constants";
|
||||
|
||||
// Basic function which logs in a user (either admin or regular user) to the application
|
||||
// It handles both successful login attempts and potential timeouts, with a retry mechanism
|
||||
export async function loginAs(page: Page, userType: "admin" | "user") {
|
||||
export async function loginAs(
|
||||
page: Page,
|
||||
userType: "admin" | "user" | "admin2"
|
||||
) {
|
||||
const { email, password } =
|
||||
userType === "admin" ? TEST_ADMIN_CREDENTIALS : TEST_USER_CREDENTIALS;
|
||||
userType === "admin"
|
||||
? TEST_ADMIN_CREDENTIALS
|
||||
: userType === "admin2"
|
||||
? TEST_ADMIN2_CREDENTIALS
|
||||
: TEST_USER_CREDENTIALS;
|
||||
|
||||
await page.goto("http://localhost:3000/auth/login", { timeout: 1000 });
|
||||
|
||||
await page.fill("#email", email);
|
||||
@ -72,3 +84,51 @@ export async function loginAsRandomUser(page: Page) {
|
||||
|
||||
return { email, password };
|
||||
}
|
||||
|
||||
export async function inviteAdmin2AsAdmin1(page: Page) {
|
||||
await page.goto("http://localhost:3000/admin/users");
|
||||
// Wait for 400ms to ensure the page has loaded completely
|
||||
await page.waitForTimeout(400);
|
||||
|
||||
// Log all currently visible test ids
|
||||
const testIds = await page.evaluate(() => {
|
||||
return Array.from(document.querySelectorAll("[data-testid]")).map((el) =>
|
||||
el.getAttribute("data-testid")
|
||||
);
|
||||
});
|
||||
console.log("Currently visible test ids:", testIds);
|
||||
|
||||
try {
|
||||
// Wait for the dropdown trigger to be visible and click it
|
||||
await page
|
||||
.getByTestId("user-role-dropdown-trigger-admin2_user@test.com")
|
||||
.waitFor({ state: "visible", timeout: 5000 });
|
||||
await page
|
||||
.getByTestId("user-role-dropdown-trigger-admin2_user@test.com")
|
||||
.click();
|
||||
|
||||
// Wait for the admin option to be visible
|
||||
await page
|
||||
.getByTestId("user-role-dropdown-admin")
|
||||
.waitFor({ state: "visible", timeout: 5000 });
|
||||
|
||||
// Click the admin option
|
||||
await page.getByTestId("user-role-dropdown-admin").click();
|
||||
|
||||
// Wait for any potential loading or update to complete
|
||||
await page.waitForTimeout(1000);
|
||||
|
||||
// Verify that the change was successful (you may need to adjust this based on your UI)
|
||||
const newRole = await page
|
||||
.getByTestId("user-role-dropdown-trigger-admin2_user@test.com")
|
||||
.textContent();
|
||||
if (newRole?.toLowerCase().includes("admin")) {
|
||||
console.log("Successfully invited admin2 as admin");
|
||||
} else {
|
||||
throw new Error("Failed to update user role to admin");
|
||||
}
|
||||
} catch (error) {
|
||||
console.error("Error inviting admin2 as admin:", error);
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user