mirror of
https://github.com/versia-pub/server.git
synced 2026-03-13 13:59:16 +01:00
fix(api): 🐛 Deleting emojis now removes them from object storage
This commit is contained in:
parent
7846a03bcf
commit
29d7b09677
5 changed files with 119 additions and 11 deletions
|
|
@ -1,4 +1,4 @@
|
|||
import { beforeEach, describe, expect, it, jest, spyOn } from "bun:test";
|
||||
import { beforeEach, describe, expect, it, jest, mock, spyOn } from "bun:test";
|
||||
import type { S3Client } from "@jsr/bradenmacdonald__s3-lite-client";
|
||||
import type { Config } from "config-manager";
|
||||
import {
|
||||
|
|
@ -127,6 +127,7 @@ describe("S3MediaBackend", () => {
|
|||
blob: jest.fn().mockResolvedValue(new Blob()),
|
||||
headers: new Headers({ "Content-Type": "image/jpeg" }),
|
||||
}),
|
||||
deleteObject: jest.fn().mockResolvedValue({}),
|
||||
} as Partial<S3Client>;
|
||||
s3MediaBackend = new S3MediaBackend(
|
||||
mockConfig as Config,
|
||||
|
|
@ -187,6 +188,21 @@ describe("S3MediaBackend", () => {
|
|||
expect(file?.name).toEqual(mockFilename);
|
||||
expect(file?.type).toEqual("image/jpeg");
|
||||
});
|
||||
|
||||
it("should delete file", async () => {
|
||||
// deleteFileByUrl
|
||||
// Upload file first
|
||||
const mockHash = "test-hash";
|
||||
spyOn(mockMediaHasher, "getMediaHash").mockResolvedValue(mockHash);
|
||||
const result = await s3MediaBackend.addFile(mockFile);
|
||||
const url = result.path;
|
||||
|
||||
await s3MediaBackend.deleteFileByUrl(`http://localhost:4566/${url}`);
|
||||
|
||||
expect(mockS3Client.deleteObject).toHaveBeenCalledWith(
|
||||
expect.stringContaining(url),
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("LocalMediaBackend", () => {
|
||||
|
|
@ -274,4 +290,28 @@ describe("LocalMediaBackend", () => {
|
|||
expect(file?.name).toEqual(mockFilename);
|
||||
expect(file?.type).toEqual("image/jpeg");
|
||||
});
|
||||
|
||||
it("should delete file", async () => {
|
||||
// deleteByUrl
|
||||
const mockHash = "test-hash";
|
||||
spyOn(mockMediaHasher, "getMediaHash").mockResolvedValue(mockHash);
|
||||
const result = await localMediaBackend.addFile(mockFile);
|
||||
const rmMock = jest.fn().mockResolvedValue(Promise.resolve());
|
||||
|
||||
// Spy on fs/promises rm
|
||||
mock.module("fs/promises", () => {
|
||||
return {
|
||||
rm: rmMock,
|
||||
};
|
||||
});
|
||||
|
||||
await localMediaBackend.deleteFileByUrl(
|
||||
"http://localhost:4566/test-hash",
|
||||
);
|
||||
|
||||
expect(rmMock).toHaveBeenCalledWith(
|
||||
`${mockConfig.media.local_uploads_folder}/${mockHash}`,
|
||||
{ recursive: true },
|
||||
);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue