mirror of
https://github.com/sudoxnym/habitica-self-host.git
synced 2026-07-31 19:20:25 +00:00
some bug-fixes on shouldDo() for today-check
This commit is contained in:
parent
12ef6edf8d
commit
51a80b6626
3 changed files with 27 additions and 10 deletions
|
|
@ -356,7 +356,7 @@ obj.cron = (user, options={}) ->
|
|||
scheduleMisses = 0
|
||||
_.times daysMissed, (n) ->
|
||||
thatDay = moment(now).subtract('days', n + 1)
|
||||
scheduleMisses++ if helpers.shouldDo(thatDay, repeat, obj.preferences?.dayStart) is true
|
||||
scheduleMisses++ if helpers.shouldDo(thatDay, repeat, {dayStart:obj.preferences?.dayStart})
|
||||
obj.score(user, task, 'down', {times:scheduleMisses, cron:true, paths:paths}) if scheduleMisses > 0
|
||||
|
||||
switch type
|
||||
|
|
|
|||
|
|
@ -18,9 +18,9 @@ daysBetween = (yesterday, now, dayStart) -> Math.abs sod(yesterday, dayStart).di
|
|||
###
|
||||
Should the user do this taks on this date, given the task's repeat options and user.preferences.dayStart?
|
||||
###
|
||||
shouldDo = (day, repeat, dayStart=0) ->
|
||||
shouldDo = (day, repeat, options={}) ->
|
||||
return false unless repeat
|
||||
now = +new Date
|
||||
[dayStart,now] = [options.dayStart||0, options.now||+new Date]
|
||||
selected = repeat[dayMapping[sod(day, dayStart).day()]]
|
||||
return selected unless moment(day).isSame(now,'d')
|
||||
if dayStart <= moment(now).hour() # we're past the dayStart mark, is it due today?
|
||||
|
|
@ -245,7 +245,7 @@ module.exports =
|
|||
|
||||
# show as completed if completed (naturally) or not required for today
|
||||
if type in ['todo', 'daily']
|
||||
if completed or (type is 'daily' and !shouldDo(+new Date, task.repeat, dayStart))
|
||||
if completed or (type is 'daily' and !shouldDo(+new Date, task.repeat, {dayStart}))
|
||||
classes += " completed"
|
||||
else
|
||||
classes += " uncompleted"
|
||||
|
|
|
|||
|
|
@ -153,9 +153,8 @@ describe 'Cron', ->
|
|||
before.dailys[0].repeat = after.dailys[0].repeat = options.repeat if options.repeat
|
||||
before.dailys[0].streak = after.dailys[0].streak = 10
|
||||
before.dailys[0].completed = after.dailys[0].completed = true if options.checked
|
||||
expect(helpers.shouldDo(now, options.repeat, options.dayStart)).to.be options.shouldDo.before if options.shouldDo
|
||||
expect(helpers.shouldDo(now, options.repeat, {dayStart:options.dayStart,now})).to.be.ok() if options.shouldDo
|
||||
algos.cron(after,{now})
|
||||
expect(helpers.shouldDo(now, options.repeat, options.dayStart)).to.be options.shouldDo.after if options.shouldDo
|
||||
switch options.expect
|
||||
when 'losePoints' then expectLostPoints(before,after,'daily')
|
||||
when 'noChange' then expectNoChange(before,after)
|
||||
|
|
@ -164,23 +163,41 @@ describe 'Cron', ->
|
|||
|
||||
cronMatrix =
|
||||
steps:
|
||||
|
||||
'due yesterday':
|
||||
defaults: {daysAgo:1, limitOne: 'daily'}
|
||||
steps:
|
||||
'(simple)': {daysAgo:1, limitOne: 'daily', expect:'losePoints'}
|
||||
|
||||
'(simple)': {expect:'losePoints'}
|
||||
|
||||
'due today':
|
||||
defaults: {repeat:{su:true,m:1,t:1,w:1,th:1,f:1,s:true}}
|
||||
steps:
|
||||
#TODO checked
|
||||
'pre-dayStart':
|
||||
defaults: {currentHour:3, dayStart:4, shouldDo:{before:true,after:true}}
|
||||
defaults: {currentHour:3, dayStart:4, shouldDo:true}
|
||||
steps:
|
||||
'checked': {checked: true, expect:'noChange'}
|
||||
'un-checked': {checked: false, expect:'noChange'}
|
||||
'post-dayStart':
|
||||
defaults: {currentHour:5, dayStart:4, shouldDo:{before:true,after:true}}
|
||||
defaults: {currentHour:5, dayStart:4, shouldDo:true}
|
||||
steps:
|
||||
'checked': {checked:true, expect:'noDamage'}
|
||||
'unchecked': {checked:false, expect: 'losePoints'}
|
||||
|
||||
'NOT due today':
|
||||
defaults: {repeat:{su:false,m:1,t:1,w:1,th:1,f:1,s:1}}
|
||||
steps:
|
||||
'pre-dayStart':
|
||||
defaults: {currentHour:3, dayStart:4, shouldDo:true}
|
||||
steps:
|
||||
'checked': {checked: true, expect:'noChange'}
|
||||
'un-checked': {checked: false, expect:'noChange'}
|
||||
'post-dayStart':
|
||||
defaults: {currentHour:5, dayStart:4, shouldDo:false}
|
||||
steps:
|
||||
'checked': {checked:true, expect:'noDamage'}
|
||||
'unchecked': {checked:false, expect: 'losePoints'}
|
||||
|
||||
'not due yesterday':
|
||||
defaults: {repeat:{su:1,m:1,t:1,w:1,th:1,f:1,s:false}}
|
||||
steps:
|
||||
|
|
|
|||
Loading…
Reference in a new issue