initial commit
[squeep-test-helper] / test / lib / stub-database.js
diff --git a/test/lib/stub-database.js b/test/lib/stub-database.js
new file mode 100644 (file)
index 0000000..883cc09
--- /dev/null
@@ -0,0 +1,44 @@
+/* eslint-env mocha */
+/* eslint-disable security/detect-object-injection */
+'use strict';
+
+const assert = require('assert');
+const StubDatabase = require('../../lib/stub-database');
+
+describe('StubDatabase', function () {
+  let db;
+  async function invokeAllImplementation() {
+    Promise.all(db._implementation.map(async (fn) => {
+      await db[fn]();
+      assert(db[fn].called, fn);
+    }));
+  }
+
+  describe('Base', function () {
+    beforeEach(function () {
+      db = new StubDatabase();
+      db._reset();
+    });
+    it('covers implementation', invokeAllImplementation);
+  }); // Base
+
+  describe('Extended', function () {
+    class DB extends StubDatabase {
+      get _stubFns() {
+        return [
+          ...super._stubFns,
+          'valueGet',
+          'valueSet',
+        ];
+      }
+      async valueSet() {
+        return this;
+      }
+    }
+    beforeEach(function () {
+      db = new DB();
+      db._reset();
+    });
+    it('covers implementation', invokeAllImplementation);
+  }); // Extended
+}); // StubDatabase