From 7277c6f9b4269e9ec9a2cc15c7ad35a8909c8010 Mon Sep 17 00:00:00 2001 From: Kristian Date: Thu, 29 Oct 2026 18:52:15 +0100 Subject: [PATCH 1/7] fixed test command --- README.md | 6 ++++-- apps/backend/package.json | 2 +- package.json | 5 +++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index fd03ca1..fcf05c9 100644 --- a/README.md +++ b/README.md @@ -81,8 +81,10 @@ Frontend: http://localhost:3000 · GraphQL API: http://localhost:3001 | `pnpm build` | Build all workspaces that define a build | | `pnpm typecheck` | Typecheck all workspaces | | `pnpm lint` / `pnpm format` / `pnpm check` | Lint, auto-fix format, and check formatting | -| `pnpm test` | Run the frontend component tests once | -| `pnpm test:watch` | Re-run tests while developing | +| `pnpm test` | Run frontend and backend tests | +| `pnpm test:frontend` | Run only the frontend component tests once | +| `pnpm test:frontend:watch` | Re-run frontend tests while developing | +| `pnpm test:backend` | Run only the backend tests once | | `pnpm db:setup` | Provision PostgreSQL natively on Ubuntu (see below) | | `pnpm db:generate` | Regenerate the Prisma client and Pothos types | | `pnpm db:push` | Push the Prisma schema to the database (prototyping) | diff --git a/apps/backend/package.json b/apps/backend/package.json index c44c870..a955de4 100644 --- a/apps/backend/package.json +++ b/apps/backend/package.json @@ -5,7 +5,7 @@ "scripts": { "dev": "dotenv -e .env -- tsx watch src/index.ts", "start": "dotenv -e .env -- tsx src/index.ts", - "test:e2e": "dotenv -e .env -- playwright test", + "test": "dotenv -e .env -- playwright test", "typecheck": "tsc --noEmit" }, "dependencies": { diff --git a/package.json b/package.json index 9b0bf2d..aa1347d 100644 --- a/package.json +++ b/package.json @@ -8,9 +8,10 @@ "build": "pnpm --recursive run build", "typecheck": "pnpm --recursive run typecheck", "lint": "eslint .", + "test": "pnpm --parallel --recursive run test", "test:frontend": "pnpm --filter @t09-project-2/frontend run test", - "test:backend": "pnpm --filter @t09-project-2/backend run test:e2e", - "test:watch": "pnpm --filter @t09-project-2/frontend run test:watch", + "test:frontend:watch": "pnpm --filter @t09-project-2/frontend run test:watch", + "test:backend": "pnpm --filter @t09-project-2/backend run test", "format": "prettier --write . && eslint . --fix", "check": "prettier --check .", "generate-routes": "pnpm --filter @t09-project-2/frontend run generate-routes", From bdedb07b8b100301bc297f3976d312ee8c19d05d Mon Sep 17 00:00:00 2001 From: Kristian Date: Thu, 29 Oct 2026 18:56:13 +0100 Subject: [PATCH 2/7] fixed failing tests --- .../src/components/__tests__/AddReviewDialog.test.tsx | 6 +++--- apps/frontend/src/components/__tests__/Map.test.tsx | 3 +++ 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/apps/frontend/src/components/__tests__/AddReviewDialog.test.tsx b/apps/frontend/src/components/__tests__/AddReviewDialog.test.tsx index ae3d639..d80db54 100644 --- a/apps/frontend/src/components/__tests__/AddReviewDialog.test.tsx +++ b/apps/frontend/src/components/__tests__/AddReviewDialog.test.tsx @@ -38,7 +38,7 @@ async function fillValidReview( ) { await user.type(screen.getByLabelText('Your name'), 'Kari') await user.type(screen.getByLabelText('Your review'), 'Great beer') - await user.click(screen.getByRole('radio', { name: '4 out of 5 stars' })) + await user.click(screen.getByRole('radio', { name: '4 out of 5 harps' })) } describe('AddReviewDialog', () => { @@ -87,7 +87,7 @@ describe('AddReviewDialog', () => { const { user, dialog } = await openDialog() await user.type(screen.getByLabelText('Your name'), 'Kari') - await user.click(screen.getByRole('radio', { name: '4 out of 5 stars' })) + await user.click(screen.getByRole('radio', { name: '4 out of 5 harps' })) submitForm(dialog) expect(await screen.findByRole('alert')).toHaveTextContent( @@ -109,7 +109,7 @@ describe('AddReviewDialog', () => { await user.type(screen.getByLabelText('Your name'), ' Kari ') await user.type(screen.getByLabelText('Your review'), ' Great beer ') - await user.click(screen.getByRole('radio', { name: '4 out of 5 stars' })) + await user.click(screen.getByRole('radio', { name: '4 out of 5 harps' })) submitForm(dialog) diff --git a/apps/frontend/src/components/__tests__/Map.test.tsx b/apps/frontend/src/components/__tests__/Map.test.tsx index 2c4ac7c..86963a8 100644 --- a/apps/frontend/src/components/__tests__/Map.test.tsx +++ b/apps/frontend/src/components/__tests__/Map.test.tsx @@ -58,6 +58,9 @@ vi.mock('react-leaflet', () => ({
{children}
), useMap: () => ({ flyTo }), + Tooltip: ({ children }: { children: ReactNode }) => ( +
{children}
+ ), })) vi.mock('leaflet', () => ({ From ed440cf7c3d5b3422b198574628e61a8c2913a9a Mon Sep 17 00:00:00 2001 From: Kristian Date: Thu, 29 Oct 2026 19:08:55 +0100 Subject: [PATCH 3/7] format --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index fcf05c9..78f6f24 100644 --- a/README.md +++ b/README.md @@ -81,10 +81,10 @@ Frontend: http://localhost:3000 · GraphQL API: http://localhost:3001 | `pnpm build` | Build all workspaces that define a build | | `pnpm typecheck` | Typecheck all workspaces | | `pnpm lint` / `pnpm format` / `pnpm check` | Lint, auto-fix format, and check formatting | -| `pnpm test` | Run frontend and backend tests | -| `pnpm test:frontend` | Run only the frontend component tests once | -| `pnpm test:frontend:watch` | Re-run frontend tests while developing | -| `pnpm test:backend` | Run only the backend tests once | +| `pnpm test` | Run frontend and backend tests | +| `pnpm test:frontend` | Run only the frontend component tests once | +| `pnpm test:frontend:watch` | Re-run frontend tests while developing | +| `pnpm test:backend` | Run only the backend tests once | | `pnpm db:setup` | Provision PostgreSQL natively on Ubuntu (see below) | | `pnpm db:generate` | Regenerate the Prisma client and Pothos types | | `pnpm db:push` | Push the Prisma schema to the database (prototyping) | From 3877404e260fadfb7ac3849ec49f9afe51c33127 Mon Sep 17 00:00:00 2001 From: Kristian Date: Thu, 29 Oct 2026 19:26:11 +0100 Subject: [PATCH 4/7] reuseExistingServer: true --- apps/backend/playwright.config.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/backend/playwright.config.ts b/apps/backend/playwright.config.ts index ae30a41..4786cb3 100644 --- a/apps/backend/playwright.config.ts +++ b/apps/backend/playwright.config.ts @@ -2,7 +2,7 @@ import { defineConfig } from '@playwright/test' import { fileURLToPath } from 'node:url' const apiBaseURL = ( - process.env.API_BASE_URL ?? 'http://127.0.0.1:3001' + process.env.API_BASE_URL ?? 'http://127.0.0.1:1001' ).replace(/\/+$/, '') const managesLocalServer = process.env.API_BASE_URL === undefined @@ -21,7 +21,7 @@ export default defineConfig({ command: 'pnpm run start', cwd: fileURLToPath(new URL('.', import.meta.url)), url: `${apiBaseURL}/?query=%7B__typename%7D`, - reuseExistingServer: !process.env.CI, + reuseExistingServer: true, timeout: 120_000, }, } From c94e6129f0515439af04fabb64d3aa7c998d4f4e Mon Sep 17 00:00:00 2001 From: Kristian Numme Date: Thu, 29 Oct 2026 19:35:24 +0100 Subject: [PATCH 5/7] Update playwright.config.ts --- apps/backend/playwright.config.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/backend/playwright.config.ts b/apps/backend/playwright.config.ts index 4786cb3..d618eb7 100644 --- a/apps/backend/playwright.config.ts +++ b/apps/backend/playwright.config.ts @@ -2,7 +2,7 @@ import { defineConfig } from '@playwright/test' import { fileURLToPath } from 'node:url' const apiBaseURL = ( - process.env.API_BASE_URL ?? 'http://127.0.0.1:1001' + process.env.API_BASE_URL ?? 'http://127.0.0.1:3001' ).replace(/\/+$/, '') const managesLocalServer = process.env.API_BASE_URL === undefined From c7c8cebc3acd425bbcb23d5fe6e06ee0d414195e Mon Sep 17 00:00:00 2001 From: Kristian Date: Thu, 29 Oct 2026 19:41:28 +0100 Subject: [PATCH 6/7] fix typecheck --- apps/frontend/src/components/__tests__/Map.test.tsx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/frontend/src/components/__tests__/Map.test.tsx b/apps/frontend/src/components/__tests__/Map.test.tsx index 86963a8..e9eaccf 100644 --- a/apps/frontend/src/components/__tests__/Map.test.tsx +++ b/apps/frontend/src/components/__tests__/Map.test.tsx @@ -28,7 +28,7 @@ interface CircleMarkerProps { } interface PopupProps { - children: ReactNode + children?: ReactNode } vi.mock('react-leaflet', () => ({ @@ -58,7 +58,7 @@ vi.mock('react-leaflet', () => ({
{children}
), useMap: () => ({ flyTo }), - Tooltip: ({ children }: { children: ReactNode }) => ( + Tooltip: ({ children }: PopupProps) => (
{children}
), })) From 71f390567f416ee211ad7e7edbbc24c6c6d6aa4a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henry=20Gr=C3=A6sberg?= Date: Thu, 29 Oct 2026 20:04:03 +0100 Subject: [PATCH 7/7] ci: write env files for backend tests and prepare test database The backend test script loads apps/backend/.env, but CI only wrote packages/db/.env, so DATABASE_URL was undefined and Playwright found no tests. Write both env files like the deploy workflow does, and apply migrations plus seed data so the e2e tests run against a known dataset. --- .github/workflows/ci.yaml | 18 ++++++++++++++---- README.md | 8 +++++--- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 11c837c..36b63d5 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -9,6 +9,10 @@ on: - opened - synchronize +env: + # Test database on the self-hosted runner + DATABASE_URL: postgresql://ci:ci@localhost:5432/ci + jobs: lint-format-and-test: runs-on: [self-hosted] @@ -21,14 +25,20 @@ jobs: - name: Install dependencies run: pnpm install --frozen-lockfile - - name: Write env file - run: > - printf 'DATABASE_URL="postgresql://ci:ci@localhost:5432/ci"\n' > - packages/db/.env + - name: Write env files + run: | + printf 'DATABASE_URL="%s"\n' "$DATABASE_URL" > apps/backend/.env + cp apps/backend/.env packages/db/.env - name: Generate Prisma client run: pnpm --filter @t09-project-2/db run db:generate + - name: Apply database migrations + run: pnpm --filter @t09-project-2/db run db:deploy + + - name: Seed test database + run: pnpm --filter @t09-project-2/db run db:seed + - name: Check formatting run: pnpm check diff --git a/README.md b/README.md index 78f6f24..d4d10a0 100644 --- a/README.md +++ b/README.md @@ -118,16 +118,18 @@ pnpm check # Runs the prettier formatter in check mode, so will not write to any The frontend uses [Vitest](https://vitest.dev/) with [Testing Library](https://testing-library.com/docs/react-testing-library/intro/) and jsdom. Component tests live in `apps/frontend/src/components/__tests__`, and shared fixtures and providers are in `apps/frontend/src/test`. The tests cover rendering, user interaction, form validation, routing and the map wrappers without needing a running backend. ```bash -pnpm test # Run all component tests once -pnpm test:watch # Re-run tests while developing +pnpm test:frontend # Run all component tests once +pnpm test:frontend:watch # Re-run tests while developing ``` The backend API has Playwright end-to-end tests that send requests to the running GraphQL API. They require PostgreSQL, the backend `.env`, and the sample data created by `pnpm db:seed` (which replaces existing database rows). The test command starts the backend automatically; set `API_BASE_URL` to use an already-running API instead. ```bash -pnpm test:e2e:backend +pnpm test:backend ``` +`pnpm test` runs the frontend component tests and the backend end-to-end tests together. CI applies the migrations and seeds the test database before running it. + ### Deployment The deployment of both the backend and frontend is automated using the github action found in `./.github/workflows/deploy-to-vm.yaml`