Files
KomediruzeckiandGitHub e5931959c1 Retire the Express backend; run e2e against the Worker (#428)
* chore: retire the Express backend, run e2e against the Worker

backend/ had not shipped for a long time. ci.yml stopped testing it,
nothing deploys it, browser-only mode is IndexedDB and cloud mode is the
Worker. But it was a complete server — routes, models, repositories, its
own test suite — and it kept attracting fixes that could never reach a
user.

The one thing holding it in the tree was e2e.yml. 35 Playwright specs
drive the real built frontend, and something had to answer /api. That is
now wrangler dev against a local D1: the runtime that actually serves the
app, so the suite finally tests what ships.

playwright.config.ts starts both servers itself — wrangler on :8787 after
d1:migrate:local, then vite on :3800 with its proxy pinned at it — and
runs a setup project first. So `pnpm run test:e2e` does the whole thing
locally, which the four curl commands it replaces never did.

global.setup.ts registers the fixture account through the real API, marks
it verified, puts it on a plan without a profile cap, seeds the fixture
profile and signs in ONCE. Every context inherits that storageState.
Signing in per context was spending the per-IP login budget on machines
with enough cores to run a context per CPU. It also clears rate_limits
first: the local database survives between runs and so did the counters,
so the seventh run of an afternoon failed at sign-in with a 429.

e2e-seed.ts is the dataset, written where the tests are instead of inside
a server's seed routine. Two accounts, six categories, two years of
transactions, goals, a loan, three holdings, a paid and an unpaid bill.
Each of those exists because a page renders its empty state without it —
and the two years are because the transactions page paginates at 50 rows.

Also gone: db/, test/backend/, test/e2e/backend-api/, test/benchmark/,
Dockerfile, docker-compose.yml, .dockerignore, the nuke-* scripts, the
root start/lint:backend/test:backend scripts, and better-sqlite3, bcrypt
and sqlite3 from onlyBuiltDependencies.

* chore: finish the e2e move and update the docs for it

Full suite against the Worker: 514 passed, 1 skipped, 0 failed.

Three things the move surfaced:

api.spec.ts asserted `x-ratelimit-limit`, a header express-rate-limit
set on a server that no longer exists. The Worker's limiter counts in D1
and answers a refusal with Retry-After, so the test now drives the export
limiter until it refuses and checks that.

The retirement chart-zoom spec wheeled at boundingBox() centre without
scrolling first. boundingBox() reports document coordinates, so a chart
below the fold got a wheel event that scrolled the page instead of
zooming — and how far down it sits depends on the data.

Workers are capped at 4 rather than one per CPU. Every worker drives the
same local D1 through one wrangler process, and a machine with a lot of
cores turned that into enough contention that pages timed out on their
first fetch, which reads as "the goals list is empty".

AGENTS.md, README.md and CONTRIBUTING.md now describe a tree without
backend/ in it, and point at `pnpm test:e2e` and worker/.dev.vars.

* ci(e2e): install the worker's own dependencies

worker/ is deliberately not a pnpm workspace member, so the root
`pnpm install` never reached it. It did not matter until the suite
started needing its wrangler: `sh: 1: wrangler: not found`.

Same install deploy-worker.yml uses.

* ci(e2e): run the suite serially, so one workerd crash cannot sink it

Four Playwright workers on a 4-vCPU runner meant four headless Chromiums,
vite and wrangler's workerd at once. Twenty seconds in, wrangler dev printed
an empty error and exited; nothing restarts it, so all 17 remaining specs
failed on a 502 from the vite proxy rather than on anything they assert.

One worker on CI, one retry, and a 30-minute job bound.
2026-08-24 03:44:56 +02:00

224 lines
8.0 KiB
TypeScript

import { expect, test } from '@playwright/test'
import { E2E_BASE } from './e2e-constants'
// No sign-in step: the `request` fixture inherits the storageState the setup project saved, so
// these calls carry the session cookie already. They go through the app origin rather than
// straight at the Worker, which is also what the browser does — the vite dev server proxies /api.
test.describe('API Endpoint Verification', () => {
test('verify accounts API endpoint', async ({ request }) => {
const response = await request.get(`${E2E_BASE}/api/accounts`)
expect(response.status()).toBe(200)
const data = await response.json()
expect(Array.isArray(data)).toBeTruthy()
if (data.length > 0) {
expect(data[0]).toHaveProperty('id')
expect(data[0]).toHaveProperty('name')
expect(data[0]).toHaveProperty('balance')
}
})
test('verify accounts POST endpoint', async ({ request }) => {
const response = await request.post(`${E2E_BASE}/api/accounts`, {
data: {
name: 'Test Account',
type: 'checking',
bank_name: 'Test Bank',
initial_balance: 1000.0,
currency: 'USD',
},
})
// May return 201 or 400 if account already exists
expect([200, 201]).toContain(response.status())
// Cleanup
const data = await response.json()
if (Array.isArray(data) && data.length > 0 && data[0].name === 'Test Account') {
await request.delete(`${E2E_BASE}/api/accounts/${data[0].id}`)
}
})
test('verify accounts DELETE endpoint', async ({ request }) => {
const response = await request.get(`${E2E_BASE}/api/accounts`)
const data = await response.json()
if (Array.isArray(data) && data.length > 0) {
const accountId = data[0].id
const deleteResponse = await request.delete(`${E2E_BASE}/api/accounts/${accountId}`)
expect(deleteResponse.status()).toBe(200)
// Verify deletion
const listResponse = await request.get(`${E2E_BASE}/api/accounts`)
const listData = await listResponse.json()
const stillExists = listData.some((a: any) => a.id === accountId)
expect(stillExists).toBeFalsy()
}
})
test('verify transactions summary API', async ({ request }) => {
const response = await request.get(`${E2E_BASE}/api/transactions/summary`, {
headers: { 'x-profile-id': '1' },
})
expect(response.status()).toBe(200)
const data = await response.json()
// The API contract is snake_case (what the frontend consumes)
expect(data).toHaveProperty('count')
expect(data).toHaveProperty('total_amount')
expect(data).toHaveProperty('total_expense')
expect(data).toHaveProperty('total_income')
expect(data).toHaveProperty('total_expenses')
expect(data).toHaveProperty('net_balance')
})
test('verify transactions API pagination', async ({ request }) => {
const response = await request.get(`${E2E_BASE}/api/transactions?limit=20`, {
headers: { 'x-profile-id': '1' },
})
expect(response.status()).toBe(200)
const data = await response.json()
expect(Array.isArray(data.rows)).toBeTruthy()
expect(data.rows.length).toBeLessThanOrEqual(20)
})
test('verify transactions filter by date', async ({ request }) => {
const response = await request.get(`${E2E_BASE}/api/transactions?start_date=2026-01-01`, {
headers: { 'x-profile-id': '1' },
})
expect(response.status()).toBe(200)
const data = await response.json()
expect(Array.isArray(data.rows)).toBeTruthy()
})
test('verify housing API', async ({ request }) => {
const response = await request.get(`${E2E_BASE}/api/housing`)
expect(response.status()).toBe(200)
const data = await response.json()
expect(data).toHaveProperty('housings')
expect(data).toHaveProperty('total_monthly')
})
test('verify loans API', async ({ request }) => {
const response = await request.get(`${E2E_BASE}/api/loans`)
expect(response.status()).toBe(200)
const data = await response.json()
expect(Array.isArray(data)).toBeTruthy()
if (data.length > 0) {
expect(data[0]).toHaveProperty('id')
expect(data[0]).toHaveProperty('name')
expect(data[0]).toHaveProperty('principal')
}
})
test('verify bills API', async ({ request }) => {
const response = await request.get(`${E2E_BASE}/api/bills`)
expect(response.status()).toBe(200)
const data = await response.json()
expect(Array.isArray(data)).toBeTruthy()
if (data.length > 0) {
expect(data[0]).toHaveProperty('id')
expect(data[0]).toHaveProperty('name')
expect(data[0]).toHaveProperty('amount')
expect(data[0]).toHaveProperty('frequency')
}
})
test('verify goals API', async ({ request }) => {
const response = await request.get(`${E2E_BASE}/api/savings-goals`)
expect(response.status()).toBe(200)
const data = await response.json()
expect(Array.isArray(data)).toBeTruthy()
if (data.length > 0) {
expect(data[0]).toHaveProperty('id')
expect(data[0]).toHaveProperty('name')
expect(data[0]).toHaveProperty('target_amount')
}
})
test('verify categories API', async ({ request }) => {
const response = await request.get(`${E2E_BASE}/api/categories`, {
headers: { 'x-profile-id': '1' },
})
expect(response.status()).toBe(200)
const data = await response.json()
expect(Array.isArray(data)).toBeTruthy()
if (data.length > 0) {
expect(data[0]).toHaveProperty('id')
expect(data[0]).toHaveProperty('name')
expect(data[0]).toHaveProperty('color')
expect(data[0]).toHaveProperty('type')
}
})
test('verify categories filter by type', async ({ request }) => {
const response = await request.get(`${E2E_BASE}/api/categories?type=expense`, {
headers: { 'x-profile-id': '1' },
})
expect(response.status()).toBe(200)
const data = await response.json()
expect(Array.isArray(data)).toBeTruthy()
if (data.length > 0) {
expect(data.every((cat: any) => cat.type === 'expense')).toBeTruthy()
}
})
test('verify budgets API', async ({ request }) => {
const response = await request.get(`${E2E_BASE}/api/budgets`)
expect(response.status()).toBe(200)
const data = await response.json()
expect(Array.isArray(data)).toBeTruthy()
})
test('verify backend is responding', async ({ page }) => {
const response = await page.goto(`${E2E_BASE}/api/health`)
expect(response?.status()).toBe(200)
})
test('verify API has proper error handling', async ({ request }) => {
// Test non-existent endpoint
const response = await request.get(`${E2E_BASE}/api/non-existent`)
expect(response.status()).toBe(404)
const data = await response.json()
expect(data).toHaveProperty('error')
})
test('verify accounts search functionality', async ({ request }) => {
const response = await request.get(`${E2E_BASE}/api/accounts?search=Checking`)
expect(response.status()).toBe(200)
const data = await response.json()
expect(Array.isArray(data)).toBeTruthy()
})
test('a rate-limited response says how long to wait', async ({ request }) => {
// `x-ratelimit-limit` came from express-rate-limit, on a server that no longer exists — the
// Worker's limiter counts in D1 and answers a refusal with Retry-After. The export route has a
// low enough cap (10 per 5 minutes) to reach without hammering anything.
let limited: Awaited<ReturnType<typeof request.get>> | undefined
for (let attempt = 0; attempt < 12 && !limited; attempt += 1) {
const response = await request.get(`${E2E_BASE}/api/export`)
if (response.status() === 429) limited = response
}
expect(limited, 'the export limiter never refused within 12 attempts').toBeTruthy()
expect(Number(limited!.headers()['retry-after'])).toBeGreaterThan(0)
})
test('verify API CORS headers', async ({ request }) => {
const response = await request.get(`${E2E_BASE}/api/accounts`)
// In development, CORS is enabled via the cors() middleware which sets allow-credentials
expect(response.headers()['access-control-allow-credentials']).toBe('true')
})
})