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