Files
TREK/server/tests/unit/nest/database/database-engine.module.test.ts
T
Isaias Tavares 2e3762afe1 feat(db): run TREK on PostgreSQL
TREK runs on PostgreSQL when TREK_DB_URL is set, and on SQLite as before
otherwise: an engine port under src/db/engine, the dialect helpers under
src/db/dialect, a Postgres baseline for the migrations up to the cut,
pg_dump/pg_restore backups, a probe of every repository method against a
real server and a Postgres test lane in CI.
2026-11-17 23:03:33 +01:00

30 lines
1.1 KiB
TypeScript

/**
* DatabaseEngineModule: one engine per container, shared by every injector.
*/
import {
DatabaseEngineModule,
DATABASE_ENGINE,
DATABASE_SETTINGS,
} from '../../../../src/nest/database/database-engine.module';
import { Test } from '@nestjs/testing';
import { describe, expect, it } from 'vitest';
describe('DatabaseEngineModule', () => {
it('ENGINE-DI-001: provides one engine instance, so state an engine keeps is the same wherever it is injected', async () => {
const moduleRef = await Test.createTestingModule({ imports: [DatabaseEngineModule] }).compile();
const engine = moduleRef.get(DATABASE_ENGINE);
expect(moduleRef.get(DATABASE_ENGINE)).toBe(engine);
expect(engine.id).toBe('sqlite');
});
it('ENGINE-DI-002: the settings are read from the environment once and the engine is resolved from them', async () => {
const moduleRef = await Test.createTestingModule({ imports: [DatabaseEngineModule] }).compile();
const settings = moduleRef.get(DATABASE_SETTINGS);
expect(settings.engine).toBe('sqlite');
expect(moduleRef.get(DATABASE_SETTINGS)).toBe(settings);
});
});