Move every handler from /api/* to /api/v1/*. /api/* is now reserved for
future versioning.
Standardise the error response shape across the API as
{"error": {"code": "snake_case", "message": "..."}}. AppError gains a
`code()` whose top-level variants are matched exhaustively without a
wildcard — new variants are a compile error until coded. 500-class
responses always emit the fixed "internal error" string and log the
real cause via tracing only.
Lock in the list pagination envelope as {"items": [...], "page": {
"limit", "offset", "total"}} and apply it to GET /api/v1/mangas. `total`
serialises as null until feat/list-search-polish lands an indexed count.
The frontend client parses the envelope into ApiError.code with an
http_error fallback for non-JSON bodies. listMangas now returns the
paged shape; the root route consumes .items. New client.test.ts covers
envelope parsing and the fallback paths.
Lockstep version bump to 0.2.0.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
60 lines
2.2 KiB
TypeScript
60 lines
2.2 KiB
TypeScript
import { test, expect } from '@playwright/test';
|
|
|
|
// These E2E tests run against the SvelteKit dev server, which proxies /api
|
|
// to the backend. Playwright starts vite via `webServer` (see
|
|
// playwright.config.ts) unless E2E_BASE_URL points at a different deployment.
|
|
//
|
|
// Routes are mocked at the page level so the journeys are deterministic and
|
|
// don't require a live backend.
|
|
|
|
const emptyPage = { items: [], page: { limit: 50, offset: 0, total: null } };
|
|
|
|
test('home page renders the Mangalord heading and search input', async ({ page }) => {
|
|
await page.route('**/api/v1/mangas*', async (route) => {
|
|
await route.fulfill({
|
|
status: 200,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify(emptyPage)
|
|
});
|
|
});
|
|
|
|
await page.goto('/');
|
|
await expect(page.getByRole('link', { name: 'Mangalord' })).toBeVisible();
|
|
await expect(page.getByTestId('search-input')).toBeVisible();
|
|
await expect(page.getByTestId('empty')).toContainText('No mangas yet');
|
|
});
|
|
|
|
test('search updates the manga list', async ({ page }) => {
|
|
let lastSearch: string | null = null;
|
|
await page.route('**/api/v1/mangas*', async (route) => {
|
|
const url = new URL(route.request().url());
|
|
lastSearch = url.searchParams.get('search');
|
|
const items =
|
|
lastSearch === 'berserk'
|
|
? [
|
|
{
|
|
id: 'b1',
|
|
title: 'Berserk',
|
|
author: 'Kentaro Miura',
|
|
description: null,
|
|
cover_image_path: null,
|
|
created_at: '2026-01-01T00:00:00Z',
|
|
updated_at: '2026-01-01T00:00:00Z'
|
|
}
|
|
]
|
|
: [];
|
|
await route.fulfill({
|
|
status: 200,
|
|
contentType: 'application/json',
|
|
body: JSON.stringify({ items, page: { limit: 50, offset: 0, total: null } })
|
|
});
|
|
});
|
|
|
|
await page.goto('/');
|
|
await page.getByTestId('search-input').fill('berserk');
|
|
await page.getByRole('button', { name: 'Search' }).click();
|
|
|
|
await expect(page.getByTestId('manga-list')).toContainText('Berserk');
|
|
expect(lastSearch).toBe('berserk');
|
|
});
|