feat: operations list with filters and edit
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
1e91f38fd3
commit
63620f8c52
4 files changed
+210
No files matched your search
@@ -0,0 +1,50 @@
|
||||
import { beforeEach, describe, expect, it } from "vitest";
|
||||
import { prisma } from "@/server/db";
|
||||
import { searchOps } from "@/server/repo";
|
||||
import { saveOperation } from "@/server/services/operations";
|
||||
import { categoryId, makeUsers, resetDb } from "./helpers";
|
||||
|
||||
let H: string;
|
||||
let C: string;
|
||||
|
||||
beforeEach(async () => {
|
||||
await resetDb();
|
||||
const u = await makeUsers();
|
||||
H = u.h.id;
|
||||
C = u.c.id;
|
||||
const base = { status: "ACTUAL" as const, date: "2026-10-15", categoryId: await categoryId("Courses") };
|
||||
for (const input of [
|
||||
{ ...base, kind: "EXPENSE" as const, amount: "86,40", label: "Carrefour Market", accountUserId: C, split: { [H]: 5000, [C]: 5000 } },
|
||||
{ ...base, kind: "EXPENSE" as const, amount: "1000", label: "Loyer", accountUserId: H, split: { [H]: 5000, [C]: 5000 }, categoryId: await categoryId("Logement") },
|
||||
{ ...base, kind: "EXPENSE" as const, amount: "40", label: "Coiffeur", accountUserId: H, split: { [H]: 10000, [C]: 0 } },
|
||||
{ ...base, kind: "EXPENSE" as const, amount: "350", label: "Révision", accountUserId: H, split: { [H]: 10000, [C]: 0 }, status: "PLANNED" as const },
|
||||
{ ...base, kind: "EXPENSE" as const, amount: "20", label: "Ignorée", accountUserId: H, split: { [H]: 10000, [C]: 0 } },
|
||||
{ ...base, kind: "EXPENSE" as const, amount: "20", label: "Novembre", accountUserId: H, split: { [H]: 10000, [C]: 0 }, date: "2026-11-02" },
|
||||
]) {
|
||||
const r = await saveOperation(input, H);
|
||||
if (!r.ok) throw new Error(r.error);
|
||||
}
|
||||
await prisma.operation.updateMany({ where: { label: "Ignorée" }, data: { status: "SKIPPED" } });
|
||||
});
|
||||
|
||||
const labels = async (f: Parameters<typeof searchOps>[0]) => (await searchOps(f)).map((o) => o.label).sort();
|
||||
|
||||
describe("searchOps", () => {
|
||||
it("searches labels case-insensitively within the month", async () => {
|
||||
expect(await labels({ month: "2026-10", q: "carre" })).toEqual(["Carrefour Market"]);
|
||||
});
|
||||
|
||||
it("filters by person: account holder or anyone with a share", async () => {
|
||||
expect(await labels({ month: "2026-10", userId: C })).toEqual(["Carrefour Market", "Loyer"]);
|
||||
});
|
||||
|
||||
it("filters by status and never returns skipped operations", async () => {
|
||||
expect(await labels({ month: "2026-10", status: "PLANNED" })).toEqual(["Révision"]);
|
||||
expect(await labels({ month: "2026-10" })).toEqual(["Carrefour Market", "Coiffeur", "Loyer", "Révision"]);
|
||||
});
|
||||
|
||||
it("filters by category and kind", async () => {
|
||||
expect(await labels({ month: "2026-10", categoryId: await categoryId("Logement") })).toEqual(["Loyer"]);
|
||||
expect(await labels({ month: "2026-10", kind: "INCOME" })).toEqual([]);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user