add account settings page, rest of otp support, stdio credential helper, other misc
[squeep-authentication-module] / test / lib / stdio-credential.js
diff --git a/test/lib/stdio-credential.js b/test/lib/stdio-credential.js
new file mode 100644 (file)
index 0000000..54865cb
--- /dev/null
@@ -0,0 +1,40 @@
+'use strict';
+
+const assert = require('node:assert');
+const sinon = require('sinon');
+const stdioCredential = require('../../lib/stdio-credential');
+const readline = require('node:readline');
+
+describe('stdioCredential', function () {
+  let answerCb, prompt;
+
+  beforeEach(function () {
+    sinon.stub(readline, 'createInterface').callsFake(({ input, output, terminal }) => {
+      return {
+        close: () => undefined,
+        prompt: () => {
+          output.write(prompt);
+        },
+        question: (_message, cb) => {
+          output.write(prompt);
+          answerCb = cb;
+        },
+        setPrompt: (p) => {
+          prompt = p;
+        },
+      };
+    });
+  });
+
+  afterEach(function () {
+    sinon.restore();
+  });
+
+  it('covers', async function () {
+    const input = 'password';
+    const resultP = stdioCredential('prompt>');
+    answerCb(input);
+    const result = await resultP;
+    assert.strictEqual(result, input);
+  });
+}); // stdioCredential
\ No newline at end of file