test(store): cover a v1 post missing standingRule entirely (v1 -> v2)

Previously only an empty posts array was tested for the "no standingRule"
path; a post that IS present but lacks the field was exercised only by an
ad-hoc script, not a committed test. Asserts rules === [] (never a version
wrapping undefined, which would later crash resolveRule/ruleAt) and that a
sibling post's rule is unaffected.
This commit is contained in:
Lucas Winther
2026-09-02 02:23:02 +02:00
parent 15dcf935f4
commit 1214d2b2ed
+22 -1
View File
@@ -109,8 +109,29 @@ describe("v1 -> v2: rules become a dated series", () => {
}
});
test("a v1 post with no posts at all migrates without throwing", () => {
test("an empty posts array migrates without throwing", () => {
const empty = { ...v1Dataset(), posts: [] };
expect(migrate(empty).posts).toEqual([]);
});
test("a v1 post with no standingRule at all migrates to an empty rules array, not a version wrapping undefined", () => {
const dataset = v1Dataset();
dataset.posts.push({
id: "unbudgeted",
name: "Unbudgeted",
order: 2,
archived: false,
currency: "DKK",
} as any);
const migrated = migrate(dataset);
const unbudgeted = migrated.posts.find((p) => p.id === "unbudgeted")!;
expect(unbudgeted.rules).toEqual([]);
// The missing field on one post must not contaminate its siblings.
expect(migrated.posts[0]!.rules).toEqual([
{ from: "2026-01", rule: { kind: "percentOfIncome", percent: 20 } },
]);
});
});