fix: check category parents and repair orphan categories (#393) #472

Open
maximus wants to merge 7 commits from issue-393-category-hierarchy into issue-429-category-combobox-portal
Showing only changes of commit 8a9d9909f9 - Show all commits

View file

@ -358,8 +358,14 @@ describe("reattachCategory on rows already in a cycle (#393)", () => {
expect(db.writes()).toEqual(["BEGIN", "ROLLBACK", "BEGIN", "ROLLBACK"]);
});
it("reattaches a category whose parent was deleted", async () => {
const db = useFakeDb([row(1, null), row(2, null, { is_active: 0 }), row(20, 2), row(21, 20)]);
it("reattaches a category whose parent was deleted, counting its active descendants only", async () => {
const db = useFakeDb([
row(1, null),
row(2, null, { is_active: 0 }),
row(20, 2),
row(21, 20),
row(22, 20, { is_active: 0 }),
]);
expect(await reattachCategory(20, 1)).toBe(2);
expect(db.rows().find((r) => r.id === 20)?.parent_id).toBe(1);
expect(await findOrphanCategories()).toEqual([]);