File tree Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Expand file tree Collapse file tree 2 files changed +45
-1
lines changed Original file line number Diff line number Diff line change @@ -306,7 +306,8 @@ const fetchStats = async (
306306 if ( include_merged_pull_requests ) {
307307 stats . totalPRsMerged = user . mergedPullRequests . totalCount ;
308308 stats . mergedPRsPercentage =
309- ( user . mergedPullRequests . totalCount / user . pullRequests . totalCount ) * 100 ;
309+ ( user . mergedPullRequests . totalCount / user . pullRequests . totalCount ) *
310+ 100 || 0 ;
310311 }
311312 stats . totalReviews = user . reviews . totalPullRequestReviewContributions ;
312313 stats . totalIssues = user . openIssues . totalCount + user . closedIssues . totalCount ;
Original file line number Diff line number Diff line change @@ -43,6 +43,16 @@ const data_stats = {
4343const data_year2003 = JSON . parse ( JSON . stringify ( data_stats ) ) ;
4444data_year2003 . data . user . commits . totalCommitContributions = 428 ;
4545
46+ const data_without_pull_requests = {
47+ data : {
48+ user : {
49+ ...data_stats . data . user ,
50+ pullRequests : { totalCount : 0 } ,
51+ mergedPullRequests : { totalCount : 0 } ,
52+ } ,
53+ } ,
54+ } ;
55+
4656const data_repo = {
4757 data : {
4858 user : {
@@ -471,4 +481,37 @@ describe("Test fetchStats", () => {
471481 rank,
472482 } ) ;
473483 } ) ;
484+
485+ it ( "should return correct data when user don't have any pull requests" , async ( ) => {
486+ mock . reset ( ) ;
487+ mock
488+ . onPost ( "https://api.github.com/graphql" )
489+ . reply ( 200 , data_without_pull_requests ) ;
490+ const stats = await fetchStats ( "anuraghazra" , false , [ ] , true ) ;
491+ const rank = calculateRank ( {
492+ all_commits : false ,
493+ commits : 100 ,
494+ prs : 0 ,
495+ reviews : 50 ,
496+ issues : 200 ,
497+ repos : 5 ,
498+ stars : 300 ,
499+ followers : 100 ,
500+ } ) ;
501+
502+ expect ( stats ) . toStrictEqual ( {
503+ contributedTo : 61 ,
504+ name : "Anurag Hazra" ,
505+ totalCommits : 100 ,
506+ totalIssues : 200 ,
507+ totalPRs : 0 ,
508+ totalPRsMerged : 0 ,
509+ mergedPRsPercentage : 0 ,
510+ totalReviews : 50 ,
511+ totalStars : 300 ,
512+ totalDiscussionsStarted : 0 ,
513+ totalDiscussionsAnswered : 0 ,
514+ rank,
515+ } ) ;
516+ } ) ;
474517} ) ;
You can’t perform that action at this time.
0 commit comments