Refactor Study Desk application structure
This commit is contained in:
parent
faaccf8a7e
commit
089439ed90
145 changed files with 8087 additions and 3412 deletions
41
tests/helpers/testDatabase.test.ts
Normal file
41
tests/helpers/testDatabase.test.ts
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
||||
import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
import { afterEach, describe, expect, it } from "vitest";
|
||||
import { assertDisposableTestDatabase } from "./testDatabase";
|
||||
|
||||
const cleanup: string[] = [];
|
||||
|
||||
afterEach(() => {
|
||||
for (const directory of cleanup.splice(0)) {
|
||||
rmSync(directory, { recursive: true, force: true });
|
||||
}
|
||||
});
|
||||
|
||||
describe("assertDisposableTestDatabase", () => {
|
||||
it("accepts a new uniquely named test database", () => {
|
||||
const directory = mkdtempSync(path.join(tmpdir(), "study-db-safety-"));
|
||||
cleanup.push(directory);
|
||||
const target = path.join(directory, "unique.test.db");
|
||||
expect(assertDisposableTestDatabase(`file:${target}`)).toBe(path.resolve(target));
|
||||
});
|
||||
|
||||
it.each(["file:./dev.db", "file:/app/data/study.db"])(
|
||||
"rejects protected database path %s",
|
||||
(databaseUrl) => {
|
||||
expect(() => assertDisposableTestDatabase(databaseUrl)).toThrow(
|
||||
"Refusing to use non-disposable database"
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
it("rejects an existing database even when its name looks like a test", () => {
|
||||
const directory = mkdtempSync(path.join(tmpdir(), "study-db-safety-"));
|
||||
cleanup.push(directory);
|
||||
const target = path.join(directory, "existing.test.db");
|
||||
writeFileSync(target, "not disposable");
|
||||
expect(() => assertDisposableTestDatabase(`file:${target}`)).toThrow(
|
||||
"Refusing to use non-disposable database"
|
||||
);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue