1
0
mirror of https://github.com/moparisthebest/mail synced 2024-11-29 20:32:15 -05:00

remove unused #check api

This commit is contained in:
Felix Hammerl 2014-03-12 16:57:14 +01:00
parent 431ae8cd89
commit 9367ba4f25
2 changed files with 2 additions and 134 deletions

View File

@ -35,7 +35,8 @@ define(function() {
return; return;
} }
this._restDao.put({}, uri(options.recipient, options.sender), completed); var uri = '/invitation/recipient/' + options.recipient + '/sender/' + options.sender;
this._restDao.put({}, uri, completed);
function completed(error, res, status) { function completed(error, res, status) {
if (error) { if (error) {
@ -57,53 +58,5 @@ define(function() {
} }
}; };
/**
* Checks if an invitation for the recipient by the sender is present in the invitation web service
* @param {String} options.recipient User ID of the recipient
* @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.
*/
InvitationDAO.prototype.check = function(options, callback) {
if (typeof options !== 'object' || typeof options.recipient !== 'string' || typeof options.recipient !== 'string') {
callback({
errMsg: 'erroneous usage of api: incorrect parameters!'
});
return;
}
this._restDao.get({
uri: uri(options.recipient, options.sender),
type: 'text'
}, completed);
function completed(error, res, status) {
// 404 is a meaningful return value from the web service
if (error && error.code !== 404) {
callback(error);
return;
}
if (error && error.code === 404) {
callback(null, InvitationDAO.INVITE_MISSING);
return;
} else if (status === 200) {
callback(null, InvitationDAO.INVITE_PENDING);
return;
}
callback({
errMsg: 'unexpected invitation state'
});
}
};
//
// Helper functions
//
function uri(a, b) {
return '/invitation/recipient/' + a + '/sender/' + b;
}
return InvitationDAO; return InvitationDAO;
}); });

View File

@ -104,90 +104,5 @@ define(function(require) {
} }
}); });
}); });
describe('check', function() {
it('should return pending invite', function(done) {
restDaoStub.get.yieldsAsync(null, undefined, 200);
invitationDao.check({
recipient: alice,
sender: bob
}, function(err, status) {
expect(err).to.not.exist;
expect(status).to.equal(InvitationDAO.INVITE_PENDING);
expect(restDaoStub.get.calledWith({
uri: expectedUri,
type: 'text'
})).to.be.true;
done();
});
});
it('should return missing invite', function(done) {
restDaoStub.get.yieldsAsync({
code: 404
});
invitationDao.check({
recipient: alice,
sender: bob
}, function(err, status) {
expect(err).to.not.exist;
expect(status).to.equal(InvitationDAO.INVITE_MISSING);
done();
});
});
it('should not work for http error', function(done) {
restDaoStub.get.yieldsAsync({
code: 1337,
errMsg: 'jawollja.'
});
invitationDao.check({
recipient: alice,
sender: bob
}, function(err, status) {
expect(err).to.exist;
expect(status).to.not.exist;
done();
});
});
it('should not work for unexpected response', function(done) {
restDaoStub.get.yieldsAsync(null, undefined, 1337);
invitationDao.check({
recipient: alice,
sender: bob
}, function(err, status) {
expect(err).to.exist;
expect(status).to.not.exist;
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;
}
});
});
}); });
}); });