feat: implement prepareSqlitePath function and add tests for database path handling

This commit is contained in:
MythEclipse
2026-05-16 00:12:31 +07:00
parent acd4648d49
commit c6ee7bb8c6
4 changed files with 39 additions and 2 deletions
+23
View File
@@ -0,0 +1,23 @@
import { mkdtemp, rm } from "node:fs/promises";
import { existsSync } from "node:fs";
import { join } from "node:path";
import { tmpdir } from "node:os";
import { describe, expect, test } from "bun:test";
import { prepareSqlitePath } from "./sqlitePath";
describe("prepareSqlitePath", () => {
test("creates parent directory for file database urls", async () => {
const root = await mkdtemp(join(tmpdir(), "booster-role-db-"));
const dbPath = join(root, "nested", "booster-role.sqlite");
expect(existsSync(join(root, "nested"))).toBe(false);
expect(prepareSqlitePath(`file:${dbPath}`)).toBe(dbPath);
expect(existsSync(join(root, "nested"))).toBe(true);
await rm(root, { recursive: true, force: true });
});
test("does not create a directory for in-memory databases", () => {
expect(prepareSqlitePath(":memory:")).toBe(":memory:");
});
});