Added test to recreate early cron issue (#9668)

* Added test to recreate early cron issue

* Gave user extra time based on reverse timezone change
This commit is contained in:
Keith Holliday
2017-12-14 09:09:11 -06:00
committed by GitHub
parent b0ebdfeb65
commit 05640f513e
3 changed files with 50 additions and 2 deletions

View File

@@ -323,4 +323,48 @@ describe('User Model', () => {
expect(user.achievements.beastMaster).to.not.equal(true);
});
});
context('days missed', () => {
// http://forbrains.co.uk/international_tools/earth_timezones
let user;
beforeEach(() => {
user = new User();
});
it('should not cron early when going back a timezone', () => {
const yesterday = moment('2017-12-05T00:00:00.000-06:00'); // 11 pm on 4 Texas
const timezoneOffset = moment().zone('-06:00').zone();
user.lastCron = yesterday;
user.preferences.timezoneOffset = timezoneOffset;
const today = moment('2017-12-06T00:00:00.000-06:00'); // 11 pm on 4 Texas
const req = {};
req.header = () => {
return timezoneOffset + 60;
};
const {daysMissed} = user.daysUserHasMissed(today, req);
expect(daysMissed).to.eql(0);
});
it('should not cron early when going back a timezone with a custom day start', () => {
const yesterday = moment('2017-12-05T02:00:00.000-08:00');
const timezoneOffset = moment().zone('-08:00').zone();
user.lastCron = yesterday;
user.preferences.timezoneOffset = timezoneOffset;
user.preferences.dayStart = 2;
const today = moment('2017-12-06T02:00:00.000-08:00');
const req = {};
req.header = () => {
return timezoneOffset + 60;
};
const {daysMissed} = user.daysUserHasMissed(today, req);
expect(daysMissed).to.eql(0);
});
});
});