2 /* eslint-disable capitalized-comments */
6 const assert
= require('assert');
7 // eslint-disable-next-line node/no-unpublished-require
8 const sinon
= require('sinon');
9 const DatabaseFactory
= require('../../../src/db');
10 const DBErrors
= require('../../../src/db/errors');
12 const noExpectedException
= 'did not get expected exception';
14 describe('DatabaseFactory', function () {
15 let db
, logger
, options
;
17 beforeEach(function () {
26 afterEach(function () {
30 it('fails on invalid engine', function () {
32 new DatabaseFactory(logger
, options
);
33 assert
.fail(noExpectedException
);
35 assert(e
instanceof DBErrors
.UnsupportedEngine
);
39 it('creates sqlite engine', function () {
41 options
.connectionString
= 'sqlite://';
42 db
= new DatabaseFactory(logger
, options
);
43 assert
.strictEqual(db
.constructor.name
, 'SQLiteDatabase');
46 it('creates postgres engine', function () {
48 const stubPgp
= sinon
.stub();
50 enumSql: sinon
.stub().returns({}),
52 stubPgp
.QueryFile
= sinon
.stub().returns({});
53 options
.connectionString
= 'postgresql://';
54 db
= new DatabaseFactory(logger
, options
, stubPgp
);
55 assert
.strictEqual(db
.constructor.name
, 'PostgresDatabase');