Refactor Study Desk application structure
This commit is contained in:
parent
faaccf8a7e
commit
089439ed90
145 changed files with 8087 additions and 3412 deletions
40
tests/migrationSchema.test.ts
Normal file
40
tests/migrationSchema.test.ts
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
import Database from "better-sqlite3";
|
||||
import path from "node:path";
|
||||
import { describe, expect, it } from "vitest";
|
||||
|
||||
function testDatabasePath() {
|
||||
const databaseUrl = process.env.DATABASE_URL;
|
||||
if (!databaseUrl?.startsWith("file:./")) {
|
||||
throw new Error("Disposable test DATABASE_URL was not provided");
|
||||
}
|
||||
return path.resolve(process.cwd(), databaseUrl.slice("file:".length));
|
||||
}
|
||||
|
||||
describe("committed migration chain", () => {
|
||||
it("creates material groups and all expected group relationships", () => {
|
||||
const database = new Database(testDatabasePath(), { readonly: true });
|
||||
try {
|
||||
const tables = database
|
||||
.prepare("SELECT name FROM sqlite_master WHERE type = 'table'")
|
||||
.all() as Array<{ name: string }>;
|
||||
expect(tables.map((table) => table.name)).toContain("MaterialGroup");
|
||||
|
||||
for (const table of ["Deck", "QuizSet", "ShareLink"]) {
|
||||
const columns = database.pragma(`table_info(${table})`) as Array<{
|
||||
name: string;
|
||||
}>;
|
||||
expect(columns.map((column) => column.name)).toContain("groupId");
|
||||
}
|
||||
|
||||
const groupIndexes = database.pragma("index_list(ShareLink)") as Array<{
|
||||
name: string;
|
||||
unique: number;
|
||||
}>;
|
||||
expect(groupIndexes).toContainEqual(
|
||||
expect.objectContaining({ name: "ShareLink_groupId_key", unique: 1 })
|
||||
);
|
||||
} finally {
|
||||
database.close();
|
||||
}
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue