mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-19 07:37:25 +01:00
Ensured damage was only done for dailies that were due yesterday
This commit is contained in:
@@ -476,6 +476,25 @@ describe('cron', () => {
|
|||||||
|
|
||||||
expect(progress.down).to.equal(-1);
|
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', () => {
|
describe('habits', () => {
|
||||||
|
|||||||
@@ -261,6 +261,10 @@ export function cron (options = {}) {
|
|||||||
let EvadeTask = 0;
|
let EvadeTask = 0;
|
||||||
let scheduleMisses = daysMissed;
|
let scheduleMisses = daysMissed;
|
||||||
|
|
||||||
|
// Only check one day back
|
||||||
|
let dailiesDaysMissed = daysMissed;
|
||||||
|
if (dailiesDaysMissed > 1) dailiesDaysMissed = 1;
|
||||||
|
|
||||||
if (completed) {
|
if (completed) {
|
||||||
dailyChecked += 1;
|
dailyChecked += 1;
|
||||||
if (!atLeastOneDailyDue) { // only bother checking until the first thing is found
|
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
|
// dailys repeat, so need to calculate how many they've missed according to their own schedule
|
||||||
scheduleMisses = 0;
|
scheduleMisses = 0;
|
||||||
|
|
||||||
for (let i = 0; i < daysMissed; i++) {
|
for (let i = 0; i < dailiesDaysMissed; i++) {
|
||||||
let thatDay = moment(now).subtract({days: i + 1});
|
let thatDay = moment(now).subtract({days: i + 1});
|
||||||
|
|
||||||
if (shouldDo(thatDay.toDate(), task, user.preferences)) {
|
if (shouldDo(thatDay.toDate(), task, user.preferences)) {
|
||||||
|
|||||||
Reference in New Issue
Block a user