add account settings page, rest of otp support, stdio credential helper, other misc
[squeep-authentication-module] / test / lib / stdio-credential.js
1 'use strict';
2
3 const assert = require('node:assert');
4 const sinon = require('sinon');
5 const stdioCredential = require('../../lib/stdio-credential');
6 const readline = require('node:readline');
7
8 describe('stdioCredential', function () {
9 let answerCb, prompt;
10
11 beforeEach(function () {
12 sinon.stub(readline, 'createInterface').callsFake(({ input, output, terminal }) => {
13 return {
14 close: () => undefined,
15 prompt: () => {
16 output.write(prompt);
17 },
18 question: (_message, cb) => {
19 output.write(prompt);
20 answerCb = cb;
21 },
22 setPrompt: (p) => {
23 prompt = p;
24 },
25 };
26 });
27 });
28
29 afterEach(function () {
30 sinon.restore();
31 });
32
33 it('covers', async function () {
34 const input = 'password';
35 const resultP = stdioCredential('prompt>');
36 answerCb(input);
37 const result = await resultP;
38 assert.strictEqual(result, input);
39 });
40 }); // stdioCredential