mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-18 07:07:35 +01:00
fix user model, sanitize some fields on task creation, add some tests and comments
This commit is contained in:
@@ -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);
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user