Skip to content

Conversation

williasc
Copy link
Member

All our Playwright tests answered the API calls with made-up data, so no test went from the browser to the database. This adds 11 tests that use the real backend and a PostgreSQL test database.

What the tests cover

  • The main flow: search, open a wine, save a review and find it on "Min side", also after a reload.
  • Users: a new user stays logged in after a reload, can log out and in again, gets an error with a wrong password, and cannot take a username that is in use.
  • Search: words from the name, no hits, filter and sorting on the whole catalogue, and "Last inn flere" through all 100 test wines without showing a wine twice.
  • Lists: a favourite is there when the same user logs in from another browser, and "Har prøvd" takes the wine off "Vil prøve".
  • Reviews: two users review the same wine, and the average follows when a review is added, changed and deleted.

How to run them

They need the same test database as the backend's database tests (see "Database tests" in docs/api.md):

cd frontend
TEST_DATABASE_URL=postgresql://vinmonopolet_app:PASSWORD@localhost:5432/vinmonopolet_test npm run e2e:api

npm run check -- --e2e runs them too. Without TEST_DATABASE_URL they are skipped, so the check still works for someone who has not made the test database.

How it works

  • The tests are in frontend/e2e-api/, with their own config in frontend/playwright.api.config.ts.
  • Playwright starts its own backend on port 3101 and its own frontend on port 4174. It never reuses a server that is already running, so the tests cannot write to the database in backend/.env.
  • Before the tests, the backend runs the migrations, loads the 100 test wines and deletes the users from earlier runs (new script npm run db:e2e:clean).
  • Each test makes its own user with a name that starts with e2e_, so the tests can run at the same time.
  • vite.config.ts now reads the backend address from BACKEND_URL. Without it, the address is http://localhost:3001 as before.

Testing

npm run check -- --e2e passes with TEST_DATABASE_URL set, and the new tests passed three runs in a row. Without the variable, the 11 tests are skipped and the check passes.

The README test table and docs/api.md describe the new tests.

Closes #116

@williasc williasc requested review from manerlan and siverne November 25, 2026 14:59
@williasc williasc requested a review from a team as a code owner November 25, 2026 14:59
@williasc williasc linked an issue Nov 25, 2026 that may be closed by this pull request
2 tasks
Copy link
Member

@siverne siverne left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ran it locally with TEST_DATABASE_URL: 11 passed. Approving!

The separate ports and reuseExistingServer: false mean the tests can't touch the database in .env, and the cleanup only removes e2e_ users.

Not blocking: db:e2e:clean deletes e2e_ users in whatever DATABASE_URL points to, so running it by hand would hit your own database, or production on the VM, where anyone can register as "e2e_something". A guard that refuses to run unless the database name ends in _test would make it safe.

@siverne siverne merged commit bf76c9d into main Nov 25, 2026
@siverne siverne deleted the 116-one-end-to-end-test-against-the-real-backend branch November 25, 2026 15:15
Sign in to join this conversation on GitHub.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

One end-to-end test against the real backend
2 participants