2014-10-07 14:32:23 -04:00
|
|
|
'use strict';
|
|
|
|
|
2014-11-21 09:06:29 -05:00
|
|
|
var RestDAO = require('../../../src/js/service/rest'),
|
|
|
|
InvitationDAO = require('../../../src/js/service/invitation'),
|
|
|
|
appConfig = require('../../../src/js/app-config');
|
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-11-21 09:06:29 -05:00
|
|
|
invitationDao = new InvitationDAO(restDaoStub, appConfig);
|
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;
|
|
|
|
expect(InvitationDAO.INVITE_MISSING).to.equal(1);
|
|
|
|
expect(InvitationDAO.INVITE_PENDING).to.equal(2);
|
|
|
|
expect(InvitationDAO.INVITE_SUCCESS).to.equal(4);
|
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) {
|
|
|
|
restDaoStub.put.yieldsAsync(null, undefined, 201);
|
|
|
|
|
|
|
|
invitationDao.invite({
|
|
|
|
recipient: alice,
|
|
|
|
sender: bob
|
|
|
|
}, function(err, status) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
expect(status).to.equal(InvitationDAO.INVITE_SUCCESS);
|
|
|
|
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 point out already invited recipient', function(done) {
|
|
|
|
restDaoStub.put.yieldsAsync(null, undefined, 304);
|
|
|
|
|
|
|
|
invitationDao.invite({
|
|
|
|
recipient: alice,
|
|
|
|
sender: bob
|
|
|
|
}, function(err, status) {
|
|
|
|
expect(err).to.not.exist;
|
|
|
|
expect(status).to.equal(InvitationDAO.INVITE_PENDING);
|
|
|
|
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-10-07 14:32:23 -04:00
|
|
|
it('should not work for http error', function(done) {
|
|
|
|
restDaoStub.put.yieldsAsync({
|
|
|
|
errMsg: 'jawollja.'
|
2013-11-20 06:17:21 -05:00
|
|
|
});
|
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
invitationDao.invite({
|
|
|
|
recipient: alice,
|
|
|
|
sender: bob
|
|
|
|
}, function(err, status) {
|
|
|
|
expect(err).to.exist;
|
|
|
|
expect(status).to.not.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-10-07 14:32:23 -04:00
|
|
|
it('should not work for unexpected response', function(done) {
|
|
|
|
restDaoStub.put.yieldsAsync(null, undefined, 1337);
|
|
|
|
|
|
|
|
invitationDao.invite({
|
|
|
|
recipient: alice,
|
|
|
|
sender: bob
|
|
|
|
}, function(err, status) {
|
|
|
|
expect(err).to.exist;
|
|
|
|
expect(status).to.not.exist;
|
|
|
|
done();
|
2013-11-20 06:17:21 -05:00
|
|
|
});
|
2014-10-07 14:32:23 -04:00
|
|
|
});
|
2013-11-20 10:04:36 -05:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
it('should report erroneous usage', function() {
|
|
|
|
invitationDao.invite({
|
|
|
|
sender: bob
|
|
|
|
}, expectError);
|
2013-11-20 10:04:36 -05:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
invitationDao.invite({
|
|
|
|
recipient: alice,
|
|
|
|
}, expectError);
|
2013-11-21 09:45:18 -05:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
invitationDao.invite({
|
|
|
|
recipient: 123,
|
|
|
|
sender: 123
|
|
|
|
}, expectError);
|
2013-11-21 09:45:18 -05:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
invitationDao.invite('asd', expectError);
|
2013-11-20 10:04:36 -05:00
|
|
|
|
2014-10-07 14:32:23 -04:00
|
|
|
function expectError(err, status) {
|
|
|
|
expect(err).to.exist;
|
|
|
|
expect(status).to.not.exist;
|
|
|
|
}
|
2013-11-20 06:17:21 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|