@@ -19,13 +19,61 @@ const data = {
19
19
followers : { totalCount : 100 } ,
20
20
repositories : {
21
21
totalCount : 5 ,
22
+ } ,
23
+ } ,
24
+ } ,
25
+ } ;
26
+
27
+ const firstRepositoriesData = {
28
+ data : {
29
+ user : {
30
+ repositories : {
22
31
nodes : [
23
32
{ name : "test-repo-1" , stargazers : { totalCount : 100 } } ,
24
33
{ name : "test-repo-2" , stargazers : { totalCount : 100 } } ,
25
34
{ name : "test-repo-3" , stargazers : { totalCount : 100 } } ,
35
+ ] ,
36
+ pageInfo : {
37
+ hasNextPage : true ,
38
+ cursor : "cursor" ,
39
+ } ,
40
+ } ,
41
+ } ,
42
+ } ,
43
+ } ;
44
+
45
+ const secondRepositoriesData = {
46
+ data : {
47
+ user : {
48
+ repositories : {
49
+ nodes : [
26
50
{ name : "test-repo-4" , stargazers : { totalCount : 50 } } ,
27
51
{ name : "test-repo-5" , stargazers : { totalCount : 50 } } ,
28
52
] ,
53
+ pageInfo : {
54
+ hasNextPage : false ,
55
+ cursor : "cursor" ,
56
+ } ,
57
+ } ,
58
+ } ,
59
+ } ,
60
+ } ;
61
+
62
+ const repositoriesWithZeroStarsData = {
63
+ data : {
64
+ user : {
65
+ repositories : {
66
+ nodes : [
67
+ { name : "test-repo-1" , stargazers : { totalCount : 100 } } ,
68
+ { name : "test-repo-2" , stargazers : { totalCount : 100 } } ,
69
+ { name : "test-repo-3" , stargazers : { totalCount : 100 } } ,
70
+ { name : "test-repo-4" , stargazers : { totalCount : 0 } } ,
71
+ { name : "test-repo-5" , stargazers : { totalCount : 0 } } ,
72
+ ] ,
73
+ pageInfo : {
74
+ hasNextPage : true ,
75
+ cursor : "cursor" ,
76
+ } ,
29
77
} ,
30
78
} ,
31
79
} ,
@@ -44,14 +92,22 @@ const error = {
44
92
45
93
const mock = new MockAdapter ( axios ) ;
46
94
95
+ beforeEach ( ( ) => {
96
+ mock
97
+ . onPost ( "https://api.github.com/graphql" )
98
+ . replyOnce ( 200 , data )
99
+ . onPost ( "https://api.github.com/graphql" )
100
+ . replyOnce ( 200 , firstRepositoriesData )
101
+ . onPost ( "https://api.github.com/graphql" )
102
+ . replyOnce ( 200 , secondRepositoriesData ) ;
103
+ } ) ;
104
+
47
105
afterEach ( ( ) => {
48
106
mock . reset ( ) ;
49
107
} ) ;
50
108
51
109
describe ( "Test fetchStats" , ( ) => {
52
110
it ( "should fetch correct stats" , async ( ) => {
53
- mock . onPost ( "https://api.github.com/graphql" ) . reply ( 200 , data ) ;
54
-
55
111
let stats = await fetchStats ( "anuraghazra" ) ;
56
112
const rank = calculateRank ( {
57
113
totalCommits : 100 ,
@@ -74,7 +130,38 @@ describe("Test fetchStats", () => {
74
130
} ) ;
75
131
} ) ;
76
132
133
+ it ( "should stop fetching when there are repos with zero stars" , async ( ) => {
134
+ mock . reset ( ) ;
135
+ mock
136
+ . onPost ( "https://api.github.com/graphql" )
137
+ . replyOnce ( 200 , data )
138
+ . onPost ( "https://api.github.com/graphql" )
139
+ . replyOnce ( 200 , repositoriesWithZeroStarsData ) ;
140
+
141
+ let stats = await fetchStats ( "anuraghazra" ) ;
142
+ const rank = calculateRank ( {
143
+ totalCommits : 100 ,
144
+ totalRepos : 5 ,
145
+ followers : 100 ,
146
+ contributions : 61 ,
147
+ stargazers : 300 ,
148
+ prs : 300 ,
149
+ issues : 200 ,
150
+ } ) ;
151
+
152
+ expect ( stats ) . toStrictEqual ( {
153
+ contributedTo : 61 ,
154
+ name : "Anurag Hazra" ,
155
+ totalCommits : 100 ,
156
+ totalIssues : 200 ,
157
+ totalPRs : 300 ,
158
+ totalStars : 300 ,
159
+ rank,
160
+ } ) ;
161
+ } ) ;
162
+
77
163
it ( "should throw error" , async ( ) => {
164
+ mock . reset ( ) ;
78
165
mock . onPost ( "https://api.github.com/graphql" ) . reply ( 200 , error ) ;
79
166
80
167
await expect ( fetchStats ( "anuraghazra" ) ) . rejects . toThrow (
@@ -83,8 +170,6 @@ describe("Test fetchStats", () => {
83
170
} ) ;
84
171
85
172
it ( "should fetch and add private contributions" , async ( ) => {
86
- mock . onPost ( "https://api.github.com/graphql" ) . reply ( 200 , data ) ;
87
-
88
173
let stats = await fetchStats ( "anuraghazra" , true ) ;
89
174
const rank = calculateRank ( {
90
175
totalCommits : 150 ,
@@ -108,7 +193,6 @@ describe("Test fetchStats", () => {
108
193
} ) ;
109
194
110
195
it ( "should fetch total commits" , async ( ) => {
111
- mock . onPost ( "https://api.github.com/graphql" ) . reply ( 200 , data ) ;
112
196
mock
113
197
. onGet ( "https://api.github.com/search/commits?q=author:anuraghazra" )
114
198
. reply ( 200 , { total_count : 1000 } ) ;
@@ -136,7 +220,6 @@ describe("Test fetchStats", () => {
136
220
} ) ;
137
221
138
222
it ( "should exclude stars of the `test-repo-1` repository" , async ( ) => {
139
- mock . onPost ( "https://api.github.com/graphql" ) . reply ( 200 , data ) ;
140
223
mock
141
224
. onGet ( "https://api.github.com/search/commits?q=author:anuraghazra" )
142
225
. reply ( 200 , { total_count : 1000 } ) ;
0 commit comments