mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-16 04:27:21 +00:00
public commit
This commit is contained in:
46
app/__test__/media/adapters/StorageLocalAdapter.spec.ts
Normal file
46
app/__test__/media/adapters/StorageLocalAdapter.spec.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { describe, expect, test } from "bun:test";
|
||||
import { randomString } from "../../../src/core/utils";
|
||||
import { StorageLocalAdapter } from "../../../src/media/storage/adapters/StorageLocalAdapter";
|
||||
|
||||
describe("StorageLocalAdapter", () => {
|
||||
const adapter = new StorageLocalAdapter({
|
||||
path: `${import.meta.dir}/local`
|
||||
});
|
||||
|
||||
const file = Bun.file(`${import.meta.dir}/icon.png`);
|
||||
const _filename = randomString(10);
|
||||
const filename = `${_filename}.png`;
|
||||
|
||||
let objects = 0;
|
||||
|
||||
test("puts an object", async () => {
|
||||
objects = (await adapter.listObjects()).length;
|
||||
expect(await adapter.putObject(filename, await file.arrayBuffer())).toBeString();
|
||||
});
|
||||
|
||||
test("lists objects", async () => {
|
||||
expect((await adapter.listObjects()).length).toBe(objects + 1);
|
||||
});
|
||||
|
||||
test("file exists", async () => {
|
||||
expect(await adapter.objectExists(filename)).toBeTrue();
|
||||
});
|
||||
|
||||
test("gets an object", async () => {
|
||||
const res = await adapter.getObject(filename, new Headers());
|
||||
expect(res.ok).toBeTrue();
|
||||
// @todo: check the content
|
||||
});
|
||||
|
||||
test("gets object meta", async () => {
|
||||
expect(await adapter.getObjectMeta(filename)).toEqual({
|
||||
type: file.type, // image/png
|
||||
size: file.size
|
||||
});
|
||||
});
|
||||
|
||||
test("deletes an object", async () => {
|
||||
expect(await adapter.deleteObject(filename)).toBeUndefined();
|
||||
expect(await adapter.objectExists(filename)).toBeFalse();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user