@@ -330,9 +330,66 @@ func TestCurrentContributionStreak_String__NoStreak(t *testing.T) {
330330
331331}
332332
333- // TODO Tests: GetCurrentContributionStreakByUsername
334- // labels: tests
335333func TestGithubService_GetCurrentContributionStreakByUsername (t * testing.T ) {
334+ assert := assert .New (t )
335+ githubClient := & MockGithubClient {}
336+ githubService := NewGithubService (githubClient )
337+
338+ ctx := context .Background ()
339+
340+ username := "devy"
341+ to := time .Now ()
342+
343+ from := time .Date (to .Year ()- 1 , to .Month (), to .Day (), to .Hour (), to .Minute (), to .Second (), to .Nanosecond (), to .Location ())
344+
345+ githubClient .On (
346+ "Query" ,
347+ ctx ,
348+ mock .AnythingOfType ("*github.contributionsQuery" ),
349+ mock .MatchedBy (func (params map [string ]interface {}) bool {
350+ return date .WithinDuration (from , params ["from" ].(githubv4.DateTime ).Time , time .Millisecond ) &&
351+ date .WithinDuration (to , params ["to" ].(githubv4.DateTime ).Time , time .Millisecond ) &&
352+ githubv4 .String (username ) == params ["username" ]
353+ }),
354+ ).Return (nil ).Run (func (args mock.Arguments ) {
355+ a := args .Get (1 ).(* contributionsQuery )
356+ (* a ) = contributionsQuery {
357+ User : user {
358+ ContributionsCollection : contributionsCollection {
359+ ContributionCalendar : contributionCalendar {
360+ TotalContributions : 100 ,
361+ Weeks : []week {
362+ {
363+ []contributionDays {
364+ {
365+ ContributionCount : 5 ,
366+ Weekday : 7 ,
367+ Date : time .Date (time .Now ().Year (), 7 , 10 , 0 , 0 , 0 , 0 , time .UTC ).Format ("2006-01-02" ),
368+ },
369+ {
370+ ContributionCount : 5 ,
371+ Weekday : 6 ,
372+ Date : time .Date (time .Now ().Year (), 7 , 9 , 0 , 0 , 0 , 0 , time .UTC ).Format ("2006-01-02" ),
373+ },
374+ {
375+ ContributionCount : 0 ,
376+ Weekday : 5 ,
377+ Date : time .Date (time .Now ().Year (), 7 , 8 , 0 , 0 , 0 , 0 , time .UTC ).Format ("2006-01-02" ),
378+ },
379+ },
380+ },
381+ },
382+ },
383+ },
384+ },
385+ }
386+ }).Once ()
387+
388+ resp , err := githubService .GetCurrentContributionStreakByUsername (ctx , username )
389+
390+ assert .NoError (err )
391+ assert .Equal (time .Date (time .Now ().Year (), 7 , 9 , 0 , 0 , 0 , 0 , time .UTC ), resp .StartedAt )
392+ assert .Equal (2 , resp .Streak )
336393
337394}
338395
0 commit comments