mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 14:47:53 +01:00
Challenge checklist fix (#7963)
* fix(challenges): don't wipe user xlists * Add test for challenge checklists not syncing to user
This commit is contained in:
committed by
Sabe Jones
parent
95d33a1dff
commit
7702f9dccc
@@ -6,8 +6,10 @@ import common from '../../../../../common/';
|
|||||||
import { each, find } from 'lodash';
|
import { each, find } from 'lodash';
|
||||||
|
|
||||||
describe('Challenge Model', () => {
|
describe('Challenge Model', () => {
|
||||||
let guild, leader, challenge, task;
|
let guild, leader, challenge, task, tasksToTest;
|
||||||
let tasksToTest = {
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
tasksToTest = {
|
||||||
habit: {
|
habit: {
|
||||||
text: 'test habit',
|
text: 'test habit',
|
||||||
type: 'habit',
|
type: 'habit',
|
||||||
@@ -30,8 +32,6 @@ describe('Challenge Model', () => {
|
|||||||
type: 'reward',
|
type: 'reward',
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
guild = new Group({
|
guild = new Group({
|
||||||
name: 'test party',
|
name: 'test party',
|
||||||
type: 'guild',
|
type: 'guild',
|
||||||
@@ -195,6 +195,24 @@ describe('Challenge Model', () => {
|
|||||||
expect(updatedUserTask.date).to.exist;
|
expect(updatedUserTask.date).to.exist;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('does not update checklists on the user task', async () => {
|
||||||
|
task = new Tasks.todo(Tasks.Task.sanitize(tasksToTest.todo)); // eslint-disable-line babel/new-cap
|
||||||
|
task.challenge.id = challenge._id;
|
||||||
|
await task.save();
|
||||||
|
|
||||||
|
await challenge.addTasks([task]);
|
||||||
|
|
||||||
|
task.checklist.push({
|
||||||
|
text: 'a new checklist',
|
||||||
|
});
|
||||||
|
await challenge.updateTask(task);
|
||||||
|
|
||||||
|
let updatedLeader = await User.findOne({_id: leader._id});
|
||||||
|
let updatedUserTask = await Tasks.Task.findById(updatedLeader.tasksOrder.todos[0]);
|
||||||
|
|
||||||
|
expect(updatedUserTask.checklist).to.deep.equal([]);
|
||||||
|
});
|
||||||
|
|
||||||
it('updates daily specific field to challenge and challenge members', async () => {
|
it('updates daily specific field to challenge and challenge members', async () => {
|
||||||
task = new Tasks.daily(Tasks.Task.sanitize(tasksToTest.daily)); // eslint-disable-line babel/new-cap
|
task = new Tasks.daily(Tasks.Task.sanitize(tasksToTest.daily)); // eslint-disable-line babel/new-cap
|
||||||
task.challenge.id = challenge._id;
|
task.challenge.id = challenge._id;
|
||||||
|
|||||||
@@ -75,7 +75,7 @@ schema.methods.canView = function canViewChallenge (user, group) {
|
|||||||
function _syncableAttrs (task) {
|
function _syncableAttrs (task) {
|
||||||
let t = task.toObject(); // lodash doesn't seem to like _.omit on Document
|
let t = task.toObject(); // lodash doesn't seem to like _.omit on Document
|
||||||
// only sync/compare important attrs
|
// only sync/compare important attrs
|
||||||
let omitAttrs = ['_id', 'userId', 'challenge', 'history', 'tags', 'completed', 'streak', 'notes', 'updatedAt'];
|
let omitAttrs = ['_id', 'userId', 'challenge', 'history', 'tags', 'completed', 'streak', 'notes', 'updatedAt', 'checklist'];
|
||||||
if (t.type !== 'reward') omitAttrs.push('value');
|
if (t.type !== 'reward') omitAttrs.push('value');
|
||||||
return _.omit(t, omitAttrs);
|
return _.omit(t, omitAttrs);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ script(type='text/ng-template', id='partials/options.social.challenges.detail.ht
|
|||||||
// Edit button
|
// Edit button
|
||||||
div(bindonce='challenge', ng-if='challenge.leader._id==user._id || user.contributor.admin')
|
div(bindonce='challenge', ng-if='challenge.leader._id==user._id || user.contributor.admin')
|
||||||
div(ng-hide='challenge._locked==false')
|
div(ng-hide='challenge._locked==false')
|
||||||
// button.btn.btn-sm.btn-default(ng-click='edit(challenge)')=env.t('edit')
|
button.btn.btn-sm.btn-default(ng-click='edit(challenge)')=env.t('edit')
|
||||||
button.btn.btn-sm.btn-success(ng-click='clone(challenge)')=env.t('clone')
|
button.btn.btn-sm.btn-success(ng-click='clone(challenge)')=env.t('clone')
|
||||||
button.btn.btn-sm.btn-warning(ng-click='close(challenge, $event)', tooltip=env.t('deleteOrSelect'))=env.t('endChallenge')
|
button.btn.btn-sm.btn-warning(ng-click='close(challenge, $event)', tooltip=env.t('deleteOrSelect'))=env.t('endChallenge')
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user