2014-10-07 14:32:23 -04:00
|
|
|
'use strict';
|
2013-10-29 07:19:27 -04:00
|
|
|
|
2014-11-21 09:06:29 -05:00
|
|
|
var RestDAO = require('../../../src/js/service/rest'),
|
|
|
|
PublicKeyDAO = require('../../../src/js/service/publickey'),
|
|
|
|
appConfig = require('../../../src/js/app-config');
|
2013-10-29 07:19:27 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
describe('Public Key DAO unit tests', function() {
|
2013-10-29 07:19:27 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
var pubkeyDao, restDaoStub;
|
2013-10-29 07:19:27 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
beforeEach(function() {
|
|
|
|
restDaoStub = sinon.createStubInstance(RestDAO);
|
2014-11-21 09:06:29 -05:00
|
|
|
pubkeyDao = new PublicKeyDAO(restDaoStub, appConfig);
|
2014-10-07 14:32:23 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function() {});
|
2013-10-29 07:19:27 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
describe('get', function() {
|
|
|
|
it('should fail', function(done) {
|
|
|
|
restDaoStub.get.yields(42);
|
2013-10-29 07:19:27 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
pubkeyDao.get('id', function(err, key) {
|
|
|
|
expect(err).to.exist;
|
|
|
|
expect(key).to.not.exist;
|
|
|
|
expect(restDaoStub.get.calledOnce).to.be.true;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2013-10-29 07:19:27 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
it('should work', function(done) {
|
|
|
|
restDaoStub.get.yields(null, {
|
|
|
|
_id: '12345',
|
|
|
|
publicKey: 'asdf'
|
2013-10-29 07:19:27 -04:00
|
|
|
});
|
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
pubkeyDao.get('id', function(err, key) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
expect(key).to.exist;
|
|
|
|
expect(key._id).to.exist;
|
|
|
|
expect(key.publicKey).to.exist;
|
|
|
|
expect(restDaoStub.get.calledOnce).to.be.true;
|
|
|
|
done();
|
2013-10-29 07:19:27 -04:00
|
|
|
});
|
|
|
|
});
|
2014-10-07 14:32:23 -04:00
|
|
|
});
|
2013-10-29 07:19:27 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
describe('verify', function() {
|
|
|
|
it('should fail', function(done) {
|
|
|
|
restDaoStub.get.yields(42);
|
2013-11-08 03:29:04 -05:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
pubkeyDao.verify('id', function(err) {
|
|
|
|
expect(err).to.exist;
|
|
|
|
done();
|
2013-11-08 03:29:04 -05:00
|
|
|
});
|
2014-10-07 14:32:23 -04:00
|
|
|
});
|
2013-11-08 03:29:04 -05:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
it('should not error for 400', function(done) {
|
|
|
|
restDaoStub.get.yields({
|
|
|
|
code: 400
|
|
|
|
});
|
2014-01-08 10:04:18 -05:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
pubkeyDao.verify('id', function(err) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
done();
|
2014-01-08 10:04:18 -05:00
|
|
|
});
|
2014-10-07 14:32:23 -04:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should work', function(done) {
|
|
|
|
var uuid = 'c621e328-8548-40a1-8309-adf1955e98a9';
|
|
|
|
restDaoStub.get.yields(null);
|
2014-01-08 10:04:18 -05:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
pubkeyDao.verify(uuid, function(err) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
expect(restDaoStub.get.calledWith(sinon.match(function(arg) {
|
|
|
|
return arg.uri === '/verify/' + uuid && arg.type === 'text';
|
|
|
|
}))).to.be.true;
|
|
|
|
done();
|
2013-11-08 03:29:04 -05:00
|
|
|
});
|
|
|
|
});
|
2014-10-07 14:32:23 -04:00
|
|
|
});
|
2013-11-08 03:29:04 -05:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
describe('get by userId', function() {
|
|
|
|
it('should fail', function(done) {
|
|
|
|
restDaoStub.get.yields(42);
|
2013-10-29 07:19:27 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
pubkeyDao.getByUserId('userId', function(err, key) {
|
|
|
|
expect(err).to.exist;
|
|
|
|
expect(key).to.not.exist;
|
|
|
|
expect(restDaoStub.get.calledOnce).to.be.true;
|
|
|
|
done();
|
2013-10-29 07:19:27 -04:00
|
|
|
});
|
2014-10-07 14:32:23 -04:00
|
|
|
});
|
2013-10-29 07:19:27 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
it('should react to 404', function(done) {
|
|
|
|
restDaoStub.get.yields({
|
|
|
|
code: 404
|
2013-10-29 07:19:27 -04:00
|
|
|
});
|
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
pubkeyDao.getByUserId('userId', function(err, key) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
expect(key).to.not.exist;
|
|
|
|
expect(restDaoStub.get.calledOnce).to.be.true;
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return empty array', function(done) {
|
|
|
|
restDaoStub.get.yields(null, []);
|
2013-10-29 07:19:27 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
pubkeyDao.getByUserId('userId', function(err, key) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
expect(key).to.not.exist;
|
|
|
|
expect(restDaoStub.get.calledOnce).to.be.true;
|
|
|
|
done();
|
2013-10-29 07:19:27 -04:00
|
|
|
});
|
2014-10-07 14:32:23 -04:00
|
|
|
});
|
2013-10-29 07:19:27 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
it('should work', function(done) {
|
|
|
|
restDaoStub.get.yields(null, [{
|
|
|
|
_id: '12345',
|
|
|
|
publicKey: 'asdf'
|
|
|
|
}]);
|
|
|
|
|
|
|
|
pubkeyDao.getByUserId('userId', function(err, key) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
expect(key).to.exist;
|
|
|
|
expect(key._id).to.exist;
|
|
|
|
expect(key.publicKey).to.exist;
|
|
|
|
expect(restDaoStub.get.calledOnce).to.be.true;
|
|
|
|
done();
|
2013-10-29 07:19:27 -04:00
|
|
|
});
|
|
|
|
});
|
2014-10-07 14:32:23 -04:00
|
|
|
});
|
2013-10-29 07:19:27 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
describe('put', function() {
|
|
|
|
it('should fail', function(done) {
|
|
|
|
restDaoStub.put.yields();
|
|
|
|
|
|
|
|
pubkeyDao.put({
|
|
|
|
_id: '12345',
|
|
|
|
publicKey: 'asdf'
|
|
|
|
}, function(err) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
expect(restDaoStub.put.calledOnce).to.be.true;
|
|
|
|
done();
|
2013-10-29 07:19:27 -04:00
|
|
|
});
|
|
|
|
});
|
2014-10-07 14:32:23 -04:00
|
|
|
});
|
2013-10-29 07:19:27 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
describe('remove', function() {
|
|
|
|
it('should fail', function(done) {
|
|
|
|
restDaoStub.remove.yields();
|
2013-10-29 07:19:27 -04:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
pubkeyDao.remove('12345', function(err) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
expect(restDaoStub.remove.calledOnce).to.be.true;
|
|
|
|
done();
|
2013-10-29 07:19:27 -04:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|