Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 21 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Kork & Krone

**Last updated:** 18 November 2026
**Last updated:** 19 November 2026
**Submission:** 4 (working system, ready for feedback on every aspect)
**Status:** In progress. See [Status for submission 4](#status-for-submission-4).

Expand Down Expand Up @@ -56,10 +56,10 @@ yet, depending on when the review is made.
| Filtering and sorting in the user interface | Done | Filter panel, active filters and sorting on `/sok` |
| Wine detail page | Done | Facts, food pairing, the shared average, the rating distribution and student reviews at `/vin/:id` |
| Student reviews (stored in the database) | Done | 0.5–5 stars and an optional comment, saved and shown at once on the wine page. They count in the shared average |
| «Mine anmeldelser» page | Done | Shows the «Vil prøve» list. Own reviews come with login in the interface |
| «Mine anmeldelser» page | Done | Shows the user's «Vil prøve» list from the API, behind login. Own reviews come with the profile page |
| User accounts | Done | Register, log in and log out at `/konto`, with sessions in PostgreSQL and an `httpOnly` cookie |
| Reviews tied to accounts | Done | Writing a review requires login, and the username is shown as the author. Older anonymous reviews are kept as «Anonym student» |
| Favourites, top 4, «Vil prøve» and «Har prøvd» per user | Backend done | API and rules in [API](docs/api.md#wine-lists). The interface comes next |
| Favourites, top 4, «Vil prøve» and «Har prøvd» per user | Done | Heart and bookmark on the wine cards, all three on the wine page. Choosing the top 4 comes with the profile page. See [API](docs/api.md#wine-lists) |
| Demo user for testing | Done | `demo` / `kork-og-krone`, see [Demo user](#demo-user) |
| Larger dataset on the VM | Done | Full version: 100 646 wines and 21 013 536 ratings |
| Continuous integration (CI) | Not yet started | Needs a self-hosted runner |
Expand Down Expand Up @@ -108,9 +108,14 @@ To try the features that need login without registering, log in at `/konto` with
| `demo` | `kork-og-krone` |

The user has favourites with a top 4, wines on «Vil prøve» and «Har prøvd», and some reviews. It exists
on the VM, and locally after `npm run db:seed:demo`, which also resets it if someone has changed it.
Everyone can see the password, so do not store anything private on this user. Searching and reading
reviews never require login.
on the VM, and locally after `npm run db:seed:demo`.

Everyone with the link can log in as `demo` and change its lists and reviews, and the lists are
public. Do not store anything private on this user. If someone has left it in a strange state, run
`npm run db:seed:demo` in `backend/` (on the VM too): it puts the lists, the reviews and the password
back as they were.

Searching and reading reviews never require login.

## Features

Expand All @@ -126,8 +131,8 @@ This section describes what users can do. "Backend" means the API supports the f
| Wine detail page | Done (`wine(id)`) | Done | Name, winery, region, grapes, alcohol, body, acidity, vintages and food pairing in Norwegian. Grapes and food link to the search |
| Student reviews | Done | Done | 0.5–5 stars in half stars and an optional comment, stored in PostgreSQL. Hover the left half of a star for half a star, or use the arrow keys. The page updates at once without a reload. One review per student per wine |
| Shared average and distribution | Done | Done | Student reviews count in the average together with X-Wines, also when sorting and filtering. The wine page shows how many gave each score |
| Wishlist ("Vil prøve") | Done | Done | Saved in the browser and shown on «Mine anmeldelser». The interface moves to the backend list next |
| Favourites, top 4 and «Har prøvd» | Done | Planned | Stored per user and public. «Har prøvd» takes a wine off «Vil prøve», and a saved review marks the wine as tried. See [API](docs/api.md#wine-lists) |
| Wine lists: favourite, «Vil prøve» and «Har prøvd» | Done | Done | Stored per user and public, so they follow the user between browsers. Heart and bookmark on the wine cards, all three on the wine page, and «Vil prøve» on «Mine anmeldelser». The buttons change at once and go back with a message if saving fails. Visitors are sent to log in and back. «Har prøvd» takes a wine off «Vil prøve», and a saved review marks the wine as tried. A «Vil prøve» list from before login moves to the user once. See [API](docs/api.md#wine-lists) |
| Top 4 favourites | Done | Planned | `setTopFavourites` and `topFavourites` in the API. Choosing them comes with the profile page |
| User accounts | Done | Done | Register, log in and log out at `/konto`. Errors are shown next to the field they are about, in Norwegian. Sessions in PostgreSQL with an `httpOnly` cookie |
| Reviews with login | Done | Done | Only logged-in users can write, change or delete a review, and only their own. Visitors see the reviews and a link to log in, which brings them back to the wine. `User.reviews` lists a user's reviews for the profile page |

Expand Down Expand Up @@ -160,6 +165,8 @@ Each row explains what we chose, why, and what else we considered. Added as the
| Pagination | GraphQL connection with an opaque cursor that holds an offset. Pages are merged in the Apollo cache | Simple, and works with every sort order. The frontend never reads the cursor, so we can switch to keyset pagination later without changing it | Keyset pagination: faster deep into large results, but harder to combine with many sort orders |
| Search, filtering and sorting | In the database | Scales to large datasets. The frontend never loads the whole catalogue | Filtering in the browser |
| Rating average | Stored on the wine and recalculated when a review is saved or deleted | Sorting and filtering by rating never has to count millions of rows | Calculating the average for every query |
| List buttons | `myLists` asked for with each wine, read from the cache with `useFragment`, and changed with an optimistic answer | A page of wines needs no extra request, every button for a wine agrees, and a click shows at once | Fetching the lists of each wine separately, or waiting for the API before the button changes |
| Expired session | An Apollo link that fetches `me` again when the API says `UNAUTHENTICATED` | The whole page shows at once that the user is logged out, wherever the error came from | Checking for the error in each feature |
| Batched lookups | DataLoader for reviews and ratings per wine | A page of wines runs one query per field instead of one per wine (the N+1 problem) | One query per wine |
| Search state flow | Field text in React state, debounced into the URL, and the query reads only the URL | One source of truth for the search, so reload, shared links and the back button all give the same result | Sending a request directly from the input |
| Filter panel on small screens | Native `<dialog>` with `showModal()` | The browser handles focus trapping, Escape and returning focus, with no extra JavaScript | A dialog library |
Expand Down Expand Up @@ -236,6 +243,7 @@ Our goal is WCAG 2.1 level AA. We design for users with reduced vision, hearing,
- Giving a review works with the keyboard: the stars are radio buttons, so the arrow keys move through every half star, and each half is at least 24 × 24 px to click (WCAG 2.5.8).
- Loading states are announced in a live region. Errors use `role="alert"` and have a "Prøv igjen" button. The message after saving a review stays in the same live region, so it is announced.
- Click targets are at least 44 × 44 px.
- The list buttons are toggle buttons (`aria-pressed`). On the wine page they have visible text in a named group. On the cards they are icons, with the wine's name in the accessible name («Favoritt Origem Merlot»). A pressed button gets a filled icon and a background, so the state does not rest on colour alone.
- Animations respect `prefers-reduced-motion`.
- No horizontal scrolling at 320 px width (WCAG 1.4.10, reflow).
- Text contrast is at least 4.9:1 in both light and dark mode.
Expand Down Expand Up @@ -298,9 +306,9 @@ and because the test was run over VPN. These are the "before" numbers. Compressi

| Level | Tools | What we test | Number of tests |
|---|---|---|---|
| Unit and components (frontend) | Vitest, React Testing Library, user-event, vitest-axe | URL parameters, formatting, mapping of API data, data hooks, components, the landing page, the wine page with reviews, the wishlist page, loading, empty and error states, and axe on each component | 269 in 28 files |
| Unit and components (frontend) | Vitest, React Testing Library, user-event, vitest-axe | URL parameters, formatting, mapping of API data, data hooks, components, the landing page, the wine page with reviews, the list buttons and «Mine anmeldelser», the cache rules for the lists, an expired session, loading, empty and error states, and axe on each component | 373 in 42 files |
| Unit (backend) | Vitest | Parsing of X-Wines CSV files, building SQL for search, filtering and sorting, review validation, and passwords, sessions and rate limiting | 92 in 11 files (6 skipped: they need a test database) |
| End-to-end | Playwright with axe-core, desktop and mobile | Landing, search and detail pages with a stubbed API: one request per page load, debounce, search, filters, sorting, load more, reload, back button, from search to wine and back, the filter dialog on mobile, no hits, wine not found, API errors, keyboard use, reflow at 320 px, and no axe violations (WCAG 2.1 AA) | 50 (24 tests in 2 browser projects, and 2 for mobile only) |
| End-to-end | Playwright with axe-core, desktop and mobile | Landing, search and detail pages with a stubbed API: one request per page load, debounce, search, filters, sorting, load more, reload, back button, from search to wine and back, the filter dialog on mobile, no hits, wine not found, API errors, keyboard use, reflow at 320 px, the wine lists (also after a reload, with login on the way, and the move of an old list), and no axe violations (WCAG 2.1 AA) | 82 (2 skipped) |
| API | Vitest with Apollo Server (`executeOperation`) | Login, reviews, wine lists, the top 4 and the demo user through real GraphQL requests, with a fake browser per user that keeps the cookie. The review tests run against a separate test database (`TEST_DATABASE_URL`), see [API](docs/api.md#database-tests) | Count again |

Counted on 16 November 2026. The skipped backend tests run the user store against a real database, and need `TEST_DATABASE_URL`.
Expand Down Expand Up @@ -392,9 +400,9 @@ Claude and ChatGPT are the main models used. The usecases for the AI tools are a

- [x] Login in the interface: forms for register and login, and reviews tied to the account instead of the anonymous ID.
- [x] Favourites with a top 4, «Vil prøve» and «Har prøvd» stored per user (backend and API).
- [ ] The lists in the interface: heart, bookmark and «Har prøvd» on the wines.
- [x] The lists in the interface: heart, bookmark and «Har prøvd» on the wines.
- [ ] Profile page with the top 4, the lists and the user's reviews.
- [ ] Wishlist stored in the backend, so it follows the user between devices. The API is ready.
- [x] Wishlist stored in the backend, so it follows the user between devices.
- [ ] Calmer landing page: less text, a separate «Om» page, and a burger menu on mobile.
- [ ] CI, an enforced coverage threshold, and eslint-plugin-jsx-a11y.
- [ ] Measure sustainability and fill in the budget table.
Expand All @@ -407,7 +415,7 @@ Claude and ChatGPT are the main models used. The usecases for the AI tools are a
- [x] Wine detail page.
- [x] Student reviews: GraphQL mutation, database tables, validation, and the new rating shown at once.
- [x] Half stars, a shared average and the rating distribution.
- [x] «Mine anmeldelser» with the wishlist.
- [x] «Mine anmeldelser» with the «Vil prøve» list from the API.
- [x] User accounts in the backend.
- [x] Database migrations.
- [x] Larger dataset on the VM.
Expand Down
12 changes: 12 additions & 0 deletions backend/src/lists/lists-api.db.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ describe.skipIf(!url)('wine lists API (PostgreSQL)', () => {
expect(pageOf(await per.request(LIST, { list: 'WANT_TO_TRY' })).totalCount).toBe(0);
});

it('lets a tried wine go back on «Vil prøve», so it is on both lists', async () => {
// A choice, not an accident: the user may want to taste it again. Only «Har prøvd»
// moves a wine between the two lists, not «Vil prøve».
const [wine] = await api.createWines(1);
const eli = await api.createBrowser('eli');
await eli.request(SET, set(wine, 'TRIED'));

const result = await eli.request(SET, set(wine, 'WANT_TO_TRY'));

expect(listsOf(result).myLists).toEqual(['WANT_TO_TRY', 'TRIED']);
});

it('keeps the lists of each user apart', async () => {
const [wine] = await api.createWines(1);
const anne = await api.createBrowser('anne');
Expand Down
39 changes: 38 additions & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ query {
During development, Vite forwards `/graphql` to the backend. On the VM, Apache forwards
`/project2/graphql`. Use `${import.meta.env.BASE_URL}graphql` as the endpoint so both work.

When any request answers `UNAUTHENTICATED`, the session has ended while the page was open (it
expired, or the user logged out in another tab). A link in `lib/apollo.ts` then fetches `me` again,
so the header, the review form and the list buttons all show that nobody is logged in. After a
login or logout, `AuthProvider` calls `resetStore()`, which empties the cache and fetches the
queries on the page again, `me` included, with the new cookie.

## Tests

`npm test` in `backend/` runs the unit tests. The API tests that need PostgreSQL are described
Expand Down Expand Up @@ -227,6 +233,7 @@ The table `user_wine` has one row per user, list and wine: `id`, `user_id`, `win
|---|---|
| A wine is at most once on each list | `UNIQUE (user_id, list, wine_id)`. Adding it again changes nothing |
| A wine can be on several lists, such as a favourite that is also tried | No rule against it |
| A tried wine can go back on «Vil prøve», and is then on both | A choice: the user may want to taste it again, for example another vintage. Only putting a wine on «Har prøvd» moves it, not the other way. Tested in `lists-api.db.test.ts` and `lib/wineLists.test.ts` |
| «Har prøvd» takes the wine off «Vil prøve» | `setWineInList` in `wine-lists.ts`, in the same transaction |
| A saved review puts the wine on «Har prøvd» | `saveReview`, in the same transaction as the review. Deleting the review keeps the wine on «Har prøvd» |
| The top 4 has at most four wines, each once, all favourites | `setTopFavourites` checks and gives a clear error. The database checks it too: `top_position BETWEEN 1 AND 4`, a unique index on `(user_id, top_position)`, and `CHECK (top_position IS NULL OR list = 'FAVOURITE')` |
Expand Down Expand Up @@ -275,6 +282,24 @@ Choices and why:
| `lists/lists-api.db.test.ts` | Through Apollo Server against PostgreSQL: login required, adding and removing twice, several lists, «Har prøvd» takes the wine off «Vil prøve», users kept apart, unknown wines and lists, pages that do not skip, one query for `myLists` on a page of 24, the top 4 rules and order, two changes at once, the database constraints, and that a saved review marks the wine as tried |
| `demo/demo-user.db.test.ts` | The demo user: the documented password works, the data follows the rules, the averages are updated, and running it again gives the same state |

### In the frontend

The code is in `frontend/src/features/lists/`.

| Part | What it does |
|---|---|
| `myLists` in the wine queries | The search, the landing page, the wine page and «Mine anmeldelser» ask for `myLists` with each wine, so a page needs no extra request for the buttons |
| `useWineList(wineId, list)` | Returns `{ isSaved, toggle, error }`. Reads `myLists` from the cache with `useFragment`, so every button for the same wine agrees. The button changes at once (`optimisticResponse`, with the same rules as the API in `lib/wineLists.ts`), and goes back with a Norwegian message if the request fails. A visitor is sent to `/konto` and back |
| `WineListButtons` | «Favoritt», «Vil prøve» and «Har prøvd» on the wine page: toggle buttons (`aria-pressed`) with visible text, in a named group |
| `WineCardListButtons` | The heart and the bookmark on each wine card. Icons only, with the wine's name in the accessible name |
| `useMyWineList(list)` | One of the user's lists, 24 wines per page, for «Mine anmeldelser» (behind login) and later the profile |
| `updateListPages` | Keeps the cached list pages in step with a change: a wine that left a list is taken out at once, and a list the wine joined is fetched again the next time it is shown, with the new wine first |
| `useLegacyWishlistImport` | Moves a «Vil prøve» list stored in the browser before login (`kk:wishlist`) to the user once, oldest first. A wine that no longer exists is skipped. The old list is only removed when every wine has been handled |

Frontend tests: `lib/wineLists.test.ts`, `features/lists/**/*.test.ts(x)`, `components/ui/WineCard.test.tsx`,
`features/my/MyPage.test.tsx`, and `e2e/lists.spec.ts`, which runs the whole flow against a small fake
API that remembers the lists.

## Demo user

`npm run db:seed:demo` in `backend/` creates the user **`demo`** with the password **`kork-og-krone`**,
Expand All @@ -299,13 +324,25 @@ cd backend
DATABASE_URL=postgresql://vinmonopolet_app:PASSWORD@localhost:5432/vinmonopolet_test npm run db:migrate
```

The migration uses `DATABASE_URL`, so it is set to the test database for this one command. The
variable set in the command wins over the one in `backend/.env`. On Windows PowerShell, which does
not understand `NAME=value command`, set it first and remove it afterwards, so the next migration
goes to your own database again:

```powershell
$env:DATABASE_URL="postgresql://vinmonopolet_app:PASSWORD@localhost:5432/vinmonopolet_test"
npm run db:migrate
Remove-Item Env:DATABASE_URL
```

Run the same command for the test database every time you pull a new migration.

Then run all tests, including the database tests:

```bash
TEST_DATABASE_URL=postgresql://vinmonopolet_app:PASSWORD@localhost:5432/vinmonopolet_test npm test
```

On Windows PowerShell, set the variable first: `$env:TEST_DATABASE_URL="postgresql://..."`, then `npm test`.
Run the migration again after pulling a new migration.

See [manual testing](manual-testing.md) for how to test users and user data by hand.
Loading