1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-11 03:35:01 -05:00
mail/test/unit/service/publickey-dao-test.js

162 lines
4.7 KiB
JavaScript
Raw Normal View History

2014-10-07 14:32:23 -04:00
'use strict';
var RestDAO = require('../../../src/js/service/rest'),
PublicKeyDAO = require('../../../src/js/service/publickey'),
appConfig = require('../../../src/js/app-config');
2014-10-07 14:32:23 -04:00
describe('Public Key DAO unit tests', function() {
2014-10-07 14:32:23 -04:00
var pubkeyDao, restDaoStub;
2014-10-07 14:32:23 -04:00
beforeEach(function() {
restDaoStub = sinon.createStubInstance(RestDAO);
pubkeyDao = new PublicKeyDAO(restDaoStub, appConfig);
2014-10-07 14:32:23 -04:00
});
afterEach(function() {});
2014-10-07 14:32:23 -04:00
describe('get', function() {
it('should fail', function(done) {
restDaoStub.get.yields(42);
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();
});
});
2014-10-07 14:32:23 -04:00
it('should work', function(done) {
restDaoStub.get.yields(null, {
_id: '12345',
publicKey: 'asdf'
});
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();
});
});
2014-10-07 14:32:23 -04:00
});
2014-10-07 14:32:23 -04:00
describe('verify', function() {
it('should fail', function(done) {
restDaoStub.get.yields(42);
2014-10-07 14:32:23 -04:00
pubkeyDao.verify('id', function(err) {
expect(err).to.exist;
done();
});
2014-10-07 14:32:23 -04:00
});
2014-10-07 14:32:23 -04:00
it('should not error for 400', function(done) {
restDaoStub.get.yields({
code: 400
});
2014-10-07 14:32:23 -04:00
pubkeyDao.verify('id', function(err) {
expect(err).to.not.exist;
done();
});
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-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();
});
});
2014-10-07 14:32:23 -04:00
});
2014-10-07 14:32:23 -04:00
describe('get by userId', function() {
it('should fail', function(done) {
restDaoStub.get.yields(42);
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();
});
2014-10-07 14:32:23 -04:00
});
2014-10-07 14:32:23 -04:00
it('should react to 404', function(done) {
restDaoStub.get.yields({
code: 404
});
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, []);
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();
});
2014-10-07 14:32:23 -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();
});
});
2014-10-07 14:32:23 -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();
});
});
2014-10-07 14:32:23 -04:00
});
2014-10-07 14:32:23 -04:00
describe('remove', function() {
it('should fail', function(done) {
restDaoStub.remove.yields();
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();
});
});
});
});