bump package version to 2.0.0
[squeep-test-helper] / test / lib / stub-database.js
1 /* eslint-disable security/detect-object-injection */
2 'use strict';
3
4 const assert = require('node:assert');
5 const sinon = require('sinon');
6 const StubDatabase = require('../../lib/stub-database');
7
8 describe('StubDatabase', function () {
9 let db;
10 async function invokeAllImplementation() {
11 Promise.all(db._implementation.map(async (fn) => {
12 await db[fn]();
13 assert(db[fn].called, fn);
14 }));
15 }
16
17 describe('Base', function () {
18 beforeEach(function () {
19 db = new StubDatabase(sinon);
20 db._reset();
21 });
22 it('covers implementation', invokeAllImplementation);
23 }); // Base
24
25 describe('Extended', function () {
26 class DB extends StubDatabase {
27 constructor() {
28 super(sinon);
29 }
30 get _stubFns() {
31 return [
32 ...super._stubFns,
33 'valueGet',
34 'valueSet',
35 ];
36 }
37 async valueSet() {
38 return this;
39 }
40 }
41 beforeEach(function () {
42 db = new DB();
43 db._reset();
44 });
45 it('covers implementation', invokeAllImplementation);
46 it('covers missing methods', async function () {
47 db = new DB();
48 await db.valueGet();
49 });
50 }); // Extended
51 }); // StubDatabase