From 9811117acdb1e53bcd040af9470acb244b91407e Mon Sep 17 00:00:00 2001 From: Tyler Renelle Date: Tue, 18 Sep 2012 01:19:12 -0400 Subject: [PATCH] Fix bug of incomplete TODOs not gaining value on cron --- lib/app/scoring.js | 5 +++-- src/app/scoring.coffee | 3 ++- test/test.coffee | 46 +++++++++++++++++++++++++----------------- 3 files changed, 33 insertions(+), 21 deletions(-) diff --git a/lib/app/scoring.js b/lib/app/scoring.js index ba14d1d1f3..32215834f5 100644 --- a/lib/app/scoring.js +++ b/lib/app/scoring.js @@ -154,7 +154,7 @@ module.exports.tally = function(user, momentDate) { var expTally, lvl, todoTally; todoTally = 0; _.each(user.get('tasks'), function(taskObj, taskId, list) { - var absVal, completed, dayMapping, repeat, task, type, value, _ref; + var absVal, completed, dayMapping, dueToday, repeat, task, type, value, _ref; if (taskObj.id == null) { return; } @@ -172,7 +172,8 @@ module.exports.tally = function(user, momentDate) { 6: 's', 7: 'su' }; - if (repeat && repeat[dayMapping[momentDate.day()]] === true) { + dueToday = repeat && repeat[dayMapping[momentDate.day()]] === true; + if (dueToday || type === 'todo') { score({ user: user, task: task, diff --git a/src/app/scoring.coffee b/src/app/scoring.coffee index 9dc177df79..70f945a6e0 100644 --- a/src/app/scoring.coffee +++ b/src/app/scoring.coffee @@ -150,7 +150,8 @@ module.exports.tally = (user, momentDate) -> # but not for Todos (just increase todo's value) unless completed dayMapping = {0:'su',1:'m',2:'t',3:'w',4:'th',5:'f',6:'s',7:'su'} - if repeat && repeat[dayMapping[momentDate.day()]]==true + dueToday = (repeat && repeat[dayMapping[momentDate.day()]]==true) + if dueToday or type=='todo' score({user:user, task:task, direction:'down', cron:true}) if type == 'daily' task.push "history", { date: new Date(momentDate), value: value } diff --git a/test/test.coffee b/test/test.coffee index 8c48030e1e..6021a3678c 100644 --- a/test/test.coffee +++ b/test/test.coffee @@ -7,29 +7,39 @@ casper = require("casper").create() casper.start url, -> @test.assertTitle "HabitRPG", "homepage title is the one expected" +# ---------- Todos gain delta on cron ------------ +casper.then -> + todoBefore = @evaluate -> window.DERBY.model.get('_todoList')[0] + @then -> + @evaluate -> + window.DERBY.model.set('_user.lastCron', new Date('09/17/2012')) + @then -> @reload() + @then -> + todoAfter = @evaluate -> window.DERBY.model.get('_todoList')[0] + @then -> @test.assert(todoBefore.value > todoAfter.value, "Incomplete TODO gained value on cron") # ---------- User Death ------------ -casper.then -> - @repeat 55, -> - @click '.habits a[data-direction="down"]' - -casper.then -> - userStats = @evaluate -> - window.DERBY.model.get('_user.stats') - utils.dump userStats - - @test.assert(@visible('#dead-modal'), 'Revive Modal Visible') - @test.assert(userStats.hp == 0, 'User HP: 0') - @test.assert(userStats.lvl == 0, 'User Lvl: 0') - @test.assert(userStats.money == 0, 'User GP: 0') +# casper.then -> + # @repeat 55, -> + # @click '.habits a[data-direction="down"]' +# +# casper.then -> + # userStats = @evaluate -> + # window.DERBY.model.get('_user.stats') + # utils.dump userStats +# + # @test.assert(@visible('#dead-modal'), 'Revive Modal Visible') + # @test.assert(userStats.hp == 0, 'User HP: 0') + # @test.assert(userStats.lvl == 0, 'User Lvl: 0') + # @test.assert(userStats.money == 0, 'User GP: 0') # ---------- Misc Pages ------------ -# casper.thenOpen "#{url}/terms", -> - # @test.assertTitle "Terms Of Use", "terms page works" -# -# casper.thenOpen "#{url}/privacy", -> - # @test.assertTitle "Privacy Policy", "privacy page works" +casper.thenOpen "#{url}/terms", -> + @test.assertTitle "Terms Of Use", "terms page works" + +casper.thenOpen "#{url}/privacy", -> + @test.assertTitle "Privacy Policy", "privacy page works" casper.run -> @test.renderResults true \ No newline at end of file