62f5f3d14fa0eb7b4e6f48a7478c0f1601b76c47
[squeep-authentication-module] / test / stub-db.js
1 /* eslint-disable security/detect-object-injection */
2 'use strict';
3
4 const sinon = require('sinon'); // eslint-disable-line node/no-unpublished-require
5
6 const spyFns = [
7 'context',
8 'transaction',
9 ];
10
11 const stubFns = [
12 'authenticationGet',
13 'authenticationInsertIdentifier',
14 'authenticationSuccess',
15 'authenticationUpdateCredential',
16 'authenticationUpdateOTPKey',
17 ];
18
19 const stubDatabase = {
20 _implementation: [ ...spyFns, ...stubFns ],
21 _reset: () => {
22 spyFns.forEach((fn) => sinon.spy(stubDatabase, fn));
23 stubFns.forEach((fn) => sinon.stub(stubDatabase, fn));
24 },
25 context: async (fn) => await fn({}),
26 transaction: async (dbCtx, fn) => await fn(dbCtx),
27 };
28
29 stubFns.forEach((fn) => {
30 stubDatabase[fn] = () => undefined;
31 });
32
33 module.exports = stubDatabase;