Add private, local only, API for usage in E2E tests (#1429)

Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
Patrick Arminio
2024-12-02 12:57:53 +01:00
committed by GitHub
parent 414864d848
commit 14129f7a50
9 changed files with 127 additions and 31 deletions

View File

@@ -1,7 +1,8 @@
import { expect, test } from "@playwright/test"
import { firstSuperuser, firstSuperuserPassword } from "./config.ts"
import { randomEmail, randomPassword } from "./utils/random"
import { logInUser, logOutUser, signUpNewUser } from "./utils/user"
import { logInUser, logOutUser } from "./utils/user"
import { createUser } from "./utils/privateApi.ts"
const tabs = ["My profile", "Password", "Appearance"]
@@ -26,13 +27,11 @@ test.describe("Edit user full name and email successfully", () => {
test.use({ storageState: { cookies: [], origins: [] } })
test("Edit user name with a valid name", async ({ page }) => {
const fullName = "Test User"
const email = randomEmail()
const updatedName = "Test User 2"
const password = randomPassword()
// Sign up a new user
await signUpNewUser(page, fullName, email, password)
await createUser({ email, password })
// Log in the user
await logInUser(page, email, password)
@@ -50,13 +49,11 @@ test.describe("Edit user full name and email successfully", () => {
})
test("Edit user email with a valid email", async ({ page }) => {
const fullName = "Test User"
const email = randomEmail()
const updatedEmail = randomEmail()
const password = randomPassword()
// Sign up a new user
await signUpNewUser(page, fullName, email, password)
await createUser({ email, password })
// Log in the user
await logInUser(page, email, password)
@@ -77,13 +74,11 @@ test.describe("Edit user with invalid data", () => {
test.use({ storageState: { cookies: [], origins: [] } })
test("Edit user email with an invalid email", async ({ page }) => {
const fullName = "Test User"
const email = randomEmail()
const password = randomPassword()
const invalidEmail = ""
// Sign up a new user
await signUpNewUser(page, fullName, email, password)
await createUser({ email, password })
// Log in the user
await logInUser(page, email, password)
@@ -97,13 +92,11 @@ test.describe("Edit user with invalid data", () => {
})
test("Cancel edit action restores original name", async ({ page }) => {
const fullName = "Test User"
const email = randomEmail()
const password = randomPassword()
const updatedName = "Test User"
// Sign up a new user
await signUpNewUser(page, fullName, email, password)
const user = await createUser({ email, password })
// Log in the user
await logInUser(page, email, password)
@@ -114,18 +107,18 @@ test.describe("Edit user with invalid data", () => {
await page.getByLabel("Full name").fill(updatedName)
await page.getByRole("button", { name: "Cancel" }).first().click()
await expect(
page.getByLabel("My profile").getByText(fullName, { exact: true }),
page
.getByLabel("My profile")
.getByText(user.full_name as string, { exact: true }),
).toBeVisible()
})
test("Cancel edit action restores original email", async ({ page }) => {
const fullName = "Test User"
const email = randomEmail()
const password = randomPassword()
const updatedEmail = randomEmail()
// Sign up a new user
await signUpNewUser(page, fullName, email, password)
await createUser({ email, password })
// Log in the user
await logInUser(page, email, password)
@@ -147,13 +140,11 @@ test.describe("Change password successfully", () => {
test.use({ storageState: { cookies: [], origins: [] } })
test("Update password successfully", async ({ page }) => {
const fullName = "Test User"
const email = randomEmail()
const password = randomPassword()
const NewPassword = randomPassword()
// Sign up a new user
await signUpNewUser(page, fullName, email, password)
await createUser({ email, password })
// Log in the user
await logInUser(page, email, password)
@@ -177,13 +168,11 @@ test.describe("Change password with invalid data", () => {
test.use({ storageState: { cookies: [], origins: [] } })
test("Update password with weak passwords", async ({ page }) => {
const fullName = "Test User"
const email = randomEmail()
const password = randomPassword()
const weakPassword = "weak"
// Sign up a new user
await signUpNewUser(page, fullName, email, password)
await createUser({ email, password })
// Log in the user
await logInUser(page, email, password)
@@ -201,14 +190,12 @@ test.describe("Change password with invalid data", () => {
test("New password and confirmation password do not match", async ({
page,
}) => {
const fullName = "Test User"
const email = randomEmail()
const password = randomPassword()
const newPassword = randomPassword()
const confirmPassword = randomPassword()
// Sign up a new user
await signUpNewUser(page, fullName, email, password)
await createUser({ email, password })
// Log in the user
await logInUser(page, email, password)
@@ -223,12 +210,10 @@ test.describe("Change password with invalid data", () => {
})
test("Current password and new password are the same", async ({ page }) => {
const fullName = "Test User"
const email = randomEmail()
const password = randomPassword()
// Sign up a new user
await signUpNewUser(page, fullName, email, password)
await createUser({ email, password })
// Log in the user
await logInUser(page, email, password)

View 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",
},
})
}