added api logic, vitest, minimal testing ui

This commit is contained in:
2025-11-15 23:26:57 -06:00
parent f4160b91db
commit 4eae966f96
95 changed files with 14155 additions and 469 deletions

32
api/tests/setup.ts Normal file
View File

@@ -0,0 +1,32 @@
import { execSync } from "node:child_process";
import { beforeAll, afterAll } from "vitest";
import { PrismaClient } from "@prisma/client";
process.env.NODE_ENV = process.env.NODE_ENV || "test";
process.env.DATABASE_URL =
process.env.DATABASE_URL ||
"postgres://app:app@localhost:5432/skymoney";
process.env.PORT = process.env.PORT || "0"; // fastify can bind an ephemeral port
process.env.HOST ??= "127.0.0.1";
process.env.CORS_ORIGIN = process.env.CORS_ORIGIN || "";
export const prisma = new PrismaClient();
// hard reset for a single user
export async function resetUser(userId: string) {
await prisma.allocation.deleteMany({ where: { userId } });
await prisma.transaction.deleteMany({ where: { userId } });
await prisma.incomeEvent.deleteMany({ where: { userId } });
await prisma.fixedPlan.deleteMany({ where: { userId } });
await prisma.variableCategory.deleteMany({ where: { userId } });
await prisma.user.deleteMany({ where: { id: userId } });
}
beforeAll(async () => {
// make sure the schema is applied before running tests
execSync("npx prisma migrate deploy", { stdio: "inherit" });
});
afterAll(async () => {
await prisma.$disconnect();
});