Skip to content

Commit

Permalink
Merge pull request #249 from cofacts/contributions
Browse files Browse the repository at this point in the history
post PR cleanups for contributions API
  • Loading branch information
MrOrz authored Mar 10, 2021
2 parents a78340a + 487bd0a commit b887a4f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 10 deletions.
3 changes: 1 addition & 2 deletions .env.sample
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ GITHUB_CALLBACK_URL=http://localhost:5000/callback/github
GOOGLE_OAUTH_KEY_PATH=PATH_TO_SERVICE_ACCOUNT_KEY
GA_PAGE_SIZE=10000
GA_WEB_VIEW_ID=GA_WEB_VIEW_ID
GA_WEB_TIMEZONE=+08:00
GA_LINE_VIEW_ID=GA_LINE_VIEW_ID
GA_LINE_TIMEZONE=+08:00

# URL to URL resolver microservice (http://github.com/cofacts/url-resolver)
URL_RESOLVER_URL=http://localhost:4000
Expand All @@ -66,3 +64,4 @@ ENGINE_API_KEY=
WEB_CONCURRENCY=2

JEST_TIMEOUT=5000
TIMEZONE=+08:00
11 changes: 8 additions & 3 deletions src/graphql/dataLoaders/__tests__/contirubtionsLoaderFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,12 @@ import fixtures from '../__fixtures__/contributionsLoaderFactory';
import MockDate from 'mockdate';

const loader = new DataLoaders();
MockDate.set(1609430400000); // 2021-01-01T00:00:00.000+08:00

describe('contributionsLoaderFactory', () => {
beforeAll(() => loadFixtures(fixtures));
beforeAll(() => {
MockDate.set(1609430400000); // 2021-01-01T00:00:00.000+08:00
return loadFixtures(fixtures);
});

it('should load last year of data for given userId', async () => {
const res = await loader.contributionsLoader.load({
Expand Down Expand Up @@ -38,5 +40,8 @@ describe('contributionsLoaderFactory', () => {
expect(error).toBe('userId is required');
});

afterAll(() => unloadFixtures(fixtures));
afterAll(() => {
MockDate.reset();
return unloadFixtures(fixtures);
});
});
2 changes: 1 addition & 1 deletion src/graphql/dataLoaders/contributionsLoaderFactory.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export default () =>
interval: 'day',
min_doc_count: 1,
format: 'yyyy-MM-dd',
time_zone: '+08:00',
time_zone: process.env.TIMEZONE || '+08:00',
},
},
},
Expand Down
8 changes: 4 additions & 4 deletions src/scripts/fetchStatsFromGA.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
fetch data without content group, run with `--useContentGroup=false`.
It would use pagePathLevel2 as primary dimension and extracts docId from there.
- Make sure `GA_WEB_VIEW_ID`, `GA_LINE_VIEW_ID`, `GA_LINE_TIMEZONE`, and
`GA_WEB_TIMEZONE` are set with correct settings in .env. Each view's timezone
- Make sure `GA_WEB_VIEW_ID`, `GA_LINE_VIEW_ID`, and `TIMEZONE=+08:00`
are set with correct settings in .env. Each view's timezone
can be found at view settings, see https://support.google.com/analytics/answer/1010249
for more details.
*/
Expand Down Expand Up @@ -61,7 +61,7 @@ const statsSources = {
useContentGroup ? 'ga:contentGroup1' : 'ga:pagePathLevel2',
primaryMetric: 'ga:pageviews',
viewId: webViewId,
timezone: process.env.GA_WEB_TIMEZONE || '+08:00',
timezone: process.env.TIMEZONE || '+08:00',
},
LINE: {
filtersExpression: docType =>
Expand All @@ -70,7 +70,7 @@ const statsSources = {
primaryDimension: () => 'ga:eventLabel',
primaryMetric: 'ga:hits',
viewId: lineViewId,
timezone: process.env.GA_LINE_TIMEZONE || '+08:00',
timezone: process.env.TIMEZONE || '+08:00',
},
};

Expand Down

0 comments on commit b887a4f

Please sign in to comment.