added api logic, vitest, minimal testing ui
This commit is contained in:
32
api/tests/setup.ts
Normal file
32
api/tests/setup.ts
Normal 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();
|
||||
});
|
||||
Reference in New Issue
Block a user