-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test(app-project): run YourStats tests in a non-UTC timezone #6412
Changes from all commits
2104465
1eb7b17
d703a43
c7c6246
2ba3612
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -28,8 +28,14 @@ export const statsClient = { | |
} | ||
} | ||
|
||
// https://stackoverflow.com/a/51918448/10951669 | ||
function firstDayOfWeek (dateObject, firstDayOfWeekIndex) { | ||
/** | ||
* Find the first day matching a given weekday number, prior to a given UTC date. | ||
* https://stackoverflow.com/a/51918448/10951669 | ||
* @param {Date} dateObject search prior to this datetime. | ||
* @param {number} firstDayOfWeekIndex day of the week to find (Sunday is 0.) | ||
* @returns a UTC date object for the first day of the week | ||
*/ | ||
function firstDayOfWeek(dateObject, firstDayOfWeekIndex) { | ||
const dayOfWeek = dateObject.getUTCDay() | ||
const firstDayOfWeek = new Date(dateObject) | ||
const diff = dayOfWeek >= firstDayOfWeekIndex | ||
|
@@ -74,7 +80,7 @@ const YourStats = types | |
weekDay.setUTCDate(newDate) | ||
const period = weekDay.toISOString().substring(0, 10) | ||
const { count } = dailyCounts.find(count => count.period.startsWith(period)) || { count: 0, period } | ||
const dayNumber = weekDay.getDay() | ||
const dayNumber = weekDay.getUTCDay() | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was causing the weekday bug in #2244, but it only triggers when you run There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. See #2528 for some context on why the code is getting the weekday here. |
||
weeklyStats.push({ | ||
count, | ||
dayNumber, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,14 +20,14 @@ describe('Stores > YourStats', function () { | |
sinon.stub(console, 'error') | ||
|
||
const MOCK_DAILY_COUNTS = [ | ||
{ count: 12, period: '2019-09-29' }, | ||
{ count: 12, period: '2019-09-30' }, | ||
{ count: 13, period: '2019-10-01' }, | ||
{ count: 14, period: '2019-10-02' }, | ||
{ count: 10, period: '2019-10-03' }, | ||
{ count: 11, period: '2019-10-04' }, | ||
{ count: 8, period: '2019-10-05' }, | ||
{ count: 15, period: '2019-10-06' } | ||
{ count: 12, period: '2019-09-29T00:00:00.000Z' }, | ||
{ count: 12, period: '2019-09-30T00:00:00.000Z' }, | ||
{ count: 13, period: '2019-10-01T00:00:00.000Z' }, | ||
{ count: 14, period: '2019-10-02T00:00:00.000Z' }, | ||
{ count: 10, period: '2019-10-03T00:00:00.000Z' }, | ||
{ count: 11, period: '2019-10-04T00:00:00.000Z' }, | ||
{ count: 8, period: '2019-10-05T00:00:00.000Z' }, | ||
{ count: 15, period: '2019-10-06T00:00:00.000Z' } | ||
Comment on lines
+23
to
+30
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These mocks should match the API responses for real ERAS data, which uses midnight UTC to mark the start of each day. |
||
] | ||
|
||
nockScope = nock('https://panoptes-staging.zooniverse.org/api') | ||
|
@@ -67,17 +67,21 @@ describe('Stores > YourStats', function () { | |
let clock | ||
|
||
before(function () { | ||
clock = sinon.useFakeTimers({ now: new Date(2019, 9, 1, 12), toFake: ['Date'] }) | ||
// Set the local clock to 1am on Tuesday 1 October 2019, UTC. | ||
// Local time for this test will be 7pm, Monday 30 September 2019, CST. | ||
clock = sinon.useFakeTimers(new Date('2019-10-01T01:00:00Z')) | ||
const user = { | ||
id: '123', | ||
login: 'test.user' | ||
} | ||
|
||
process.env.TZ = 'America/Chicago' | ||
rootStore.user.set(user) | ||
}) | ||
|
||
after(function () { | ||
clock.restore() | ||
delete process.env.TZ | ||
}) | ||
|
||
it('should request user statistics', function () { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Today" is always the current day in Greenwich.