frontend build
This commit is contained in:
59
frontend/tests/utils/mailcatcher.ts
Normal file
59
frontend/tests/utils/mailcatcher.ts
Normal file
@@ -0,0 +1,59 @@
|
||||
import type { APIRequestContext } from "@playwright/test"
|
||||
|
||||
type Email = {
|
||||
id: number
|
||||
recipients: string[]
|
||||
subject: string
|
||||
}
|
||||
|
||||
async function findEmail({
|
||||
request,
|
||||
filter,
|
||||
}: { request: APIRequestContext; filter?: (email: Email) => boolean }) {
|
||||
const response = await request.get(`${process.env.MAILCATCHER_HOST}/messages`)
|
||||
|
||||
let emails = await response.json()
|
||||
|
||||
if (filter) {
|
||||
emails = emails.filter(filter)
|
||||
}
|
||||
|
||||
const email = emails[emails.length - 1]
|
||||
|
||||
if (email) {
|
||||
return email as Email
|
||||
}
|
||||
|
||||
return null
|
||||
}
|
||||
|
||||
export function findLastEmail({
|
||||
request,
|
||||
filter,
|
||||
timeout = 5000,
|
||||
}: {
|
||||
request: APIRequestContext
|
||||
filter?: (email: Email) => boolean
|
||||
timeout?: number
|
||||
}) {
|
||||
const timeoutPromise = new Promise<never>((_, reject) =>
|
||||
setTimeout(
|
||||
() => reject(new Error("Timeout while trying to get latest email")),
|
||||
timeout,
|
||||
),
|
||||
)
|
||||
|
||||
const checkEmails = async () => {
|
||||
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))
|
||||
}
|
||||
}
|
||||
|
||||
return Promise.race([timeoutPromise, checkEmails()])
|
||||
}
|
||||
22
frontend/tests/utils/privateApi.ts
Normal file
22
frontend/tests/utils/privateApi.ts
Normal file
@@ -0,0 +1,22 @@
|
||||
// Note: the `PrivateService` is only available when generating the client
|
||||
// for local environments
|
||||
import { OpenAPI, PrivateService } from "../../src/client"
|
||||
|
||||
OpenAPI.BASE = `${process.env.VITE_API_URL}`
|
||||
|
||||
export const createUser = async ({
|
||||
email,
|
||||
password,
|
||||
}: {
|
||||
email: string
|
||||
password: string
|
||||
}) => {
|
||||
return await PrivateService.createUser({
|
||||
requestBody: {
|
||||
email,
|
||||
password,
|
||||
is_verified: true,
|
||||
full_name: "Test User",
|
||||
},
|
||||
})
|
||||
}
|
||||
13
frontend/tests/utils/random.ts
Normal file
13
frontend/tests/utils/random.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
export const randomEmail = () =>
|
||||
`test_${Math.random().toString(36).substring(7)}@example.com`
|
||||
|
||||
export const randomTeamName = () =>
|
||||
`Team ${Math.random().toString(36).substring(7)}`
|
||||
|
||||
export const randomPassword = () => `${Math.random().toString(36).substring(2)}`
|
||||
|
||||
export const slugify = (text: string) =>
|
||||
text
|
||||
.toLowerCase()
|
||||
.replace(/\s+/g, "-")
|
||||
.replace(/[^\w-]+/g, "")
|
||||
35
frontend/tests/utils/user.ts
Normal file
35
frontend/tests/utils/user.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import { type Page, expect } from "@playwright/test"
|
||||
|
||||
export async function signUpNewUser(
|
||||
page: Page,
|
||||
name: string,
|
||||
email: string,
|
||||
password: string,
|
||||
) {
|
||||
await page.goto("/signup")
|
||||
|
||||
await page.getByPlaceholder("Full Name").fill(name)
|
||||
await page.getByPlaceholder("Email").fill(email)
|
||||
await page.getByPlaceholder("Password", { exact: true }).fill(password)
|
||||
await page.getByPlaceholder("Confirm Password").fill(password)
|
||||
await page.getByRole("button", { name: "Sign Up" }).click()
|
||||
await page.goto("/login")
|
||||
}
|
||||
|
||||
export async function logInUser(page: Page, email: string, password: string) {
|
||||
await page.goto("/login")
|
||||
|
||||
await page.getByPlaceholder("Email").fill(email)
|
||||
await page.getByPlaceholder("Password", { exact: true }).fill(password)
|
||||
await page.getByRole("button", { name: "Log In" }).click()
|
||||
await page.waitForURL("/")
|
||||
await expect(
|
||||
page.getByText("Welcome back, nice to see you again!"),
|
||||
).toBeVisible()
|
||||
}
|
||||
|
||||
export async function logOutUser(page: Page) {
|
||||
await page.getByTestId("user-menu").click()
|
||||
await page.getByRole("menuitem", { name: "Log out" }).click()
|
||||
await page.goto("/login")
|
||||
}
|
||||
Reference in New Issue
Block a user