From 696027025be835c03214d1959bc0b4739488bdda Mon Sep 17 00:00:00 2001 From: Alys Date: Sun, 9 Aug 2015 12:41:06 +1000 Subject: [PATCH] add tests for Dailies under new cron behaviour where multiple missed days are treated as one --- test/common/dailies.coffee | 112 +++++++++++++++++++++++++++++++++---- 1 file changed, 102 insertions(+), 10 deletions(-) diff --git a/test/common/dailies.coffee b/test/common/dailies.coffee index 9a9498d24e..3802ad1609 100644 --- a/test/common/dailies.coffee +++ b/test/common/dailies.coffee @@ -59,7 +59,6 @@ describe 'daily/weekly that repeats everyday (default)', -> weekly = null describe 'when startDate is in the future', -> - beforeEach -> user = newUser() user.dailys = [ @@ -141,19 +140,19 @@ describe 'daily/weekly that repeats everyday (default)', -> it 'is due on startDate', -> daily_due_today = shared.shouldDo moment(), daily daily_due_on_start_date = shared.shouldDo moment().add(7, 'days'), daily - + expect(daily_due_today).to.be false expect(daily_due_on_start_date).to.be true weekly_due_today = shared.shouldDo moment(), weekly weekly_due_on_start_date = shared.shouldDo moment().add(7, 'days'), weekly - + expect(weekly_due_today).to.be false expect(weekly_due_on_start_date).to.be true describe 'when startDate is in the past', -> completeDaily = null - + beforeEach -> user = newUser() user.dailys = [ @@ -168,9 +167,14 @@ describe 'daily/weekly that repeats everyday (default)', -> expect(user.stats.hp).to.be.lessThan 50 it 'decreases value on cron if daily is incomplete', -> - cron(user) - expect(daily.value).to.be.lessThan 0 - expect(weekly.value).to.be.lessThan 0 + cron(user, 1) + expect(daily.value).to.be -1 + expect(weekly.value).to.be -1 + + it 'decreases value on cron once only if daily is incomplete and multiple days are missed', -> + cron(user, 7) + expect(daily.value).to.be -1 + expect(weekly.value).to.be -1 it 'resets checklists if daily is not marked as complete', -> checklist = [ @@ -196,7 +200,7 @@ describe 'daily/weekly that repeats everyday (default)', -> _.each daily.checklist, (box)-> expect(box.completed).to.be false - + _.each weekly.checklist, (box)-> expect(box.completed).to.be false @@ -232,7 +236,7 @@ describe 'daily/weekly that repeats everyday (default)', -> describe 'when startDate is today', -> completeDaily = null - + beforeEach -> user = newUser() user.dailys = [ @@ -276,7 +280,7 @@ describe 'daily/weekly that repeats everyday (default)', -> _.each daily.checklist, (box)-> expect(box.completed).to.be false - + _.each weekly.checklist, (box)-> expect(box.completed).to.be false @@ -328,3 +332,91 @@ describe 'daily that repeats every x days', -> isDue = shared.shouldDo moment().add(day, 'days'), daily expect(isDue).to.be true if day % due == 0 expect(isDue).to.be false if day % due != 0 + +describe 'daily that repeats every X days when multiple days are missed', -> + everyX = 3 + startDateDaysAgo = everyX * 3 + user = null + daily = null + + describe 'including missing a due date', -> + missedDays = everyX * 2 + 1 + + beforeEach -> + user = newUser() + user.dailys = [ + shared.taskDefaults({type:'daily', startDate: moment().subtract(startDateDaysAgo, 'days'), frequency: 'daily', everyX: everyX}) + ] + daily = user.dailys[0] + + it 'decreases value on cron once only if daily is incomplete', -> + cron(user, missedDays) + expect(daily.value).to.be -1 + + it 'resets checklists if daily is incomplete', -> + checklist = [ + { + 'text' : '1', + 'id' : 'checklist-one', + 'completed' : true + } + ] + daily.checklist = checklist + cron(user, missedDays) + _.each daily.checklist, (box)-> + expect(box.completed).to.be false + + it 'resets checklists if daily is marked as complete', -> + checklist = [ + { + 'text' : '1', + 'id' : 'checklist-one', + 'completed' : true + } + ] + daily.checklist = checklist + daily.completed = true + cron(user, missedDays) + _.each daily.checklist, (box)-> + expect(box.completed).to.be false + + describe 'but not missing a due date', -> + missedDays = everyX - 1 + + beforeEach -> + user = newUser() + user.dailys = [ + shared.taskDefaults({type:'daily', startDate: moment().subtract(startDateDaysAgo, 'days'), frequency: 'daily', everyX: everyX}) + ] + daily = user.dailys[0] + + it 'does not decrease value on cron', -> + cron(user, missedDays) + expect(daily.value).to.be 0 + + it 'does not reset checklists if daily is incomplete', -> + checklist = [ + { + 'text' : '1', + 'id' : 'checklist-one', + 'completed' : true + } + ] + daily.checklist = checklist + cron(user, missedDays) + _.each daily.checklist, (box)-> + expect(box.completed).to.be true + + it 'resets checklists if daily is marked as complete', -> + checklist = [ + { + 'text' : '1', + 'id' : 'checklist-one', + 'completed' : true + } + ] + daily.checklist = checklist + daily.completed = true + cron(user, missedDays) + _.each daily.checklist, (box)-> + expect(box.completed).to.be false