From 560904a4fc08da8b0cecde58d49e00ea1173dd5c Mon Sep 17 00:00:00 2001 From: Patrick Arminio Date: Fri, 22 Nov 2024 11:31:05 +0000 Subject: [PATCH 01/18] Add a local only private API --- backend/app/api/main.py | 7 +++- backend/app/api/routes/private.py | 38 ++++++++++++++++++++ backend/app/tests/api/routes/test_private.py | 26 ++++++++++++++ 3 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 backend/app/api/routes/private.py create mode 100644 backend/app/tests/api/routes/test_private.py diff --git a/backend/app/api/main.py b/backend/app/api/main.py index 09e0663fc3..6c702234da 100644 --- a/backend/app/api/main.py +++ b/backend/app/api/main.py @@ -1,9 +1,14 @@ from fastapi import APIRouter -from app.api.routes import items, login, users, utils +from app.api.routes import items, login, private, users, utils +from app.core.config import settings api_router = APIRouter() api_router.include_router(login.router, tags=["login"]) api_router.include_router(users.router, prefix="/users", tags=["users"]) api_router.include_router(utils.router, prefix="/utils", tags=["utils"]) api_router.include_router(items.router, prefix="/items", tags=["items"]) + + +if settings.ENVIRONMENT == "local": + api_router.include_router(private.router, prefix="/private", tags=["private"]) diff --git a/backend/app/api/routes/private.py b/backend/app/api/routes/private.py new file mode 100644 index 0000000000..7dbb007b28 --- /dev/null +++ b/backend/app/api/routes/private.py @@ -0,0 +1,38 @@ +from typing import Any + +from fastapi import APIRouter +from pydantic import BaseModel + +from app.api.deps import SessionDep +from app.core.security import get_password_hash +from app.models import ( + User, + UserPublic, +) + +router = APIRouter(tags=["private"]) + + +class PrivateCreateUser(BaseModel): + email: str + password: str + full_name: str + is_verified: bool = False + + +@router.post("/users/", response_model=UserPublic) +def create_user(user_in: PrivateCreateUser, session: SessionDep) -> Any: + """ + Create a new user. + """ + + user = User( + email=user_in.email, + full_name=user_in.full_name, + hashed_password=get_password_hash(user_in.password), + ) + + session.add(user) + session.commit() + + return user diff --git a/backend/app/tests/api/routes/test_private.py b/backend/app/tests/api/routes/test_private.py new file mode 100644 index 0000000000..1e1f985021 --- /dev/null +++ b/backend/app/tests/api/routes/test_private.py @@ -0,0 +1,26 @@ +from fastapi.testclient import TestClient +from sqlmodel import Session, select + +from app.core.config import settings +from app.models import User + + +def test_create_user(client: TestClient, db: Session) -> None: + r = client.post( + f"{settings.API_V1_STR}/private/users/", + json={ + "email": "pollo@listo.com", + "password": "password123", + "full_name": "Pollo Listo", + }, + ) + + assert r.status_code == 200 + + data = r.json() + + user = db.exec(select(User).where(User.id == data["id"])).first() + + assert user + assert user.email == "pollo@listo.com" + assert user.full_name == "Pollo Listo" From 73daefadc355874eb480db50f4380d2183a8a2c5 Mon Sep 17 00:00:00 2001 From: Patrick Arminio Date: Mon, 25 Nov 2024 11:04:05 +0000 Subject: [PATCH 02/18] Rename type --- backend/app/api/routes/private.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/app/api/routes/private.py b/backend/app/api/routes/private.py index 7dbb007b28..69002a18e8 100644 --- a/backend/app/api/routes/private.py +++ b/backend/app/api/routes/private.py @@ -13,7 +13,7 @@ router = APIRouter(tags=["private"]) -class PrivateCreateUser(BaseModel): +class CreateUser(BaseModel): email: str password: str full_name: str @@ -21,7 +21,7 @@ class PrivateCreateUser(BaseModel): @router.post("/users/", response_model=UserPublic) -def create_user(user_in: PrivateCreateUser, session: SessionDep) -> Any: +def create_user(user_in: CreateUser, session: SessionDep) -> Any: """ Create a new user. """ From 7a9f9455a0d47126b6671e08351efd406b6c221e Mon Sep 17 00:00:00 2001 From: Patrick Arminio Date: Mon, 25 Nov 2024 12:16:56 +0000 Subject: [PATCH 03/18] Rename type --- backend/app/api/routes/private.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/app/api/routes/private.py b/backend/app/api/routes/private.py index 69002a18e8..34dcc8a581 100644 --- a/backend/app/api/routes/private.py +++ b/backend/app/api/routes/private.py @@ -13,7 +13,7 @@ router = APIRouter(tags=["private"]) -class CreateUser(BaseModel): +class UserCreate(BaseModel): email: str password: str full_name: str @@ -21,7 +21,7 @@ class CreateUser(BaseModel): @router.post("/users/", response_model=UserPublic) -def create_user(user_in: CreateUser, session: SessionDep) -> Any: +def create_user(user_in: UserCreate, session: SessionDep) -> Any: """ Create a new user. """ From c003281d026a3343187d43b67a47aa5a25a2aa48 Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 25 Nov 2024 12:19:03 +0000 Subject: [PATCH 04/18] =?UTF-8?q?=E2=9C=A8=20Autogenerate=20frontend=20cli?= =?UTF-8?q?ent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/client/sdk.gen.ts | 26 ++++++++++++++++++++++++++ frontend/src/client/types.gen.ts | 31 ++++++++++++++++++++++--------- 2 files changed, 48 insertions(+), 9 deletions(-) diff --git a/frontend/src/client/sdk.gen.ts b/frontend/src/client/sdk.gen.ts index 92ded2bde8..156003aec9 100644 --- a/frontend/src/client/sdk.gen.ts +++ b/frontend/src/client/sdk.gen.ts @@ -23,6 +23,8 @@ import type { LoginResetPasswordResponse, LoginRecoverPasswordHtmlContentData, LoginRecoverPasswordHtmlContentResponse, + PrivateCreateUserData, + PrivateCreateUserResponse, UsersReadUsersData, UsersReadUsersResponse, UsersCreateUserData, @@ -272,6 +274,30 @@ export class LoginService { } } +export class PrivateService { + /** + * Create User + * Create a new user. + * @param data The data for the request. + * @param data.requestBody + * @returns UserPublic Successful Response + * @throws ApiError + */ + public static createUser( + data: PrivateCreateUserData, + ): CancelablePromise { + return __request(OpenAPI, { + method: "POST", + url: "/api/v1/private/users/", + body: data.requestBody, + mediaType: "application/json", + errors: { + 422: "Validation Error", + }, + }) + } +} + export class UsersService { /** * Read Users diff --git a/frontend/src/client/types.gen.ts b/frontend/src/client/types.gen.ts index c2a58d06cb..ee61db0a06 100644 --- a/frontend/src/client/types.gen.ts +++ b/frontend/src/client/types.gen.ts @@ -1,5 +1,20 @@ // This file is auto-generated by @hey-api/openapi-ts +export type app__api__routes__private__UserCreate = { + email: string + password: string + full_name: string + is_verified?: boolean +} + +export type app__models__UserCreate = { + email: string + is_active?: boolean + is_superuser?: boolean + full_name?: string | null + password: string +} + export type Body_login_login_access_token = { grant_type?: string | null username: string @@ -54,14 +69,6 @@ export type UpdatePassword = { new_password: string } -export type UserCreate = { - email: string - is_active?: boolean - is_superuser?: boolean - full_name?: string | null - password: string -} - export type UserPublic = { email: string is_active?: boolean @@ -158,6 +165,12 @@ export type LoginRecoverPasswordHtmlContentData = { export type LoginRecoverPasswordHtmlContentResponse = string +export type PrivateCreateUserData = { + requestBody: app__api__routes__private__UserCreate +} + +export type PrivateCreateUserResponse = UserPublic + export type UsersReadUsersData = { limit?: number skip?: number @@ -166,7 +179,7 @@ export type UsersReadUsersData = { export type UsersReadUsersResponse = UsersPublic export type UsersCreateUserData = { - requestBody: UserCreate + requestBody: app__models__UserCreate } export type UsersCreateUserResponse = UserPublic From 21d1c9e29e8927a06c94e63b4535d9d69b9ac0f4 Mon Sep 17 00:00:00 2001 From: Patrick Arminio Date: Mon, 25 Nov 2024 12:20:48 +0000 Subject: [PATCH 05/18] Add prefix to type --- backend/app/api/routes/private.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/app/api/routes/private.py b/backend/app/api/routes/private.py index 34dcc8a581..e820977b69 100644 --- a/backend/app/api/routes/private.py +++ b/backend/app/api/routes/private.py @@ -13,7 +13,7 @@ router = APIRouter(tags=["private"]) -class UserCreate(BaseModel): +class PrivateUserCreate(BaseModel): email: str password: str full_name: str @@ -21,7 +21,7 @@ class UserCreate(BaseModel): @router.post("/users/", response_model=UserPublic) -def create_user(user_in: UserCreate, session: SessionDep) -> Any: +def create_user(user_in: PrivateUserCreate, session: SessionDep) -> Any: """ Create a new user. """ From 40c7ecfd6d1b1b86021a4010a11829992eea6f3d Mon Sep 17 00:00:00 2001 From: github-actions Date: Mon, 25 Nov 2024 15:21:04 +0000 Subject: [PATCH 06/18] =?UTF-8?q?=E2=9C=A8=20Autogenerate=20frontend=20cli?= =?UTF-8?q?ent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/client/types.gen.ts | 34 ++++++++++++++++---------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/frontend/src/client/types.gen.ts b/frontend/src/client/types.gen.ts index ee61db0a06..67d4abd286 100644 --- a/frontend/src/client/types.gen.ts +++ b/frontend/src/client/types.gen.ts @@ -1,20 +1,5 @@ // This file is auto-generated by @hey-api/openapi-ts -export type app__api__routes__private__UserCreate = { - email: string - password: string - full_name: string - is_verified?: boolean -} - -export type app__models__UserCreate = { - email: string - is_active?: boolean - is_superuser?: boolean - full_name?: string | null - password: string -} - export type Body_login_login_access_token = { grant_type?: string | null username: string @@ -59,6 +44,13 @@ export type NewPassword = { new_password: string } +export type PrivateUserCreate = { + email: string + password: string + full_name: string + is_verified?: boolean +} + export type Token = { access_token: string token_type?: string @@ -69,6 +61,14 @@ export type UpdatePassword = { new_password: string } +export type UserCreate = { + email: string + is_active?: boolean + is_superuser?: boolean + full_name?: string | null + password: string +} + export type UserPublic = { email: string is_active?: boolean @@ -166,7 +166,7 @@ export type LoginRecoverPasswordHtmlContentData = { export type LoginRecoverPasswordHtmlContentResponse = string export type PrivateCreateUserData = { - requestBody: app__api__routes__private__UserCreate + requestBody: PrivateUserCreate } export type PrivateCreateUserResponse = UserPublic @@ -179,7 +179,7 @@ export type UsersReadUsersData = { export type UsersReadUsersResponse = UsersPublic export type UsersCreateUserData = { - requestBody: app__models__UserCreate + requestBody: UserCreate } export type UsersCreateUserResponse = UserPublic From ca352928e40e6410e8f5e8057d8db2613cc77380 Mon Sep 17 00:00:00 2001 From: Patrick Arminio Date: Tue, 26 Nov 2024 11:07:14 +0000 Subject: [PATCH 07/18] Update environment settings --- .github/workflows/generate-client.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/generate-client.yml b/.github/workflows/generate-client.yml index 1cf417ab89..d579f3ab20 100644 --- a/.github/workflows/generate-client.yml +++ b/.github/workflows/generate-client.yml @@ -39,6 +39,7 @@ jobs: - run: uv run bash scripts/generate-client.sh env: VIRTUAL_ENV: backend/.venv + ENVIRONMENT: production - name: Add changes to git run: | git config --local user.email "github-actions@github.com" From 2221ce05a4a59d8fa9710214cdde240ab529cdc0 Mon Sep 17 00:00:00 2001 From: Patrick Arminio Date: Tue, 26 Nov 2024 11:13:42 +0000 Subject: [PATCH 08/18] Add secret key --- .github/workflows/generate-client.yml | 1 + backend/app/core/config.py | 1 + 2 files changed, 2 insertions(+) diff --git a/.github/workflows/generate-client.yml b/.github/workflows/generate-client.yml index d579f3ab20..070a35def1 100644 --- a/.github/workflows/generate-client.yml +++ b/.github/workflows/generate-client.yml @@ -40,6 +40,7 @@ jobs: env: VIRTUAL_ENV: backend/.venv ENVIRONMENT: production + SECRET_KEY: just-for-generating-client - name: Add changes to git run: | git config --local user.email "github-actions@github.com" diff --git a/backend/app/core/config.py b/backend/app/core/config.py index 2370469d7a..71eae567b3 100644 --- a/backend/app/core/config.py +++ b/backend/app/core/config.py @@ -120,3 +120,4 @@ def _enforce_non_default_secrets(self) -> Self: settings = Settings() # type: ignore + From 499d05dbb0ce6f2d5838c1970edbbd0cda747e14 Mon Sep 17 00:00:00 2001 From: Patrick Arminio Date: Tue, 26 Nov 2024 11:26:37 +0000 Subject: [PATCH 09/18] Add missing env --- .github/workflows/generate-client.yml | 2 ++ backend/app/core/config.py | 1 - 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/generate-client.yml b/.github/workflows/generate-client.yml index 070a35def1..b1787b0489 100644 --- a/.github/workflows/generate-client.yml +++ b/.github/workflows/generate-client.yml @@ -41,6 +41,8 @@ jobs: VIRTUAL_ENV: backend/.venv ENVIRONMENT: production SECRET_KEY: just-for-generating-client + POSTGRES_PASSWORD: just-for-generating-client + FIRST_SUPERUSER_PASSWORD: just-for-generating-client - name: Add changes to git run: | git config --local user.email "github-actions@github.com" diff --git a/backend/app/core/config.py b/backend/app/core/config.py index 71eae567b3..2370469d7a 100644 --- a/backend/app/core/config.py +++ b/backend/app/core/config.py @@ -120,4 +120,3 @@ def _enforce_non_default_secrets(self) -> Self: settings = Settings() # type: ignore - From dfbebb43303c39315df32e65e6038cb65c41a87c Mon Sep 17 00:00:00 2001 From: github-actions Date: Tue, 26 Nov 2024 12:18:20 +0000 Subject: [PATCH 10/18] =?UTF-8?q?=E2=9C=A8=20Autogenerate=20frontend=20cli?= =?UTF-8?q?ent?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- frontend/src/client/sdk.gen.ts | 26 -------------------------- frontend/src/client/types.gen.ts | 13 ------------- 2 files changed, 39 deletions(-) diff --git a/frontend/src/client/sdk.gen.ts b/frontend/src/client/sdk.gen.ts index 156003aec9..92ded2bde8 100644 --- a/frontend/src/client/sdk.gen.ts +++ b/frontend/src/client/sdk.gen.ts @@ -23,8 +23,6 @@ import type { LoginResetPasswordResponse, LoginRecoverPasswordHtmlContentData, LoginRecoverPasswordHtmlContentResponse, - PrivateCreateUserData, - PrivateCreateUserResponse, UsersReadUsersData, UsersReadUsersResponse, UsersCreateUserData, @@ -274,30 +272,6 @@ export class LoginService { } } -export class PrivateService { - /** - * Create User - * Create a new user. - * @param data The data for the request. - * @param data.requestBody - * @returns UserPublic Successful Response - * @throws ApiError - */ - public static createUser( - data: PrivateCreateUserData, - ): CancelablePromise { - return __request(OpenAPI, { - method: "POST", - url: "/api/v1/private/users/", - body: data.requestBody, - mediaType: "application/json", - errors: { - 422: "Validation Error", - }, - }) - } -} - export class UsersService { /** * Read Users diff --git a/frontend/src/client/types.gen.ts b/frontend/src/client/types.gen.ts index 67d4abd286..c2a58d06cb 100644 --- a/frontend/src/client/types.gen.ts +++ b/frontend/src/client/types.gen.ts @@ -44,13 +44,6 @@ export type NewPassword = { new_password: string } -export type PrivateUserCreate = { - email: string - password: string - full_name: string - is_verified?: boolean -} - export type Token = { access_token: string token_type?: string @@ -165,12 +158,6 @@ export type LoginRecoverPasswordHtmlContentData = { export type LoginRecoverPasswordHtmlContentResponse = string -export type PrivateCreateUserData = { - requestBody: PrivateUserCreate -} - -export type PrivateCreateUserResponse = UserPublic - export type UsersReadUsersData = { limit?: number skip?: number From d6df2faedbf51f999f8eb15b709642f0627cd9ab Mon Sep 17 00:00:00 2001 From: Patrick Arminio Date: Tue, 26 Nov 2024 17:35:00 +0000 Subject: [PATCH 11/18] Update playwright --- .github/workflows/playwright.yml | 12 ++++++++ frontend/tests/user-settings.spec.ts | 43 +++++++++------------------- frontend/tests/utils/privateApi.ts | 20 +++++++++++++ 3 files changed, 46 insertions(+), 29 deletions(-) create mode 100644 frontend/tests/utils/privateApi.ts diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 8c741221f7..f3bf85fb7e 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -59,6 +59,18 @@ jobs: if: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.debug_enabled == 'true' }} with: limit-access-to-actor: true + - name: Install uv + uses: astral-sh/setup-uv@v3 + with: + version: "0.4.15" + enable-cache: true + - run: uv sync + working-directory: backend + - run: uv run bash scripts/generate-client.sh + env: + VIRTUAL_ENV: backend/.venv + - run: npm ci + working-directory: frontend - run: docker compose build - run: docker compose down -v --remove-orphans - name: Run Playwright tests diff --git a/frontend/tests/user-settings.spec.ts b/frontend/tests/user-settings.spec.ts index a3a8a27490..8175d155c4 100644 --- a/frontend/tests/user-settings.spec.ts +++ b/frontend/tests/user-settings.spec.ts @@ -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) diff --git a/frontend/tests/utils/privateApi.ts b/frontend/tests/utils/privateApi.ts new file mode 100644 index 0000000000..b88b0dda67 --- /dev/null +++ b/frontend/tests/utils/privateApi.ts @@ -0,0 +1,20 @@ +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", + }, + }) +} From 3500d8d50ebf7307833ef0cb7d61216fdc4ad9c0 Mon Sep 17 00:00:00 2001 From: Patrick Arminio Date: Tue, 26 Nov 2024 17:38:29 +0000 Subject: [PATCH 12/18] Test --- frontend/tests/utils/privateApi.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/frontend/tests/utils/privateApi.ts b/frontend/tests/utils/privateApi.ts index b88b0dda67..2c6f73aeb0 100644 --- a/frontend/tests/utils/privateApi.ts +++ b/frontend/tests/utils/privateApi.ts @@ -1,3 +1,4 @@ +// @ts-ignore import { OpenAPI, PrivateService } from "../../src/client" OpenAPI.BASE = `${process.env.VITE_API_URL}` From 8c1a8d6473810e94ecb62d14f054dc7c29a39f07 Mon Sep 17 00:00:00 2001 From: Patrick Arminio Date: Tue, 26 Nov 2024 17:43:10 +0000 Subject: [PATCH 13/18] Fix yaml --- .github/workflows/playwright.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index f3bf85fb7e..f36e1ca1c4 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -70,7 +70,7 @@ jobs: env: VIRTUAL_ENV: backend/.venv - run: npm ci - working-directory: frontend + working-directory: frontend - run: docker compose build - run: docker compose down -v --remove-orphans - name: Run Playwright tests From 245e62a03523203ee06186e9ea63be7ed1edd4dd Mon Sep 17 00:00:00 2001 From: Patrick Arminio Date: Tue, 26 Nov 2024 17:45:05 +0000 Subject: [PATCH 14/18] Fix environment --- .github/workflows/playwright.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index f36e1ca1c4..1e70a382fb 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -69,6 +69,7 @@ jobs: - run: uv run bash scripts/generate-client.sh env: VIRTUAL_ENV: backend/.venv + ENVIRONMENT: local - run: npm ci working-directory: frontend - run: docker compose build From 3cb25ed5b2a79523621701d739a00d1a54bb75c9 Mon Sep 17 00:00:00 2001 From: Patrick Arminio Date: Tue, 26 Nov 2024 17:47:21 +0000 Subject: [PATCH 15/18] Fix --- .github/workflows/playwright.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/playwright.yml b/.github/workflows/playwright.yml index 1e70a382fb..b78f32c623 100644 --- a/.github/workflows/playwright.yml +++ b/.github/workflows/playwright.yml @@ -66,12 +66,11 @@ jobs: enable-cache: true - run: uv sync working-directory: backend + - run: npm ci + working-directory: frontend - run: uv run bash scripts/generate-client.sh env: VIRTUAL_ENV: backend/.venv - ENVIRONMENT: local - - run: npm ci - working-directory: frontend - run: docker compose build - run: docker compose down -v --remove-orphans - name: Run Playwright tests From 609a8e079387f0756e35037718fe04a149ccf964 Mon Sep 17 00:00:00 2001 From: Patrick Arminio Date: Thu, 28 Nov 2024 10:13:19 +0000 Subject: [PATCH 16/18] Ignore tests when building --- frontend/package.json | 2 +- frontend/tests/utils/privateApi.ts | 3 ++- frontend/tsconfig.build.json | 4 ++++ frontend/tsconfig.json | 1 + 4 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 frontend/tsconfig.build.json diff --git a/frontend/package.json b/frontend/package.json index 84f9841485..546028c9a9 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -5,7 +5,7 @@ "type": "module", "scripts": { "dev": "vite", - "build": "tsc && vite build", + "build": "tsc -p tsconfig.build.json && vite build", "lint": "biome check --apply-unsafe --no-errors-on-unmatched --files-ignore-unknown=true ./", "preview": "vite preview", "generate-client": "openapi-ts" diff --git a/frontend/tests/utils/privateApi.ts b/frontend/tests/utils/privateApi.ts index 2c6f73aeb0..b6fa0afe67 100644 --- a/frontend/tests/utils/privateApi.ts +++ b/frontend/tests/utils/privateApi.ts @@ -1,4 +1,5 @@ -// @ts-ignore +// 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}` diff --git a/frontend/tsconfig.build.json b/frontend/tsconfig.build.json new file mode 100644 index 0000000000..13bd2efc21 --- /dev/null +++ b/frontend/tsconfig.build.json @@ -0,0 +1,4 @@ +{ + "extends": "./tsconfig.json", + "exclude": ["tests/**/*.ts"] +} diff --git a/frontend/tsconfig.json b/frontend/tsconfig.json index 355a2a920b..fe494589e3 100644 --- a/frontend/tsconfig.json +++ b/frontend/tsconfig.json @@ -21,5 +21,6 @@ "noFallthroughCasesInSwitch": true }, "include": ["src/**/*.ts", "tests/**/*.ts", "playwright.config.ts"], + "exclude": ["tests/utils/privateApi.ts"], "references": [{ "path": "./tsconfig.node.json" }] } From 8ccd117bfde672eefd65b8186a464bc2e9b143f4 Mon Sep 17 00:00:00 2001 From: Patrick Arminio Date: Thu, 28 Nov 2024 10:25:36 +0000 Subject: [PATCH 17/18] Remove unused exclude --- frontend/tsconfig.json | 1 - 1 file changed, 1 deletion(-) diff --git a/frontend/tsconfig.json b/frontend/tsconfig.json index fe494589e3..355a2a920b 100644 --- a/frontend/tsconfig.json +++ b/frontend/tsconfig.json @@ -21,6 +21,5 @@ "noFallthroughCasesInSwitch": true }, "include": ["src/**/*.ts", "tests/**/*.ts", "playwright.config.ts"], - "exclude": ["tests/utils/privateApi.ts"], "references": [{ "path": "./tsconfig.node.json" }] } From 67372b4b6f55e4d63017b92328ddf2298df734a1 Mon Sep 17 00:00:00 2001 From: Patrick Arminio Date: Mon, 2 Dec 2024 11:53:34 +0000 Subject: [PATCH 18/18] Move tags and prefix to the private router instead --- backend/app/api/main.py | 2 +- backend/app/api/routes/private.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/backend/app/api/main.py b/backend/app/api/main.py index 6c702234da..45e930c4a1 100644 --- a/backend/app/api/main.py +++ b/backend/app/api/main.py @@ -11,4 +11,4 @@ if settings.ENVIRONMENT == "local": - api_router.include_router(private.router, prefix="/private", tags=["private"]) + api_router.include_router(private.router) diff --git a/backend/app/api/routes/private.py b/backend/app/api/routes/private.py index e820977b69..9f33ef1900 100644 --- a/backend/app/api/routes/private.py +++ b/backend/app/api/routes/private.py @@ -10,7 +10,7 @@ UserPublic, ) -router = APIRouter(tags=["private"]) +router = APIRouter(tags=["private"], prefix="/private") class PrivateUserCreate(BaseModel):