removed unneccesary files
This commit is contained in:
@@ -3,6 +3,7 @@ import { describe, it, expect, beforeAll, afterAll, beforeEach } from "vitest";
|
||||
import appFactory from "./appFactory";
|
||||
import { prisma, resetUser, ensureUser, U, cid, closePrisma } from "./helpers";
|
||||
import type { FastifyInstance } from "fastify";
|
||||
import { randomUUID } from "node:crypto";
|
||||
|
||||
let app: FastifyInstance;
|
||||
|
||||
@@ -59,10 +60,13 @@ describe("manual rebalance", () => {
|
||||
|
||||
const cats = await prisma.variableCategory.findMany({ where: { userId: U }, orderBy: { priority: "asc" } });
|
||||
const targets = cats.map((c) => ({ id: c.id, targetCents: 2500 })); // 4 * 2500 = 10000
|
||||
const csrf = randomUUID().replace(/-/g, "");
|
||||
const postRes = await request(app.server)
|
||||
.post("/variable-categories/manual-rebalance")
|
||||
.set("x-user-id", U)
|
||||
.send({ targets });
|
||||
.set("x-csrf-token", csrf)
|
||||
.set("Cookie", `csrf=${csrf}`)
|
||||
.send({ targets, forceLowerSavings: true });
|
||||
|
||||
expect(postRes.statusCode).toBe(200);
|
||||
expect(postRes.body?.availableCents).toBe(10_000);
|
||||
@@ -78,11 +82,14 @@ describe("manual rebalance", () => {
|
||||
it("rebalances when sums match available", async () => {
|
||||
const cats = await prisma.variableCategory.findMany({ where: { userId: U }, orderBy: { priority: "asc" } });
|
||||
const targets = cats.map((c) => ({ id: c.id, targetCents: 2500 })); // 4 * 2500 = 10000
|
||||
const csrf = randomUUID().replace(/-/g, "");
|
||||
|
||||
const res = await request(app.server)
|
||||
.post("/variable-categories/manual-rebalance")
|
||||
.set("x-user-id", U)
|
||||
.send({ targets });
|
||||
.set("x-csrf-token", csrf)
|
||||
.set("Cookie", `csrf=${csrf}`)
|
||||
.send({ targets, forceLowerSavings: true });
|
||||
|
||||
expect(res.statusCode).toBe(200);
|
||||
expect(res.body?.ok).toBe(true);
|
||||
@@ -93,10 +100,13 @@ describe("manual rebalance", () => {
|
||||
it("rejects sum mismatch", async () => {
|
||||
const cats = await prisma.variableCategory.findMany({ where: { userId: U }, orderBy: { priority: "asc" } });
|
||||
const targets = cats.map((c, i) => ({ id: c.id, targetCents: i === 0 ? 5000 : 1000 })); // 5000 + 3*1000 = 8000
|
||||
const csrf = randomUUID().replace(/-/g, "");
|
||||
|
||||
const res = await request(app.server)
|
||||
.post("/variable-categories/manual-rebalance")
|
||||
.set("x-user-id", U)
|
||||
.set("x-csrf-token", csrf)
|
||||
.set("Cookie", `csrf=${csrf}`)
|
||||
.send({ targets });
|
||||
|
||||
expect(res.statusCode).toBe(400);
|
||||
@@ -108,10 +118,13 @@ describe("manual rebalance", () => {
|
||||
// savings to 500 (below 20% of 10000 = 2000)
|
||||
const targets = cats.map((c) => ({ id: c.id, targetCents: c.isSavings ? 500 : 3166 })); // 500 + 3*3166 = 9998 -> adjust
|
||||
targets[1].targetCents += 2; // total 10000
|
||||
const csrf = randomUUID().replace(/-/g, "");
|
||||
|
||||
const res = await request(app.server)
|
||||
.post("/variable-categories/manual-rebalance")
|
||||
.set("x-user-id", U)
|
||||
.set("x-csrf-token", csrf)
|
||||
.set("Cookie", `csrf=${csrf}`)
|
||||
.send({ targets });
|
||||
|
||||
expect(res.statusCode).toBe(400);
|
||||
@@ -120,6 +133,8 @@ describe("manual rebalance", () => {
|
||||
const resOk = await request(app.server)
|
||||
.post("/variable-categories/manual-rebalance")
|
||||
.set("x-user-id", U)
|
||||
.set("x-csrf-token", csrf)
|
||||
.set("Cookie", `csrf=${csrf}`)
|
||||
.send({ targets, forceLowerSavings: true });
|
||||
|
||||
expect(resOk.statusCode).toBe(200);
|
||||
@@ -129,13 +144,16 @@ describe("manual rebalance", () => {
|
||||
const cats = await prisma.variableCategory.findMany({ where: { userId: U }, orderBy: { priority: "asc" } });
|
||||
const targets = cats.map((c, i) => ({ id: c.id, targetCents: i === 0 ? 9000 : 333 }));
|
||||
targets[1].targetCents += 1; // sum 10000
|
||||
const csrf = randomUUID().replace(/-/g, "");
|
||||
|
||||
const res = await request(app.server)
|
||||
.post("/variable-categories/manual-rebalance")
|
||||
.set("x-user-id", U)
|
||||
.set("x-csrf-token", csrf)
|
||||
.set("Cookie", `csrf=${csrf}`)
|
||||
.send({ targets });
|
||||
|
||||
expect(res.statusCode).toBe(400);
|
||||
expect(res.body?.code).toBe("OVER_80_PERCENT");
|
||||
expect(res.body?.code).toBe("OVER_80_CONFIRM_REQUIRED");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user