bump package version to 1.0.2
[squeep-test-helper] / lib / stub-database.js
1 /* eslint-disable class-methods-use-this */
2 'use strict';
3
4 const sinon = require('sinon'); // eslint-disable-line node/no-unpublished-require
5
6 class StubDatabase {
7 constructor() {
8 this._implementation.forEach((fn) => {
9 if (!(fn in this)) {
10 this[fn] = async () => { /* */ }; // eslint-disable-line security/detect-object-injection
11 }
12 });
13 }
14
15 get _implementation() {
16 return [
17 ...this._spyFns,
18 ...this._stubFns,
19 ];
20 }
21
22 get _spyFns() {
23 return [
24 'context',
25 'transaction',
26 ];
27 }
28
29 get _stubFns() {
30 return [
31 'initialize',
32 'healthCheck',
33 ];
34 }
35
36 _reset() {
37 this._spyFns.forEach((fn) => {
38 sinon.spy(this, fn);
39 });
40 this._stubFns.forEach((fn) => {
41 sinon.stub(this, fn);
42 });
43 }
44
45 async context(fn) {
46 await fn({});
47 }
48
49 async transaction(dbCtx, fn) {
50 await fn(dbCtx);
51 }
52
53 }
54
55 module.exports = StubDatabase;