@@ -24,6 +24,10 @@ const data = {
24
24
} ,
25
25
} ;
26
26
27
+ const dataYear = JSON . parse ( JSON . stringify ( data ) ) ;
28
+ dataYear . data . user . contributionsCollection . totalCommitContributions = 2003 ;
29
+ dataYear . data . user . contributionsCollection . restrictedContributionsCount = 3 ;
30
+
27
31
const firstRepositoriesData = {
28
32
data : {
29
33
user : {
@@ -92,10 +96,23 @@ const error = {
92
96
93
97
const mock = new MockAdapter ( axios ) ;
94
98
99
+ /**
100
+ * Mocks the GraphQL API based on certain conditions.
101
+ *
102
+ * @param {* } config Axios config object.
103
+ * @returns Axios response object.
104
+ */
105
+ const mockData = ( config ) => {
106
+ // If year is 2003, return dataYear.
107
+ if ( config . data . includes ( "contributionsCollection(from: $starttime)" ) )
108
+ return [ 200 , dataYear ] ;
109
+ return [ 200 , data ] ;
110
+ } ;
111
+
95
112
beforeEach ( ( ) => {
96
113
mock
97
114
. onPost ( "https://api.github.com/graphql" )
98
- . replyOnce ( 200 , data )
115
+ . replyOnce ( mockData )
99
116
. onPost ( "https://api.github.com/graphql" )
100
117
. replyOnce ( 200 , firstRepositoriesData ) ;
101
118
// .onPost("https://api.github.com/graphql") // NOTE: Temporarily disable fetching of multiple pages. Done because of #2130.
@@ -254,61 +271,15 @@ describe("Test fetchStats", () => {
254
271
} ) ;
255
272
} ) ;
256
273
257
- it ( "should get present year commits when provide no year" , async ( ) => {
258
- const data2003 = { ...data , data :
259
- { ...data . data , user :
260
- { ...data . data . user , contributionsCollection : {
261
- totalCommitContributions : 2003 ,
262
- restrictedContributionsCount : 3 ,
263
- } } } }
264
- mock . onPost ( "https://api.github.com/graphql" ) . reply ( ( cfg ) => {
265
- if ( cfg . data . includes ( "contributionsCollection(from: 2003-01-01T00:00:00Z)" ) )
266
- return [ 200 , data2003 ] ;
267
- return [ 200 , data ] ;
268
- } ) ;
269
-
270
- let stats = await fetchStats ( "anuraghazra" , true , false , [ ] ) ;
271
- const rank = calculateRank ( {
272
- totalCommits : 150 ,
273
- totalRepos : 5 ,
274
- followers : 100 ,
275
- contributions : 61 ,
276
- stargazers : 400 ,
277
- prs : 300 ,
278
- issues : 200 ,
279
- } ) ;
280
-
281
- expect ( stats ) . toStrictEqual ( {
282
- contributedTo : 61 ,
283
- name : "Anurag Hazra" ,
284
- totalCommits : 150 ,
285
- totalIssues : 200 ,
286
- totalPRs : 300 ,
287
- totalStars : 400 ,
288
- rank,
289
- } ) ;
290
- } ) ;
291
-
292
274
it ( "should get commits of provided year" , async ( ) => {
293
- const data2003 = { ...data , data :
294
- { ...data . data , user :
295
- { ...data . data . user , contributionsCollection : {
296
- totalCommitContributions : 2003 ,
297
- restrictedContributionsCount : 3 ,
298
- } } } }
299
- mock . onPost ( "https://api.github.com/graphql" ) . reply ( ( cfg ) => {
300
- if ( cfg . data . includes ( `"starttime":"2003-01-01T00:00:00Z"` ) )
301
- return [ 200 , data2003 ] ;
302
- return [ 200 , data ] ;
303
- } ) ;
304
-
305
275
let stats = await fetchStats ( "anuraghazra" , true , false , [ ] , 2003 ) ;
306
276
const rank = calculateRank ( {
307
277
totalCommits : 2006 ,
308
278
totalRepos : 5 ,
309
279
followers : 100 ,
310
280
contributions : 61 ,
311
- stargazers : 400 ,
281
+ // stargazers: 400, // NOTE: Temporarily disable fetching of multiple pages. Done because of #2130.
282
+ stargazers : 300 , // NOTE: Temporarily disable fetching of multiple pages. Done because of #2130.
312
283
prs : 300 ,
313
284
issues : 200 ,
314
285
} ) ;
@@ -319,7 +290,8 @@ describe("Test fetchStats", () => {
319
290
totalCommits : 2006 ,
320
291
totalIssues : 200 ,
321
292
totalPRs : 300 ,
322
- totalStars : 400 ,
293
+ // totalStars: 400, // NOTE: Temporarily disable fetching of multiple pages. Done because of #2130.
294
+ totalStars : 300 , // NOTE: Temporarily disable fetching of multiple pages. Done because of #2130.
323
295
rank,
324
296
} ) ;
325
297
} ) ;
0 commit comments