mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 22:57:21 +01:00
fix tasks updating and reminders tests
This commit is contained in:
@@ -152,14 +152,14 @@ describe('POST /tasks/user', () => {
|
|||||||
text: 'test habit',
|
text: 'test habit',
|
||||||
type: 'habit',
|
type: 'habit',
|
||||||
reminders: [
|
reminders: [
|
||||||
{id: id1, startDate: new Date(), time: new Date()},
|
{_id: id1, startDate: new Date(), time: new Date()},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(task.reminders).to.be.an('array');
|
expect(task.reminders).to.be.an('array');
|
||||||
expect(task.reminders.length).to.eql(1);
|
expect(task.reminders.length).to.eql(1);
|
||||||
expect(task.reminders[0]).to.be.an('object');
|
expect(task.reminders[0]).to.be.an('object');
|
||||||
expect(task.reminders[0].id).to.eql(id1);
|
expect(task.reminders[0]._id).to.eql(id1);
|
||||||
expect(task.reminders[0].startDate).to.be.a('string'); // json doesn't have dates
|
expect(task.reminders[0].startDate).to.be.a('string'); // json doesn't have dates
|
||||||
expect(task.reminders[0].time).to.be.a('string');
|
expect(task.reminders[0].time).to.be.a('string');
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -80,14 +80,14 @@ describe('PUT /tasks/:id', () => {
|
|||||||
|
|
||||||
let savedDaily = await user.put(`/tasks/${daily._id}`, {
|
let savedDaily = await user.put(`/tasks/${daily._id}`, {
|
||||||
reminders: [
|
reminders: [
|
||||||
{id: id1, time: new Date(), startDate: new Date()},
|
{_id: id1, time: new Date(), startDate: new Date()},
|
||||||
{id: id2, time: new Date(), startDate: new Date()},
|
{_id: id2, time: new Date(), startDate: new Date()},
|
||||||
],
|
],
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(savedDaily.reminders.length).to.equal(2);
|
expect(savedDaily.reminders.length).to.equal(2);
|
||||||
expect(savedDaily.reminders[0].id).to.equal(id1);
|
expect(savedDaily.reminders[0]._id).to.equal(id1);
|
||||||
expect(savedDaily.reminders[1].id).to.equal(id2);
|
expect(savedDaily.reminders[1]._id).to.equal(id2);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -304,24 +304,7 @@ api.updateTask = {
|
|||||||
throw new NotFound(res.t('taskNotFound'));
|
throw new NotFound(res.t('taskNotFound'));
|
||||||
}
|
}
|
||||||
|
|
||||||
// If reminders are updated -> replace the original ones
|
Tasks.Task.sanitize(req.body);
|
||||||
if (req.body.reminders) {
|
|
||||||
task.reminders = req.body.reminders;
|
|
||||||
delete req.body.reminders;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If checklist is updated -> replace the original one
|
|
||||||
if (req.body.checklist) {
|
|
||||||
task.checklist = req.body.checklist;
|
|
||||||
delete req.body.checklist;
|
|
||||||
}
|
|
||||||
|
|
||||||
// If tags are updated -> replace the original ones
|
|
||||||
if (req.body.tags) {
|
|
||||||
task.tags = req.body.tags;
|
|
||||||
delete req.body.tags;
|
|
||||||
}
|
|
||||||
|
|
||||||
// TODO we have to convert task to an object because otherwise things don't get merged correctly. Bad for performances?
|
// TODO we have to convert task to an object because otherwise things don't get merged correctly. Bad for performances?
|
||||||
// TODO regarding comment above, make sure other models with nested fields are using this trick too
|
// TODO regarding comment above, make sure other models with nested fields are using this trick too
|
||||||
_.assign(task, common.ops.updateTask(task.toObject(), req));
|
_.assign(task, common.ops.updateTask(task.toObject(), req));
|
||||||
|
|||||||
@@ -60,12 +60,6 @@ TaskSchema.statics.sanitizeCreate = function sanitizeCreate (createObj) {
|
|||||||
return this.sanitize(createObj, noCreate);
|
return this.sanitize(createObj, noCreate);
|
||||||
};
|
};
|
||||||
|
|
||||||
// A list of additional fields that cannot be updated (but can be set on creation)
|
|
||||||
let noUpdate = ['_id', 'type'];
|
|
||||||
TaskSchema.statics.sanitizeUpdate = function sanitizeUpdate (updateObj) {
|
|
||||||
return this.sanitize(updateObj, noUpdate);
|
|
||||||
};
|
|
||||||
|
|
||||||
// Sanitize checklist objects (disallowing _id)
|
// Sanitize checklist objects (disallowing _id)
|
||||||
TaskSchema.statics.sanitizeChecklist = function sanitizeChecklist (checklistObj) {
|
TaskSchema.statics.sanitizeChecklist = function sanitizeChecklist (checklistObj) {
|
||||||
delete checklistObj._id;
|
delete checklistObj._id;
|
||||||
|
|||||||
Reference in New Issue
Block a user