mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
simplify some tests, replace tags when updating tags (like for checklist)
This commit is contained in:
@@ -50,19 +50,9 @@ describe('POST /tasks', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('ignores setting history field');
|
it(`ignores setting userId, history, createdAt,
|
||||||
|
updatedAt, challenge, completed, streak,
|
||||||
it('ignores setting createdAt field');
|
dateCompleted fields`);
|
||||||
|
|
||||||
it('ignores setting updatedAt field');
|
|
||||||
|
|
||||||
it('ignores setting challenge field');
|
|
||||||
|
|
||||||
it('ignores setting completed field');
|
|
||||||
|
|
||||||
it('ignores setting streak field');
|
|
||||||
|
|
||||||
it('ignores setting dateCompleted field');
|
|
||||||
|
|
||||||
it('ignores invalid fields');
|
it('ignores invalid fields');
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -22,25 +22,9 @@ describe('PUT /tasks/:id', () => {
|
|||||||
// task = createdTask
|
// task = createdTask
|
||||||
});
|
});
|
||||||
|
|
||||||
it('ignores setting type field');
|
it(`ignores setting _id, type, userId, history, createdAt,
|
||||||
|
updatedAt, challenge, completed, streak,
|
||||||
it('ignores setting userId field');
|
dateCompleted fields`);
|
||||||
|
|
||||||
it('ignores setting history field');
|
|
||||||
|
|
||||||
it('ignores setting createdAt field');
|
|
||||||
|
|
||||||
it('ignores setting updatedAt field');
|
|
||||||
|
|
||||||
it('ignores setting challenge field');
|
|
||||||
|
|
||||||
it('ignores setting value field');
|
|
||||||
|
|
||||||
it('ignores setting completed field');
|
|
||||||
|
|
||||||
it('ignores setting streak field');
|
|
||||||
|
|
||||||
it('ignores setting dateCompleted field');
|
|
||||||
|
|
||||||
it('ignores invalid fields');
|
it('ignores invalid fields');
|
||||||
});
|
});
|
||||||
@@ -97,6 +81,7 @@ describe('PUT /tasks/:id', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('can update checklists'); // Can it?
|
it('can update checklists'); // Can it?
|
||||||
|
it('can update tags'); // Can it?
|
||||||
});
|
});
|
||||||
|
|
||||||
context('dailys', () => {
|
context('dailys', () => {
|
||||||
@@ -129,6 +114,7 @@ describe('PUT /tasks/:id', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('can update checklists'); // Can it?
|
it('can update checklists'); // Can it?
|
||||||
|
it('can update tags'); // Can it?
|
||||||
|
|
||||||
it('updates repeat, even if frequency is set to daily');
|
it('updates repeat, even if frequency is set to daily');
|
||||||
|
|
||||||
|
|||||||
@@ -174,6 +174,13 @@ api.updateTask = {
|
|||||||
delete req.body.checklist;
|
delete req.body.checklist;
|
||||||
task.checklist = req.body.checklist;
|
task.checklist = req.body.checklist;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If tags are updated -> replace the original ones
|
||||||
|
if (req.body.tags) {
|
||||||
|
delete req.body.tags;
|
||||||
|
task.tags = req.body.tags;
|
||||||
|
}
|
||||||
|
|
||||||
// TODO merge goes deep into objects, it's ok?
|
// TODO merge goes deep into objects, it's ok?
|
||||||
// TODO also check that array and mixed fields are updated correctly without marking modified
|
// TODO also check that array and mixed fields are updated correctly without marking modified
|
||||||
_.merge(task, Tasks.Task.sanitizeUpdate(req.body));
|
_.merge(task, Tasks.Task.sanitizeUpdate(req.body));
|
||||||
|
|||||||
@@ -46,13 +46,13 @@ TaskSchema.plugin(baseModel, {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// A list of additional fields that cannot be set on creation (but can be set on updare)
|
// A list of additional fields that cannot be set on creation (but can be set on updare)
|
||||||
let noCreate = ['completed'];
|
let noCreate = ['completed']; // TODO completed should be removed for updates too?
|
||||||
TaskSchema.statics.sanitizeCreate = function sanitizeCreate (createObj) {
|
TaskSchema.statics.sanitizeCreate = function sanitizeCreate (createObj) {
|
||||||
return Task.sanitize(createObj, noCreate); // eslint-disable-line no-use-before-define
|
return Task.sanitize(createObj, noCreate); // eslint-disable-line no-use-before-define
|
||||||
};
|
};
|
||||||
|
|
||||||
// A list of additional fields that cannot be updated (but can be set on creation)
|
// A list of additional fields that cannot be updated (but can be set on creation)
|
||||||
let noUpdate = ['_id', 'type']; // TODO should prevent changes to checlist.*.id
|
let noUpdate = ['_id', 'type'];
|
||||||
TaskSchema.statics.sanitizeUpdate = function sanitizeUpdate (updateObj) {
|
TaskSchema.statics.sanitizeUpdate = function sanitizeUpdate (updateObj) {
|
||||||
return Task.sanitize(updateObj, noUpdate); // eslint-disable-line no-use-before-define
|
return Task.sanitize(updateObj, noUpdate); // eslint-disable-line no-use-before-define
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user