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 { 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 { 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 { const resp = await request.post("/api/transactions", { data: input }); if (!resp.ok()) { throw new Error(`failed to create transaction: ${resp.status()} ${await resp.text()}`); } }