Fixed update query to revert challenge tags when broken (#9791)

This commit is contained in:
Keith Holliday
2018-01-15 10:31:33 -07:00
committed by GitHub
parent 745f930749
commit 935fa1baae
2 changed files with 9 additions and 3 deletions

View File

@@ -149,13 +149,19 @@ describe('POST /challenges/:challengeId/winner/:winnerId', () => {
await sleep(0.5);
let tasks = await winningUser.get('/tasks/user');
let testTask = _.find(tasks, (task) => {
const tasks = await winningUser.get('/tasks/user');
const testTask = _.find(tasks, (task) => {
return task.text === taskText;
});
const updatedUser = await winningUser.sync();
const challengeTag = updatedUser.tags.find(tags => {
return tags.id === challenge._id;
});
expect(testTask.challenge.broken).to.eql('CHALLENGE_CLOSED');
expect(testTask.challenge.winner).to.eql(winningUser.profile.name);
expect(challengeTag.challenge).to.eql('false');
});
});
});

View File

@@ -341,7 +341,7 @@ schema.methods.closeChal = async function closeChal (broken = {}) {
// Set the challenge tag to non-challenge status and remove the challenge from the user's challenges
User.update({
challenges: challenge._id,
'tags._id': challenge._id,
'tags.id': challenge._id,
}, {
$set: {'tags.$.challenge': false},
$pull: {challenges: challenge._id},