feat: place purchases and bills in budget hierarchy

This commit is contained in:
Lucas Winther committed 2026-09-30 13:48:49 +02:00
1 parent b0e8145d2e
commit 85a21c58eb
19 files changed
+281 -70

No files matched your search

+15
View File
@@ -118,6 +118,21 @@ describe("import rejects invalid folder graph", () => {
const folder = (id: string, parentId: string | null, order: number) => ({ id, name: id, parentId, order });
const parse = (data: Dataset) => parseDatasetJson(JSON.stringify(data));
test("round-trips a standalone purchase and a bill nested beneath a post", () => {
const data = populated();
data.folders = [folder("home", null, 3)];
data.purchases[0]!.placement = { folderId: "home", order: 0 };
data.recurring.push({ id: "rent", name: "Rent", order: 0, folderId: null, parentPostId: data.posts[0]!.id, archived: false, amount: { amount: 100, currency: "DKK" }, startDate: "2026-01", recurrence: { kind: "everyNMonths", n: 1 }, anchoring: "calendar", splitMode: "percent", splits: [{ postId: data.posts[0]!.id, value: 100, absorbsRemainder: true }] });
const restored = parse(data);
expect(restored.purchases[0]!.placement?.folderId).toBe("home");
expect(restored.recurring[0]!.parentPostId).toBe(data.posts[0]!.id);
restored.recurring[0]!.parentPostId = "missing";
expect(() => parse(restored)).toThrow(/parent post/);
restored.recurring[0]!.parentPostId = data.posts[0]!.id;
restored.purchases[0]!.placement!.folderId = "missing";
expect(() => parse(restored)).toThrow(/unknown folder/);
});
test("valid nested tree parses", () => {
const data = populated();
data.folders = [folder("home", null, 0), folder("bills", "home", 0)];