mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-17 06:37:23 +01:00
If user's cron will happen later today, start the task yesterday. (#10783)
* If user's cron will happen later today, start the task yesterday. * Added default dayStart to taskDefaults. * Removed the need to call shouldDo twice to calculate nextDue. * Revert "Removed the need to call shouldDo twice to calculate nextDue." This reverts commit e1467f2fc33cfb11e6a4fc667460df6a48b69d45. * Removed defaults from taskDefault arguments. * Got user from $store in copyAsTodoModal.vue. * Fixed tests for taskDefaults to include mock user. * Fix shouldDo tests when run in GMT timezone. * Added test to taskDefault; added utcOffset to taskDefault. * Replaced utcOffset with zone. * Removed erroneous import.
This commit is contained in:
committed by
Matteo Pagliazzi
parent
12aef475c8
commit
a48a6a292d
@@ -1,8 +1,11 @@
|
||||
import moment from 'moment';
|
||||
|
||||
import taskDefaults from '../../../website/common/script/libs/taskDefaults';
|
||||
import { generateUser } from '../../helpers/common.helper';
|
||||
|
||||
describe('taskDefaults', () => {
|
||||
it('applies defaults to undefined type or habit', () => {
|
||||
let task = taskDefaults();
|
||||
let task = taskDefaults({}, generateUser());
|
||||
expect(task.type).to.eql('habit');
|
||||
expect(task._id).to.exist;
|
||||
expect(task.text).to.eql(task._id);
|
||||
@@ -18,7 +21,7 @@ describe('taskDefaults', () => {
|
||||
});
|
||||
|
||||
it('applies defaults to a daily', () => {
|
||||
let task = taskDefaults({ type: 'daily' });
|
||||
let task = taskDefaults({ type: 'daily' }, generateUser());
|
||||
expect(task.type).to.eql('daily');
|
||||
expect(task._id).to.exist;
|
||||
expect(task.text).to.eql(task._id);
|
||||
@@ -42,7 +45,7 @@ describe('taskDefaults', () => {
|
||||
});
|
||||
|
||||
it('applies defaults a reward', () => {
|
||||
let task = taskDefaults({ type: 'reward' });
|
||||
let task = taskDefaults({ type: 'reward' }, generateUser());
|
||||
expect(task.type).to.eql('reward');
|
||||
expect(task._id).to.exist;
|
||||
expect(task.text).to.eql(task._id);
|
||||
@@ -52,7 +55,7 @@ describe('taskDefaults', () => {
|
||||
});
|
||||
|
||||
it('applies defaults a todo', () => {
|
||||
let task = taskDefaults({ type: 'todo' });
|
||||
let task = taskDefaults({ type: 'todo' }, generateUser());
|
||||
expect(task.type).to.eql('todo');
|
||||
expect(task._id).to.exist;
|
||||
expect(task.text).to.eql(task._id);
|
||||
@@ -61,4 +64,18 @@ describe('taskDefaults', () => {
|
||||
expect(task.priority).to.eql(1);
|
||||
expect(task.completed).to.eql(false);
|
||||
});
|
||||
|
||||
it('starts a task yesterday if user cron is later today', () => {
|
||||
// Configure to have a day start that's *always* tomorrow.
|
||||
let user = generateUser({'preferences.dayStart': 25});
|
||||
let task = taskDefaults({ type: 'daily' }, user);
|
||||
|
||||
expect(task.startDate).to.eql(
|
||||
moment()
|
||||
.zone(user.preferences.timezoneOffset, 'hour')
|
||||
.startOf('day')
|
||||
.subtract(1, 'day')
|
||||
.toDate()
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user