3 const assert
= require('node:assert');
4 const sinon
= require('sinon');
5 const DatabaseFactory
= require('../../../src/db');
6 const DBErrors
= require('../../../src/db/errors');
8 const noExpectedException
= 'did not get expected exception';
10 describe('DatabaseFactory', function () {
11 let db
, logger
, options
;
13 beforeEach(function () {
22 afterEach(function () {
26 it('fails on invalid engine', function () {
28 new DatabaseFactory(logger
, options
);
29 assert
.fail(noExpectedException
);
31 assert(e
instanceof DBErrors
.UnsupportedEngine
);
35 it('creates sqlite engine', function () {
37 options
.connectionString
= 'sqlite://';
38 db
= new DatabaseFactory(logger
, options
);
39 assert
.strictEqual(db
.constructor.name
, 'SQLiteDatabase');
42 it('creates postgres engine', function () {
44 const stubPgp
= sinon
.stub();
46 enumSql: sinon
.stub().returns({}),
48 stubPgp
.QueryFile
= sinon
.stub().returns({});
49 options
.connectionString
= 'postgresql://';
50 db
= new DatabaseFactory(logger
, options
, stubPgp
);
51 assert
.strictEqual(db
.constructor.name
, 'PostgresDatabase');