fix user model, sanitize some fields on task creation, add some tests and comments

This commit is contained in:
Matteo Pagliazzi
2015-12-03 18:15:22 +01:00
parent 506609cc29
commit c0a99eec8b
4 changed files with 36 additions and 7 deletions

View File

@@ -17,7 +17,7 @@ describe('POST /tasks', () => {
});
});
context('checks "type" is present and a valid value', () => {
context('checks "req.body.type"', () => {
it('returns an error if req.body.type is absent', () => {
expect(api.post('/tasks', {
notType: 'habit',
@@ -27,5 +27,26 @@ describe('POST /tasks', () => {
message: t('invalidReqParams'),
});
});
it('returns an error if req.body.type is not valid', () => {
expect(api.post('/tasks', {
type: 'habitF',
})).to.eventually.be.rejected.and.eql({
code: 400,
error: 'BadRequest',
message: t('invalidReqParams'),
});
});
});
context('checks "task.userId"', () => {
it('sets "task.userId" to valid value', () => {
return api.post('/tasks', {
text: 'test habit',
type: 'habit',
}).then((task) => {
expect(task.userId).to.equal(user._id);
});
});
});
});