feat: spread an annual amount over 12 monthly entries, add Dividendes category

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
YugonitoandClaude Opus 5.5 committed 2026-10-27 21:40:53 +01:00
1 parent 9fbcf12323
commit 900f3c1d58
4 files changed
+98 -4

No files matched your search

+40
View File
@@ -109,6 +109,46 @@ describe("saveOperation", () => {
});
});
describe("saveOperation with an annual amount spread over 12 months", () => {
const dividends = (over: Partial<OperationInput> = {}): OperationInput => ({
kind: "INCOME",
amount: "1000",
label: "Dividendes",
categoryId: salaire,
date: "2026-10-31",
accountUserId: H,
status: "ACTUAL",
split: { [H]: 10000, [C]: 0 },
spreadOverYear: true,
...over,
});
it("creates 12 monthly entries summing to the annual amount", async () => {
expect(await saveOperation(dividends(), H)).toMatchObject({ ok: true });
const ops = await prisma.operation.findMany({ orderBy: { date: "asc" }, include: { splits: true } });
expect(ops).toHaveLength(12);
expect(ops.map((o) => o.date.toISOString().slice(0, 10)).slice(0, 5)).toEqual([
"2026-10-31",
"2026-11-30",
"2026-12-31",
"2027-01-31",
"2027-02-28",
]);
expect(ops[11].date.toISOString().slice(0, 10)).toBe("2027-09-30");
expect(ops.map((o) => o.amount.toString())).toEqual(["83.37", ...Array(11).fill("83.33")]);
expect(ops[0].label).toBe("Dividendes (1/12)");
expect(ops[11].label).toBe("Dividendes (12/12)");
expect(ops.every((o) => o.status === "ACTUAL" && o.splits.length === 2 && o.recurringId === null)).toBe(true);
});
it("cannot also be recurring", async () => {
expect(await saveOperation(dividends({ makeRecurring: { frequency: "MONTHLY", endDate: null } }), H)).toEqual({
ok: false,
error: "Un montant annuel lissé ne peut pas être récurrent.",
});
});
});
describe("deleteOperation on a recurring occurrence", () => {
it("does not come back at the next sync", async () => {
const r = await saveOperation(expense({ makeRecurring: { frequency: "MONTHLY", endDate: null } }), H);