From 2c6288e9977b32aeade01b811d98bff7041740d9 Mon Sep 17 00:00:00 2001 From: Tyler Renelle Date: Thu, 11 Oct 2012 13:03:10 -0400 Subject: [PATCH] test for running cron multiple times. it's passing, but not working inthe browser - will need to test with capser --- test/user.mocha.coffee | 42 ++++++++++++++++++++++++------------------ 1 file changed, 24 insertions(+), 18 deletions(-) diff --git a/test/user.mocha.coffee b/test/user.mocha.coffee index 7c0f5b979e..879484d00b 100644 --- a/test/user.mocha.coffee +++ b/test/user.mocha.coffee @@ -190,25 +190,31 @@ describe 'User', -> it 'does proper calculations when daily is complete' it 'calculates dailys properly when they have repeat dates' - it 'calculates user.stats & task.value properly on cron', -> - - times = 10 + runCron = (times, pass=1) -> # Set lastCron to days ago - today = new moment() - ago = new moment().subtract('days',times) - model.set '_user.lastCron', ago.toDate() - # Run run - scoring.cron() - [stats, task] = statsTask() - - # Should have updated cron to today - lastCron = moment(model.get('_user.lastCron')) - expect(today.diff(lastCron, 'days')).to.eql 0 - - shouldBe = modificationsLookup('down', {times:times}) - # Should have updated points properly - expect(stats.hp).to.be.eql shouldBe.user.stats.hp - expect(task.value).to.eql shouldBe.value + today = new moment() + ago = new moment().subtract('days',times) + model.set '_user.lastCron', ago.toDate() + # Run run + scoring.cron() + [stats, task] = statsTask() + + # Should have updated cron to today + lastCron = moment(model.get('_user.lastCron')) + expect(today.diff(lastCron, 'days')).to.eql 0 + + shouldBe = modificationsLookup('down', {times:times*pass}) + # Should have updated points properly + expect(Math.round(stats.hp)).to.be.eql Math.round(shouldBe.user.stats.hp) + expect(Math.round(task.value)).to.eql Math.round(shouldBe.value) + + it 'calculates user.stats & task.value properly on cron', -> + runCron(10) + + it 'runs cron multiple times properly', -> + runCron(5) + runCron(5, 2) + #TODO clicking repeat dates on newly-created item doesn't refresh until you refresh the page #TODO dates on dailies is having issues, possibility: date cusps? my saturday exempts were set to exempt at 8pm friday