fix: Uploaded and immediately deleted images are not removed from storage (#4562)
* fix: Uploaded and immediately deleted images are not removed from storage upon permanant delete closes #4557 * Move attachment deletion async
This commit is contained in:
@@ -1,9 +1,12 @@
|
||||
import { subDays } from "date-fns";
|
||||
import { Attachment, Document } from "@server/models";
|
||||
import DeleteAttachmentTask from "@server/queues/tasks/DeleteAttachmentTask";
|
||||
import { buildAttachment, buildDocument } from "@server/test/factories";
|
||||
import { setupTestDatabase } from "@server/test/support";
|
||||
import documentPermanentDeleter from "./documentPermanentDeleter";
|
||||
|
||||
jest.mock("@server/queues/tasks/DeleteAttachmentTask");
|
||||
|
||||
setupTestDatabase();
|
||||
|
||||
describe("documentPermanentDeleter", () => {
|
||||
@@ -47,11 +50,15 @@ describe("documentPermanentDeleter", () => {
|
||||
teamId: document.teamId,
|
||||
documentId: document.id,
|
||||
});
|
||||
await buildAttachment({
|
||||
teamId: document.teamId,
|
||||
documentId: document.id,
|
||||
});
|
||||
document.text = ``;
|
||||
await document.save();
|
||||
const countDeletedDoc = await documentPermanentDeleter([document]);
|
||||
expect(countDeletedDoc).toEqual(1);
|
||||
expect(await Attachment.count()).toEqual(0);
|
||||
expect(DeleteAttachmentTask.schedule).toHaveBeenCalledTimes(2);
|
||||
expect(
|
||||
await Document.unscoped().count({
|
||||
paranoid: false,
|
||||
|
||||
Reference in New Issue
Block a user