@accounter/server
Version:
Accounter GraphQL server
36 lines • 1.07 kB
JavaScript
import { connectTestDb, closeTestDb } from './db-connection.js';
import { runMigrationsIfNeeded } from './db-migrations.js';
import { seedAdminOnce } from './db-fixtures.js';
import { withTestTransaction } from './test-transaction.js';
export class TestDatabase {
pool = null;
async connect() {
this.pool = await connectTestDb();
return this.pool;
}
getPool() {
if (!this.pool)
throw new Error('TestDatabase not connected');
return this.pool;
}
async ensureLatestSchema() {
if (!this.pool)
await this.connect();
await runMigrationsIfNeeded(this.getPool());
}
async seedAdmin() {
if (!this.pool)
await this.connect();
await seedAdminOnce(this.getPool());
}
async withTransaction(fn) {
if (!this.pool)
await this.connect();
return withTestTransaction(this.getPool(), fn);
}
async close() {
await closeTestDb();
this.pool = null;
}
}
//# sourceMappingURL=test-database.js.map