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
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ dist-ssr

# Local Claude Code settings
.claude/

# Playwright and coverage
test-results/
playwright-report/
blob-report/
coverage/
24 changes: 14 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
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 user's «Vil prøve» list from the API, behind login. Own reviews come with the profile page |
| «Min side» (profile) | Done | The top 4 in its own frame, the newest wines on each list with «Se alle», and the newest reviews, behind login. A page for each list, and for all reviews (newest or oldest first) |
| 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 | 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) |
| 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, and «Endre topp 4» on «Min side». 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 @@ -131,8 +131,9 @@ 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 |
| 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 |
| 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 each list on «Min side». 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 | Done | Shown in its own frame on «Min side», with four numbered places. «Endre topp 4» chooses and orders them with buttons that work with the keyboard and a screen reader, without drag and drop |
| «Min side» | Done | Done | `/mine` with the top 4, the lists and the reviews, a page for each list at `/mine/favoritter`, `/mine/vil-prove` and `/mine/har-provd`, and `/mine/dommer`, newest or oldest first. Behind login |
| 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 @@ -166,6 +167,7 @@ Each row explains what we chose, why, and what else we considered. Added as the
| 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 |
| Top 4 editor | Buttons to move, add and take out, with a live region and focus kept on the button | Works the same with a keyboard, a screen reader, a switch and a finger, and is simple to test | Drag and drop, which needs a second way to do the same for keyboard and screen reader users |
| 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 |
Expand Down Expand Up @@ -242,8 +244,10 @@ Our goal is WCAG 2.1 level AA. We design for users with reduced vision, hearing,
- Ratings are always shown as text, for example "4,6 av 5 · 23 dommer". The stars have a text alternative, so a screen reader reads «3,5 av 5 stjerner» instead of five images.
- 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.
- Click targets are at least 44 × 44 px. The heart and the bookmark on the wine cards are 44 × 40 px, so they sit closer together; that is still well above the 24 px WCAG 2.5.8 asks for.
- 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.
- «Endre topp 4» uses buttons only, no drag and drop: «Flytt opp», «Flytt ned», «Ta ut» and «Legg til», named with the wine. Each change is read out, focus never jumps to the top of the page, and a button that does nothing right now (`aria-disabled`) can still have focus.
- When a wine disappears from a list on «Min side», a live region says so and focus moves to the list's heading.
- 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 @@ -306,9 +310,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 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, 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) |
| 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, «Min side», the list pages, the reviews page and «Endre topp 4», the cache rules for the lists, an expired session, loading, empty and error states, and axe on each component | 421 in 46 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 | 147 in 17 files (42 tests, 4 files 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, the wine lists (also after a reload, with login on the way, and the move of an old list), «Min side» from login to logout with the top 4 chosen with the keyboard, and no axe violations (WCAG 2.1 AA) | 86 (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 @@ -401,7 +405,7 @@ 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).
- [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.
- [x] Profile page («Min side») with the top 4, the lists and the user's reviews.
- [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.
Expand All @@ -415,7 +419,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 «Vil prøve» list from the API.
- [x] «Min side» with the top 4, the lists and the reviews, and a page for each.
- [x] User accounts in the backend.
- [x] Database migrations.
- [x] Larger dataset on the VM.
Expand Down
3 changes: 2 additions & 1 deletion backend/src/lists/wine-lists.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// The wine lists and their rules, and the SQL that changes and reads them.
// The database checks what it can (see the user_wine migration); the rules that span two
// lists are here, and run in one transaction.
// lists are here, and run in one transaction. The frontend repeats them in
// frontend/src/lib/wineLists.ts, so a button can change before the answer: change both together.
import type { PoolClient } from 'pg';
import { decodeIdCursor } from '../connection';
import { pool } from '../db';
Expand Down
31 changes: 20 additions & 11 deletions backend/src/resolvers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -206,21 +206,30 @@ export const resolvers = {

// User comes from auth/resolvers.ts. Fields that belong to other features are added here.
User: {
// Newest written first. The order is by id, which an edit does not change, so editing a
// review while someone pages through the list neither skips nor repeats one.
async reviews(user: { id: string }, args: { first?: number | null; after?: string | null }) {
// By when the review was given, newest or oldest first. The order is by id, which an edit
// does not change, so editing a review while someone pages through the list neither skips
// nor repeats one. The cursor is the id of the last review on the page, in both orders.
async reviews(
user: { id: string },
args: { first?: number | null; after?: string | null; order?: 'NEWEST' | 'OLDEST' | null },
) {
const userId = Number(user.id);
const first = limitReviews(args.first, 10);
const before = decodeIdCursor(args.after);
// The index review_user_id covers both queries.
const [list, count] = await Promise.all([
pool.query<ReviewRow>(
`SELECT * FROM review
const afterId = decodeIdCursor(args.after);
// Fixed SQL for each order, never text from the request. The index review_user_id
// (user_id, id DESC) covers both, read forwards or backwards.
const page =
args.order === 'OLDEST'
? `SELECT * FROM review
WHERE user_id = $1 AND ($2::integer IS NULL OR id > $2)
ORDER BY id ASC
LIMIT $3`
: `SELECT * FROM review
WHERE user_id = $1 AND ($2::integer IS NULL OR id < $2)
ORDER BY id DESC
LIMIT $3`,
[userId, before, first + 1],
),
LIMIT $3`;
const [list, count] = await Promise.all([
pool.query<ReviewRow>(page, [userId, afterId, first + 1]),
pool.query<{ total: number }>('SELECT count(*)::int AS total FROM review WHERE user_id = $1', [
userId,
]),
Expand Down
40 changes: 38 additions & 2 deletions backend/src/review-api.db.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ const url = process.env.TEST_DATABASE_URL;
const SAVE = `mutation Save($input: ReviewInput!) { saveReview(input: $input) { id rating comment author } }`;
const DELETE = `mutation Delete($wineId: ID!) { deleteReview(wineId: $wineId) }`;
const MINE = `query Mine($wineId: ID!) { myReview(wineId: $wineId) { id rating comment author } }`;
const MY_REVIEWS = `query MyReviews($first: Int, $after: String) {
me { reviews(first: $first, after: $after) {
const MY_REVIEWS = `query MyReviews($first: Int, $after: String, $order: ReviewOrder) {
me { reviews(first: $first, after: $after, order: $order) {
totalCount
edges { node { rating wine { id } } }
pageInfo { hasNextPage endCursor }
Expand Down Expand Up @@ -215,6 +215,42 @@ describe.skipIf(!url)('reviews API (PostgreSQL)', () => {
expect(second.edges.map((edge) => edge.node)).toEqual([{ rating: 5, wine: { id: wineId } }]);
});

it('lists the oldest first with order: OLDEST, one page at a time, without skipping', async () => {
const eva = await createBrowser('eva');
await eva.request(SAVE, save(4));
await eva.request(SAVE, { input: { wineId: otherWineId, rating: 2 } });

const first = pageOf(await eva.request(MY_REVIEWS, { first: 1, order: 'OLDEST' }));
expect(first.totalCount).toBe(2);
expect(first.edges.map((edge) => edge.node)).toEqual([{ rating: 4, wine: { id: wineId } }]);
expect(first.pageInfo.hasNextPage).toBe(true);

// Editing the review already shown neither moves it nor repeats it on the next page.
await eva.request(SAVE, save(5));

const second = pageOf(
await eva.request(MY_REVIEWS, { first: 1, after: first.pageInfo.endCursor, order: 'OLDEST' }),
);
expect(second.edges.map((edge) => edge.node)).toEqual([{ rating: 2, wine: { id: otherWineId } }]);
expect(second.pageInfo.hasNextPage).toBe(false);
});

it('lists the newest first when the order is NEWEST or left out', async () => {
const ole = await createBrowser('ole');
await ole.request(SAVE, save(4));
await ole.request(SAVE, { input: { wineId: otherWineId, rating: 2 } });

for (const order of [undefined, 'NEWEST']) {
const page = pageOf(await ole.request(MY_REVIEWS, { order }));
expect(page.edges.map((edge) => edge.node.wine.id)).toEqual([otherWineId, wineId]);
}
});

it('rejects an order that does not exist', async () => {
const per = await createBrowser('per');
expect(codeOf(await per.request(MY_REVIEWS, { order: 'BEST' }))).toBe('BAD_USER_INPUT');
});

it('rejects a cursor that was not made by the API', async () => {
const ina = await createBrowser('ina');
expect(codeOf(await ina.request(MY_REVIEWS, { after: 'not-a-cursor' }))).toBe('BAD_USER_INPUT');
Expand Down
15 changes: 12 additions & 3 deletions backend/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,10 +116,19 @@ export const typeDefs = `#graphql
pageInfo: PageInfo!
}
"The order of a user's reviews: by when each review was first given (an edit does not move it)."
enum ReviewOrder {
NEWEST
OLDEST
}
# User is defined in auth/schema.ts. Reviews are public, so this works for any user.
extend type User {
"The user's reviews, newest first. Use pageInfo.endCursor as 'after' to load more."
reviews(first: Int = 10, after: String): ReviewConnection!
"""
The user's reviews, by when they were given: newest first, or oldest first. Use
pageInfo.endCursor as 'after' to load more, with the same order.
"""
reviews(first: Int = 10, after: String, order: ReviewOrder = NEWEST): ReviewConnection!
}
"The author is always the logged-in user, so it is not part of the input."
Expand Down Expand Up @@ -164,4 +173,4 @@ export const typeDefs = `#graphql
"""
deleteReview(wineId: ID!): Boolean!
}
`;
`;
Loading