Store phone/tablet/photo-frame shells with catalogs, append pages from extra images or PDFs, and reorder drafts with drag-and-drop. Co-authored-by: Cursor <cursoragent@cursor.com>
51 lines
1.5 KiB
TypeScript
51 lines
1.5 KiB
TypeScript
import fs from "node:fs/promises";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
import { afterEach, describe, expect, it } from "vitest";
|
|
import { openDatabase } from "../../server/db";
|
|
import { createCatalogRepo } from "../../server/catalog-repo";
|
|
|
|
const temps: string[] = [];
|
|
|
|
async function tempDb() {
|
|
const dir = await fs.mkdtemp(path.join(os.tmpdir(), "dc-db-"));
|
|
temps.push(dir);
|
|
const db = await openDatabase(path.join(dir, "catalogs.sqlite"));
|
|
return createCatalogRepo(db);
|
|
}
|
|
|
|
afterEach(async () => {
|
|
await Promise.all(temps.splice(0).map((dir) => fs.rm(dir, { recursive: true, force: true })));
|
|
});
|
|
|
|
describe("catalog repo", () => {
|
|
it("inserts and reads a catalog", async () => {
|
|
const repo = await tempDb();
|
|
const created = repo.create({
|
|
id: "abc12xyz90",
|
|
deleteToken: "token-token-token-token-12",
|
|
title: "کاتالوگ",
|
|
effect: "magazine",
|
|
pageCount: 2,
|
|
});
|
|
const found = repo.getById("abc12xyz90");
|
|
expect(found).toEqual(created);
|
|
expect(found?.flipMs).toBe(1000);
|
|
expect(found?.frame).toBe("none");
|
|
expect(found?.deleteToken).toBe("token-token-token-token-12");
|
|
});
|
|
|
|
it("returns null after delete", async () => {
|
|
const repo = await tempDb();
|
|
repo.create({
|
|
id: "id1",
|
|
deleteToken: "tok",
|
|
title: "کاتالوگ",
|
|
effect: "slide",
|
|
pageCount: 1,
|
|
});
|
|
expect(repo.deleteById("id1")).toBe(true);
|
|
expect(repo.getById("id1")).toBeNull();
|
|
});
|
|
});
|