3 const assert
= require('node:assert');
4 const sinon
= require('sinon');
5 const DB
= require('../../../src/db');
6 const DBErrors
= require('../../../src/db/errors');
7 const DatabasePostgres
= require('../../../src/db/postgres');
8 const DatabaseSQLite
= require('../../../src/db/sqlite');
9 const stubLogger
= require('../../stub-logger');
11 describe('DatabaseFactory', function () {
13 beforeEach(function () {
21 afterEach(function () {
24 it('gets engines', function () {
25 const result
= DB
.Engines
;
26 assert(result
instanceof Object
);
27 assert(Object
.keys(result
).length
);
29 it('creates postgres db', function () {
30 options
.db
.connectionString
= 'postgresql://blah';
31 const db
= new DB(logger
, options
);
32 assert(db
instanceof DatabasePostgres
);
34 it('creates sqlite db', function () {
35 options
.db
.connectionString
= 'sqlite://:memory:';
36 const db
= new DB(logger
, options
);
37 assert(db
instanceof DatabaseSQLite
);
39 it('handles missing db', function () {
40 delete options
.db
.connectionString
;
42 new DB(logger
, options
);
43 assert
.fail('did not get expected exception');
45 assert(e
instanceof DBErrors
.UnsupportedEngine
);
48 }); // DatabaseFactory