mirror of
https://github.com/HabitRPG/habitica.git
synced 2025-12-16 14:17:22 +01:00
* Issue 10209 - Remove read usages of zone * Issue 10209 - Add coverage on daysSince and startOfDay cron utility functions * Issue 10209 - Add unit test for daysUserHasMissed method * Issue 10209 - Remove usages of deprecated `moment.js#zone` method. * Issue 10209 - Add helper function to centralise logic Also simplify timezoneOffsetToUtc function in site.vue * Issue 10209 - Also add getUtcOffset as method on user Co-authored-by: Matteo Pagliazzi <matteopagliazzi@gmail.com>
83 lines
2.6 KiB
JavaScript
83 lines
2.6 KiB
JavaScript
import moment from 'moment';
|
|
|
|
import taskDefaults from '../../../website/common/script/libs/taskDefaults';
|
|
import getUtcOffset from '../../../website/common/script/fns/getUtcOffset';
|
|
import { generateUser } from '../../helpers/common.helper';
|
|
|
|
describe('taskDefaults', () => {
|
|
it('applies defaults to undefined type or habit', () => {
|
|
const task = taskDefaults({}, generateUser());
|
|
expect(task.type).to.eql('habit');
|
|
expect(task._id).to.exist;
|
|
expect(task.text).to.eql(task._id);
|
|
expect(task.tags).to.eql([]);
|
|
expect(task.value).to.eql(0);
|
|
expect(task.priority).to.eql(1);
|
|
expect(task.up).to.eql(true);
|
|
expect(task.down).to.eql(true);
|
|
expect(task.history).to.eql([]);
|
|
expect(task.frequency).to.equal('daily');
|
|
expect(task.counterUp).to.equal(0);
|
|
expect(task.counterDown).to.equal(0);
|
|
});
|
|
|
|
it('applies defaults to a daily', () => {
|
|
const task = taskDefaults({ type: 'daily' }, generateUser());
|
|
expect(task.type).to.eql('daily');
|
|
expect(task._id).to.exist;
|
|
expect(task.text).to.eql(task._id);
|
|
expect(task.tags).to.eql([]);
|
|
expect(task.value).to.eql(0);
|
|
expect(task.priority).to.eql(1);
|
|
expect(task.history).to.eql([]);
|
|
expect(task.completed).to.eql(false);
|
|
expect(task.streak).to.eql(0);
|
|
expect(task.repeat).to.eql({
|
|
m: true,
|
|
t: true,
|
|
w: true,
|
|
th: true,
|
|
f: true,
|
|
s: true,
|
|
su: true,
|
|
});
|
|
expect(task.frequency).to.eql('weekly');
|
|
expect(task.startDate).to.exist;
|
|
});
|
|
|
|
it('applies defaults a reward', () => {
|
|
const task = taskDefaults({ type: 'reward' }, generateUser());
|
|
expect(task.type).to.eql('reward');
|
|
expect(task._id).to.exist;
|
|
expect(task.text).to.eql(task._id);
|
|
expect(task.tags).to.eql([]);
|
|
expect(task.value).to.eql(10);
|
|
expect(task.priority).to.eql(1);
|
|
});
|
|
|
|
it('applies defaults a todo', () => {
|
|
const task = taskDefaults({ type: 'todo' }, generateUser());
|
|
expect(task.type).to.eql('todo');
|
|
expect(task._id).to.exist;
|
|
expect(task.text).to.eql(task._id);
|
|
expect(task.tags).to.eql([]);
|
|
expect(task.value).to.eql(0);
|
|
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.
|
|
const user = generateUser({ 'preferences.dayStart': 25 });
|
|
const task = taskDefaults({ type: 'daily' }, user);
|
|
|
|
expect(task.startDate).to.eql(
|
|
moment()
|
|
.utcOffset(getUtcOffset(user))
|
|
.startOf('day')
|
|
.subtract(1, 'day')
|
|
.toDate(),
|
|
);
|
|
});
|
|
});
|