Ensured damage was only done for dailies that were due yesterday

This commit is contained in:
Keith Holliday
2017-06-27 22:01:01 -06:00
parent ca8541e8c4
commit 8299982484
2 changed files with 24 additions and 1 deletions

View File

@@ -476,6 +476,25 @@ describe('cron', () => {
expect(progress.down).to.equal(-1);
});
it('should do damage for only yesterday\'s dailies', () => {
daysMissed = 3;
tasksByType.dailys[0].startDate = moment(new Date()).subtract({days: 1});
let daily = {
text: 'test daily',
type: 'daily',
};
let task = new Tasks.daily(Tasks.Task.sanitize(daily)); // eslint-disable-line new-cap
tasksByType.dailys.push(task);
tasksByType.dailys[1].startDate = moment(new Date()).subtract({days: 2});
tasksByType.dailys[1].everyX = 2;
tasksByType.dailys[1].frequency = 'daily';
cron({user, tasksByType, daysMissed, analytics});
expect(user.stats.hp).to.equal(48);
});
});
describe('habits', () => {

View File

@@ -261,6 +261,10 @@ export function cron (options = {}) {
let EvadeTask = 0;
let scheduleMisses = daysMissed;
// Only check one day back
let dailiesDaysMissed = daysMissed;
if (dailiesDaysMissed > 1) dailiesDaysMissed = 1;
if (completed) {
dailyChecked += 1;
if (!atLeastOneDailyDue) { // only bother checking until the first thing is found
@@ -271,7 +275,7 @@ export function cron (options = {}) {
// dailys repeat, so need to calculate how many they've missed according to their own schedule
scheduleMisses = 0;
for (let i = 0; i < daysMissed; i++) {
for (let i = 0; i < dailiesDaysMissed; i++) {
let thatDay = moment(now).subtract({days: i + 1});
if (shouldDo(thatDay.toDate(), task, user.preferences)) {