Deleting a collection should detach associated drafts from it (#5082)
Co-authored-by: Tom Moor <tom.moor@gmail.com>
This commit is contained in:
33
server/queues/tasks/DetachDraftsFromCollectionTask.test.ts
Normal file
33
server/queues/tasks/DetachDraftsFromCollectionTask.test.ts
Normal 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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user