Deleting a collection should detach associated drafts from it (#5082)

Co-authored-by: Tom Moor <tom.moor@gmail.com>
This commit is contained in:
Apoorv Mishra
2023-04-24 00:50:44 +05:30
committed by GitHub
parent 7250c0ed64
commit 86062f396d
39 changed files with 363 additions and 112 deletions

View File

@@ -0,0 +1,33 @@
import { Document } from "@server/models";
import { buildCollection, buildDocument } from "@server/test/factories";
import { setupTestDatabase } from "@server/test/support";
import DetachDraftsFromCollectionTask from "./DetachDraftsFromCollectionTask";
setupTestDatabase();
describe("DetachDraftsFromCollectionTask", () => {
const ip = "127.0.0.1";
it("should detach drafts from deleted collection", async () => {
const collection = await buildCollection();
const document = await buildDocument({
title: "test",
collectionId: collection.id,
publishedAt: null,
createdById: collection.createdById,
teamId: collection.teamId,
});
await collection.destroy();
const task = new DetachDraftsFromCollectionTask();
await task.perform({
collectionId: collection.id,
ip,
actorId: collection.createdById,
});
const draft = await Document.findByPk(document.id);
expect(draft).not.toBe(null);
expect(draft?.deletedAt).toBe(null);
expect(draft?.collectionId).toBe(null);
});
});