test(cloudcmd) _authenticate

This commit is contained in:
coderaiser 2017-11-08 17:37:15 +02:00
parent 430307e574
commit 10255164d5
2 changed files with 78 additions and 10 deletions

View file

@ -1,10 +1,14 @@
'use strict';
const test = require('tape');
const diff = require('sinon-called-with-diff');
const sinon = diff(require('sinon'));
const currify = require('currify');
const DIR = '../../server/';
const cloudcmd = require(DIR + 'cloudcmd');
const config = require(DIR + 'config');
const {_authenticate} = cloudcmd;
test('cloudcmd: args: no', (t) => {
const fn = () => cloudcmd();
@ -45,3 +49,63 @@ test('cloudcmd: defaults: console', (t) => {
t.end();
});
test('cloudcmd: authenticate: reject', (t) => {
const success = sinon.stub();
const emit = sinon.stub();
const socket = {
emit,
};
_authenticate(socket, success, 'hello', 'world');
t.ok(emit.calledWith('reject'), 'should reject');
t.end();
});
test('cloudcmd: authenticate: reject: success', (t) => {
const success = sinon.stub();
const emit = sinon.stub();
const socket = {
emit,
};
_authenticate(socket, success, 'hello', 'world');
t.notOk(success.called, 'should not call success');
t.end();
});
test('cloudcmd: authenticate: accept: success', (t) => {
const success = sinon.stub();
const emit = sinon.stub();
const socket = {
emit,
};
const set = credentials();
const reset = set('hello', 'world');
_authenticate(socket, success, 'hello', 'world');
reset();
t.ok(success.called, 'should call success');
t.end();
});
function credentials() {
const username = config('username');
const password = config('password');
const reset = () => {
config('username', username);
config('password', password);
}
const set = currify((fn, a, b) => {
config('username', a);
config('password', b);
return fn;
});
return set(reset);
}