Skip to content

Commit

Permalink
chore(tests): tests to go along with #1883 challenges fix
Browse files Browse the repository at this point in the history
  • Loading branch information
lefnire committed Feb 15, 2014
1 parent 191b789 commit 78fcdd2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/controllers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ api.score = function(req, res, next) {
if (err) return next(err);
if (!chal) {
task.challenge.broken = 'CHALLENGE_DELETED';
user.markModified('tasks');
return user.save();
}
var t = chal.tasks[task.id];
Expand Down
27 changes: 27 additions & 0 deletions test/api.mocha.js
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,33 @@ describe('API', function () {
});
});

it('Challenge deleted, breaks task link', function (done) {
var itThis = this;
request.del(baseURL + "/challenges/" + challenge._id).end(function (res) {
User.findById(user._id, function(err,user){
var len = user.dailys.length- 1,
daily = user.dailys[user.dailys.length-1];
expect(daily.challenge.broken).to.be('CHALLENGE_DELETED');

// Now let's handle if challenge was deleted, but didn't get to update all the users (an error)
var unset = {$unset:{}};
unset['$unset']['dailys.' + len + '.challenge.broken'] = 1;
User.findByIdAndUpdate(user._id,unset,function(err,user){
expect(err).to.not.be.ok();
expect(user.dailys[len].challenge.broken).to.not.be.ok();
request.post(baseURL + "/user/tasks/" + daily.id + "/up").end(function (res) {
setTimeout(function(){
User.findById(user._id,function(err,user){
expect(user.dailys[len].challenge.broken).to.be('CHALLENGE_DELETED');
done()
})
}, 100); // we need to wait for challenge to update user, it's a background job for perf reasons
})
})
})
})
});

it('Admin creates a challenge', function (done) {
User.findByIdAndUpdate(_id, {$set:{'contributor.admin':true}}, function (err,_user) {
expect(err).to.not.be.ok();
Expand Down

0 comments on commit 78fcdd2

Please sign in to comment.