mirror of
https://github.com/unjs/unstorage.git
synced 2025-12-08 21:26:09 +00:00
33 lines
1.2 KiB
TypeScript
33 lines
1.2 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import { listen } from "listhen";
|
|
import { $fetch } from "ohmyfetch";
|
|
import { createStorage } from "../src";
|
|
import { createStorageServer } from "../src/server";
|
|
|
|
describe("server", () => {
|
|
it("basic", async () => {
|
|
const storage = createStorage();
|
|
const storageServer = createStorageServer(storage);
|
|
const { close, url: serverURL } = await listen(storageServer.handle, {
|
|
port: { random: true }
|
|
});
|
|
|
|
const fetchStorage = (url: string, options?: any) => $fetch(url, { baseURL: serverURL, ...options });
|
|
|
|
expect(await fetchStorage("foo", {})).toMatchObject([]);
|
|
|
|
await storage.setItem("foo/bar", "bar");
|
|
await storage.setMeta("foo/bar", { mtime: new Date() });
|
|
expect(await fetchStorage("foo/bar")).toBe("bar");
|
|
|
|
expect(await fetchStorage("foo/bar", { method: "PUT", body: "updated" })).toBe("OK");
|
|
expect(await fetchStorage("foo/bar")).toBe("updated");
|
|
expect(await fetchStorage("/")).toMatchObject(["foo/bar"]);
|
|
|
|
expect(await fetchStorage("foo/bar", { method: "DELETE" })).toBe("OK");
|
|
expect(await fetchStorage("foo/bar", {})).toMatchObject([]);
|
|
|
|
await close();
|
|
});
|
|
});
|