diff --git a/test/common/shouldDo.test.js b/test/common/shouldDo.test.js index 7f08076b25..4159d5133e 100644 --- a/test/common/shouldDo.test.js +++ b/test/common/shouldDo.test.js @@ -713,8 +713,9 @@ describe('shouldDo', () => { it('leaves daily inactive if not day of the month', () => { dailyTask.everyX = 1; dailyTask.frequency = 'monthly'; - dailyTask.daysOfMonth = [15]; - let tomorrow = moment().add(1, 'day').toDate();// @TODO: make sure this is not the 15 + let today = moment(); + dailyTask.daysOfMonth = [today.date()]; + let tomorrow = today.add(1, 'day').toDate(); expect(shouldDo(tomorrow, dailyTask, options)).to.equal(false); }); @@ -732,8 +733,9 @@ describe('shouldDo', () => { it('leaves daily inactive if not on date of the x month', () => { dailyTask.everyX = 2; dailyTask.frequency = 'monthly'; - dailyTask.daysOfMonth = [15]; - let tomorrow = moment().add(2, 'months').add(1, 'day').toDate(); + let today = moment(); + dailyTask.daysOfMonth = [today.date()]; + let tomorrow = today.add(2, 'months').add(1, 'day').toDate(); expect(shouldDo(tomorrow, dailyTask, options)).to.equal(false); }); @@ -911,6 +913,28 @@ describe('shouldDo', () => { expect(shouldDo(day, dailyTask, options)).to.equal(false); }); + it('returns false when next due is requested and no repeats are available', () => { + dailyTask.repeat = { + su: false, + s: false, + f: false, + th: false, + w: false, + t: false, + m: false, + }; + + let today = moment('2017-05-27T17:34:40.000Z'); + let week = today.monthWeek(); + dailyTask.startDate = today.toDate(); + dailyTask.weeksOfMonth = [week]; + dailyTask.everyX = 1; + dailyTask.frequency = 'monthly'; + day = moment('2017-02-23'); + options.nextDue = true; + expect(shouldDo(day, dailyTask, options)).to.equal(false); + }); + it('activates Daily if correct week of the month on the day of the start date', () => { dailyTask.repeat = { su: false, diff --git a/website/client-old/js/services/taskServices.js b/website/client-old/js/services/taskServices.js index 82d1546401..2c4a272d1a 100644 --- a/website/client-old/js/services/taskServices.js +++ b/website/client-old/js/services/taskServices.js @@ -38,6 +38,18 @@ angular.module('habitrpg') } function saveTask (task, stayOpen, isSaveAndClose) { + + // Ensure user has a repeat day selected for monthly day of the week + var taskIsDayOfTheWeekMonthly = task._edit.frequency === 'monthly' && task._edit.repeatsOn == 'dayOfWeek'; + var repeats = _.values(task._edit.repeat); + var repeatHasTrueDay = _.find(repeats, function (item) { + return item === true; + }); + if (taskIsDayOfTheWeekMonthly && !repeatHasTrueDay) { + alert(env.t('repeatDayError')); + return; + } + if (task._edit) { angular.copy(task._edit, task); } diff --git a/website/common/locales/en/tasks.json b/website/common/locales/en/tasks.json index 1e3eee45dc..e157f4f200 100644 --- a/website/common/locales/en/tasks.json +++ b/website/common/locales/en/tasks.json @@ -169,5 +169,6 @@ "yearlyRepeatHelpContent": "This task will be due every X years", "resets": "Resets", "summaryStart": "Repeats <%= frequency %> every <%= everyX %> <%= frequencyPlural %> ", - "nextDue": "Next Due Dates" + "nextDue": "Next Due Dates", + "repeatDayError": "Please ensure that you have at least one day of the week selected." } diff --git a/website/common/script/cron.js b/website/common/script/cron.js index ca2cce98c3..16466fe1a8 100644 --- a/website/common/script/cron.js +++ b/website/common/script/cron.js @@ -164,6 +164,7 @@ export function shouldDo (day, dailyTask, options = {}) { let matchEveryX = differenceInMonths % dailyTask.everyX === 0; if (dailyTask.weeksOfMonth && dailyTask.weeksOfMonth.length > 0) { + if (daysOfTheWeek.length === 0) return false; schedule = schedule.every(daysOfTheWeek).daysOfWeek() .every(dailyTask.weeksOfMonth).weeksOfMonthByDay();