1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-29 20:32:15 -05:00
mail/test/unit/service/invitation-dao-test.js

89 lines
2.5 KiB
JavaScript
Raw Normal View History

2014-10-07 14:32:23 -04:00
'use strict';
var RestDAO = require('../../../src/js/service/rest'),
2014-12-10 11:20:55 -05:00
InvitationDAO = require('../../../src/js/service/invitation');
2014-10-07 14:32:23 -04:00
describe('Invitation DAO unit tests', function() {
var restDaoStub, invitationDao,
alice = 'zuhause@aol.com',
bob = 'manfred.mustermann@musterdomain.com',
expectedUri = '/invitation/recipient/' + alice + '/sender/' + bob;
beforeEach(function() {
restDaoStub = sinon.createStubInstance(RestDAO);
2014-12-11 12:12:37 -05:00
invitationDao = new InvitationDAO(restDaoStub);
2014-10-07 14:32:23 -04:00
});
describe('initialization', function() {
it('should wire up correctly', function() {
expect(invitationDao._restDao).to.equal(restDaoStub);
expect(invitationDao.invite).to.exist;
2013-11-20 06:17:21 -05:00
});
2014-10-07 14:32:23 -04:00
});
2013-11-20 06:17:21 -05:00
2014-10-07 14:32:23 -04:00
describe('invite', function() {
it('should invite the recipient', function(done) {
2014-12-10 11:39:40 -05:00
restDaoStub.put.returns(resolves());
2014-10-07 14:32:23 -04:00
invitationDao.invite({
recipient: alice,
sender: bob
2014-12-10 11:20:55 -05:00
}).then(function() {
2014-10-07 14:32:23 -04:00
expect(restDaoStub.put.calledWith({}, expectedUri)).to.be.true;
done();
2013-11-20 06:17:21 -05:00
});
});
2014-10-07 14:32:23 -04:00
it('should not work for http error', function(done) {
2014-12-10 11:39:40 -05:00
restDaoStub.put.returns(rejects(new Error()));
2013-11-20 06:17:21 -05:00
2014-10-07 14:32:23 -04:00
invitationDao.invite({
recipient: alice,
sender: bob
2014-12-10 11:20:55 -05:00
}).catch(function(err) {
2014-10-07 14:32:23 -04:00
expect(err).to.exist;
done();
2013-11-20 06:17:21 -05:00
});
2014-10-07 14:32:23 -04:00
});
2013-11-20 06:17:21 -05:00
2014-12-10 11:20:55 -05:00
it('should report erroneous usage', function(done) {
2014-10-07 14:32:23 -04:00
invitationDao.invite({
sender: bob
2014-12-10 11:20:55 -05:00
}, expectError);
invitationDao.invite('asd').catch(expectError);
function expectError(err) {
2014-10-07 14:32:23 -04:00
expect(err).to.exist;
done();
2014-12-10 11:20:55 -05:00
}
2014-10-07 14:32:23 -04:00
});
2014-12-10 11:20:55 -05:00
it('should report erroneous usage', function(done) {
2014-10-07 14:32:23 -04:00
invitationDao.invite({
recipient: alice,
}, expectError);
2013-11-21 09:45:18 -05:00
2014-12-10 11:20:55 -05:00
invitationDao.invite('asd').catch(expectError);
function expectError(err) {
expect(err).to.exist;
done();
}
});
it('should report erroneous usage', function(done) {
2014-10-07 14:32:23 -04:00
invitationDao.invite({
recipient: 123,
sender: 123
}, expectError);
2013-11-21 09:45:18 -05:00
2014-12-10 11:20:55 -05:00
invitationDao.invite('asd').catch(expectError);
2014-12-10 11:20:55 -05:00
function expectError(err) {
2014-10-07 14:32:23 -04:00
expect(err).to.exist;
2014-12-10 11:20:55 -05:00
done();
2014-10-07 14:32:23 -04:00
}
2013-11-20 06:17:21 -05:00
});
});
});