Skip to content
Snippets Groups Projects
Commit a5f2ee1d authored by ccahoon1's avatar ccahoon1
Browse files

fixed most of the tests and config

parent e7702b26
No related branches found
No related tags found
No related merge requests found
......@@ -54,8 +54,8 @@ test("Log in with valid email and password ", async ({ page }) => {
await page.waitForURL("/")
await expect(
page.getByText("Welcome back, nice to see you again!"),
).toBeVisible({ timeout: 10000 })
page.getByText("Explore Assignments"),
).toBeVisible({ timeout: 15000 })
})
test("Log in with invalid email", async ({ page }) => {
......@@ -74,7 +74,7 @@ test("Log in with invalid password", async ({ page }) => {
await fillForm(page, firstSuperuser, password)
await page.getByRole("button", { name: "Log In" }).click()
await expect(page.getByText("Incorrect email or password")).toBeVisible()
await expect(page).toHaveURL('/login')
})
// Log out
......@@ -88,11 +88,10 @@ test("Successful log out", async ({ page }) => {
await page.waitForURL("/")
await expect(
page.getByText("Welcome back, nice to see you again!"),
).toBeVisible()
page.getByText("Explore Assignments"),
).toBeVisible({ timeout: 15000 })
await page.getByTestId("user-menu").click()
await page.getByRole("menuitem", { name: "Log out" }).click()
await page.getByText("Log Out").click()
await page.waitForURL("/login")
})
......@@ -105,11 +104,10 @@ test("Logged-out user cannot access protected routes", async ({ page }) => {
await page.waitForURL("/")
await expect(
page.getByText("Welcome back, nice to see you again!"),
).toBeVisible()
page.getByText("Explore Assignments"),
).toBeVisible({ timeout: 15000 })
await page.getByTestId("user-menu").click()
await page.getByRole("menuitem", { name: "Log out" }).click()
await page.getByText("Log Out").click({ timeout: 10000 })
await page.waitForURL("/login")
await page.goto("/settings")
......
......
......@@ -9,28 +9,43 @@ type Email = {
async function findEmail({
request,
filter,
}: { request: APIRequestContext; filter?: (email: Email) => boolean }) {
const response = await request.get(`${process.env.MAILCATCHER_HOST}/messages`)
}: {
request: APIRequestContext
filter?: (email: Email) => boolean
}): Promise<Email | null> {
// use the .json API
const res = await request.get(
`${process.env.MAILCATCHER_HOST}/messages.json`,
{ headers: { Accept: "application/json" } }
)
let emails = await response.json()
if (res.status() !== 200) {
return null
}
if (filter) {
emails = emails.filter(filter)
let emails: any
try {
emails = await res.json()
} catch {
return null
}
const email = emails[emails.length - 1]
if (!Array.isArray(emails)) {
return null
}
if (email) {
return email as Email
if (filter) {
emails = emails.filter(filter)
}
return null
const last = emails[emails.length - 1]
return last ? (last as Email) : null
}
export function findLastEmail({
request,
filter,
timeout = 5000,
timeout = 30000,
}: {
request: APIRequestContext
filter?: (email: Email) => boolean
......@@ -39,21 +54,20 @@ export function findLastEmail({
const timeoutPromise = new Promise<never>((_, reject) =>
setTimeout(
() => reject(new Error("Timeout while trying to get latest email")),
timeout,
),
timeout
)
)
const checkEmails = async () => {
const checkEmails = async (): Promise<Email> => {
while (true) {
const emailData = await findEmail({ request, filter })
if (emailData) {
return emailData
}
// Wait for 100ms before checking again
await new Promise((resolve) => setTimeout(resolve, 100))
await new Promise((r) => setTimeout(r, 100))
}
}
return Promise.race([timeoutPromise, checkEmails()])
}
......@@ -21,15 +21,15 @@ export async function logInUser(page: Page, email: string, password: string) {
await page.getByPlaceholder("Email").fill(email)
await page.getByPlaceholder("Password", { exact: true }).fill(password)
await page.getByRole("button", { name: "Log In" }).click()
await page.getByRole("button", { name: "Log In" }).click({ timeout: 30000 })
await page.waitForURL("/")
await expect(
page.getByText("Welcome back, nice to see you again!"),
).toBeVisible()
page.getByText("Explore Assignement"),
).toBeVisible({ timeout: 15000 })
}
export async function logOutUser(page: Page) {
await page.getByTestId("user-menu").click()
await page.getByRole("menuitem", { name: "Log out" }).click()
await page.getByText("Log Out").click( { timeout: 30000 } )
await page.goto("/login")
}
......@@ -2,10 +2,10 @@
"cookies": [
{
"name": "better-auth.session_token",
"value": "RYDpx2xMbwTUIzCOMLlKthcZVOXhQISe.vrlRgYDBhFTUDYa%2BWEF38117HSzl8bsv78bRCSz6va8%3D",
"value": "e2MLQV7xbmwLNtBUSqRPmipODriinNQj.6OJGXsz5zCOgYLdTOgMFlKoRi0cqVJSX8xUK1hUXmdQ%3D",
"domain": "localhost",
"path": "/",
"expires": 1747066310.182979,
"expires": 1747853565.325038,
"httpOnly": true,
"secure": false,
"sameSite": "Lax"
......
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment