Files
Termix/src/backend/tests/database/repositories/test-support.ts
T
LukeGus 7f43932429 refactor(tests): move backend tests into src/backend/tests mirror tree
Backend *.test.ts files (and the test-support harness) no longer sit next
to source files; they live under src/backend/tests/ mirroring the source
layout. Imports rewritten accordingly; CLAUDE.md convention updated.
2026-07-16 04:31:29 -05:00

32 lines
871 B
TypeScript

import Database from "better-sqlite3";
import { drizzle } from "drizzle-orm/better-sqlite3";
import * as schema from "../../../database/db/schema.js";
import type { DatabaseContext } from "../../../database/repositories/database-context.js";
export class TestSqliteDatabase {
private sqlite: Database.Database | null = null;
private context: DatabaseContext | null = null;
async connect(): Promise<DatabaseContext> {
if (this.context) return this.context;
this.sqlite = new Database(":memory:");
this.sqlite.exec("PRAGMA foreign_keys = ON");
this.context = {
dialect: "sqlite",
drizzle: drizzle(this.sqlite, { schema }),
sqlite: this.sqlite,
};
return this.context;
}
async close(): Promise<void> {
if (this.sqlite) {
this.sqlite.close();
this.sqlite = null;
this.context = null;
}
}
}