mirror of
https://github.com/Zproger/Aurum.git
synced 2026-10-13 02:56:39 +07:00
test: real backend pytest + E2E Playwright suites, both isolated from prod data
backend/tests/: 33 pytest tests against a real Postgres database (aurum_test, created/migrated/dropped per run) exercised through the actual HTTP API — not sqlite, not mocks, and the real `aurum` database is never opened (app lifespan is skipped, get_session is overridden per test). Covers transaction category-kind validation, year/month/date-range filtering and pagination, dashboard summary arithmetic, budget status, cash flow, and the /transactions/years picker. e2e/: 6 Playwright specs driving a real browser against a fully separate throwaway docker-compose stack (run.sh: separate project name, database, port, and volume, torn down with `down -v` on exit) — regression coverage for the Recent Transactions month bug, the Card grid-overflow bug, the frozen-year bug, the Net Worth default range, and the Dashboard-> Transactions deep link, all fixed earlier this session. Also synced the backend's APP_VERSION constant (stale at 0.15.2, embedded in exported backups) with the frontend version.
This commit is contained in:
36
e2e/tests/helpers.ts
Normal file
36
e2e/tests/helpers.ts
Normal file
@@ -0,0 +1,36 @@
|
||||
import type { APIRequestContext } from "@playwright/test";
|
||||
|
||||
/** Thin wrapper over the real HTTP API (proxied at /api by nginx, same as
|
||||
* the frontend uses) — fast, reliable fixture setup so each spec can drive
|
||||
* the actual UI against known data instead of guessing at pre-existing
|
||||
* account/category IDs. */
|
||||
|
||||
export async function getDefaultAccountId(request: APIRequestContext): Promise<number> {
|
||||
const resp = await request.get("/api/accounts");
|
||||
const accounts = await resp.json();
|
||||
return accounts[0].id;
|
||||
}
|
||||
|
||||
export async function getCategoryId(request: APIRequestContext, name: string): Promise<number> {
|
||||
const resp = await request.get("/api/categories");
|
||||
const categories = await resp.json();
|
||||
const match = categories.find((c: { name: string }) => c.name === name);
|
||||
if (!match) throw new Error(`category "${name}" not found`);
|
||||
return match.id;
|
||||
}
|
||||
|
||||
export interface TransactionInput {
|
||||
account_id: number;
|
||||
category_id?: number;
|
||||
type: "income" | "expense" | "transfer";
|
||||
amount: string;
|
||||
description: string;
|
||||
date: string; // YYYY-MM-DD
|
||||
}
|
||||
|
||||
export async function createTransaction(request: APIRequestContext, input: TransactionInput): Promise<void> {
|
||||
const resp = await request.post("/api/transactions", { data: input });
|
||||
if (!resp.ok()) {
|
||||
throw new Error(`failed to create transaction: ${resp.status()} ${await resp.text()}`);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user