1
0
mirror of https://github.com/moparisthebest/mail synced 2024-12-01 13:22:16 -05:00

[WO-61] change method signature for invitation DAO

This commit is contained in:
Felix Hammerl 2013-11-20 16:04:36 +01:00
parent 6fa06fc4e8
commit 8e8947e742
2 changed files with 98 additions and 16 deletions

View File

@ -23,12 +23,19 @@ define(function() {
/** /**
* Notes an invite for the recipient by the sender in the invitation web service * Notes an invite for the recipient by the sender in the invitation web service
* @param {String} recipient User ID of the recipient * @param {String} options.recipient User ID of the recipient
* @param {String} sender User ID of the sender * @param {String} options.sender User ID of the sender
* @param {Function} callback(error, status) Returns information if the invitation worked (INVITE_SUCCESS), if an invitation is already pendin (INVITE_PENDING), or information if an error occurred. * @param {Function} callback(error, status) Returns information if the invitation worked (INVITE_SUCCESS), if an invitation is already pendin (INVITE_PENDING), or information if an error occurred.
*/ */
InvitationDAO.prototype.invite = function(recipient, sender, callback) { InvitationDAO.prototype.invite = function(options, callback) {
this._restDao.put(null, uri(recipient, sender), completed); if (typeof options !== 'object' || typeof options.recipient !== 'string' || typeof options.recipient !== 'string') {
callback({
errMsg: 'erroneous usage of api: incorrect parameters!'
});
return;
}
this._restDao.put(null, uri(options.recipient, options.sender), completed);
function completed(error, res, status) { function completed(error, res, status) {
if (error) { if (error) {
@ -52,12 +59,19 @@ define(function() {
/** /**
* Checks if an invitation for the recipient by the sender is present in the invitation web service * Checks if an invitation for the recipient by the sender is present in the invitation web service
* @param {String} recipient User ID of the recipient * @param {String} options.recipient User ID of the recipient
* @param {String} sender User ID of the sender * @param {String} options.sender User ID of the sender
* @param {Function} callback(error, status) Returns information about the invitation status, either an invitation is already on place (INVITE_PENDING), or not (INVITE_MISSING), or information if an error occurred. * @param {Function} callback(error, status) Returns information about the invitation status, either an invitation is already on place (INVITE_PENDING), or not (INVITE_MISSING), or information if an error occurred.
*/ */
InvitationDAO.prototype.check = function(recipient, sender, callback) { InvitationDAO.prototype.check = function(options, callback) {
this._restDao.get(null, uri(recipient, sender), completed); if (typeof options !== 'object' || typeof options.recipient !== 'string' || typeof options.recipient !== 'string') {
callback({
errMsg: 'erroneous usage of api: incorrect parameters!'
});
return;
}
this._restDao.get(null, uri(options.recipient, options.sender), completed);
function completed(error, res, status) { function completed(error, res, status) {
// 404 is a meaningful return value from the web service // 404 is a meaningful return value from the web service

View File

@ -30,7 +30,10 @@ define(function(require) {
it('should invite the recipient', function(done) { it('should invite the recipient', function(done) {
restDaoStub.put.yieldsAsync(null, undefined, 201); restDaoStub.put.yieldsAsync(null, undefined, 201);
invitationDao.invite(alice, bob, function(err, status) { invitationDao.invite({
recipient: alice,
sender: bob
}, function(err, status) {
expect(err).to.not.exist; expect(err).to.not.exist;
expect(status).to.equal(InvitationDAO.INVITE_SUCCESS); expect(status).to.equal(InvitationDAO.INVITE_SUCCESS);
expect(restDaoStub.put.calledWith(null, expectedUri)).to.be.true; expect(restDaoStub.put.calledWith(null, expectedUri)).to.be.true;
@ -41,7 +44,10 @@ define(function(require) {
it('should point out already invited recipient', function(done) { it('should point out already invited recipient', function(done) {
restDaoStub.put.yieldsAsync(null, undefined, 304); restDaoStub.put.yieldsAsync(null, undefined, 304);
invitationDao.invite(alice, bob, function(err, status) { invitationDao.invite({
recipient: alice,
sender: bob
}, function(err, status) {
expect(err).to.not.exist; expect(err).to.not.exist;
expect(status).to.equal(InvitationDAO.INVITE_PENDING); expect(status).to.equal(InvitationDAO.INVITE_PENDING);
done(); done();
@ -53,7 +59,10 @@ define(function(require) {
errMsg: 'jawollja.' errMsg: 'jawollja.'
}); });
invitationDao.invite(alice, bob, function(err, status) { invitationDao.invite({
recipient: alice,
sender: bob
}, function(err, status) {
expect(err).to.exist; expect(err).to.exist;
expect(status).to.not.exist; expect(status).to.not.exist;
done(); done();
@ -63,19 +72,47 @@ define(function(require) {
it('should not work for unexpected response', function(done) { it('should not work for unexpected response', function(done) {
restDaoStub.put.yieldsAsync(null, undefined, 1337); restDaoStub.put.yieldsAsync(null, undefined, 1337);
invitationDao.invite(alice, bob, function(err, status) { invitationDao.invite({
recipient: alice,
sender: bob
}, function(err, status) {
expect(err).to.exist; expect(err).to.exist;
expect(status).to.not.exist; expect(status).to.not.exist;
done(); done();
}); });
}); });
it('should report erroneous usage', function() {
invitationDao.invite({
sender: bob
}, expectError);
invitationDao.invite({
recipient: alice,
}, expectError);
invitationDao.invite({
recipient: 123,
sender: 123
}, expectError);
invitationDao.invite('asd', expectError);
function expectError(err, status) {
expect(err).to.exist;
expect(status).to.not.exist;
}
});
}); });
describe('check', function() { describe('check', function() {
it('should return pending invite', function(done) { it('should return pending invite', function(done) {
restDaoStub.get.yieldsAsync(null, undefined, 200); restDaoStub.get.yieldsAsync(null, undefined, 200);
invitationDao.check(alice, bob, function(err, status) { invitationDao.check({
recipient: alice,
sender: bob
}, function(err, status) {
expect(err).to.not.exist; expect(err).to.not.exist;
expect(status).to.equal(InvitationDAO.INVITE_PENDING); expect(status).to.equal(InvitationDAO.INVITE_PENDING);
expect(restDaoStub.get.calledWith(null, expectedUri)).to.be.true; expect(restDaoStub.get.calledWith(null, expectedUri)).to.be.true;
@ -88,7 +125,10 @@ define(function(require) {
code: 404 code: 404
}); });
invitationDao.check(alice, bob, function(err, status) { invitationDao.check({
recipient: alice,
sender: bob
}, function(err, status) {
expect(err).to.not.exist; expect(err).to.not.exist;
expect(status).to.equal(InvitationDAO.INVITE_MISSING); expect(status).to.equal(InvitationDAO.INVITE_MISSING);
done(); done();
@ -101,7 +141,10 @@ define(function(require) {
errMsg: 'jawollja.' errMsg: 'jawollja.'
}); });
invitationDao.check(alice, bob, function(err, status) { invitationDao.check({
recipient: alice,
sender: bob
}, function(err, status) {
expect(err).to.exist; expect(err).to.exist;
expect(status).to.not.exist; expect(status).to.not.exist;
done(); done();
@ -111,12 +154,37 @@ define(function(require) {
it('should not work for unexpected response', function(done) { it('should not work for unexpected response', function(done) {
restDaoStub.get.yieldsAsync(null, undefined, 1337); restDaoStub.get.yieldsAsync(null, undefined, 1337);
invitationDao.check(alice, bob, function(err, status) { invitationDao.check({
recipient: alice,
sender: bob
}, function(err, status) {
expect(err).to.exist; expect(err).to.exist;
expect(status).to.not.exist; expect(status).to.not.exist;
done(); done();
}); });
}); });
it('should report erroneous usage', function() {
invitationDao.check({
sender: bob
}, expectError);
invitationDao.check({
recipient: alice,
}, expectError);
invitationDao.check({
recipient: 123,
sender: 123
}, expectError);
invitationDao.check('asd', expectError);
function expectError(err, status) {
expect(err).to.exist;
expect(status).to.not.exist;
}
});
}); });
}); });
}); });