initial commit
[squeep-authentication-module] / test / stub-db.js
diff --git a/test/stub-db.js b/test/stub-db.js
new file mode 100644 (file)
index 0000000..2d1ce77
--- /dev/null
@@ -0,0 +1,31 @@
+/* eslint-disable security/detect-object-injection */
+'use strict';
+
+const sinon = require('sinon'); // eslint-disable-line node/no-unpublished-require
+
+const spyFns = [
+  'context',
+  'transaction',
+];
+
+const stubFns = [
+  'authenticationSuccess',
+  'authenticationGet',
+  'authenticationUpsert',
+];
+
+const stubDatabase = {
+  _implementation: [ ...spyFns, ...stubFns ],
+  _reset: () => {
+    spyFns.forEach((fn) => sinon.spy(stubDatabase, fn));
+    stubFns.forEach((fn) => sinon.stub(stubDatabase, fn));
+  },
+  context: async (fn) => await fn({}),
+  transaction: async (dbCtx, fn) => await fn(dbCtx),
+};
+
+stubFns.forEach((fn) => {
+  stubDatabase[fn] = () => {};
+});
+
+module.exports = stubDatabase;
\ No newline at end of file