Skip to content

Commit 0150b38

Browse files
committed
test for GetCurrentContributionStreakByUsername
1 parent 92a22e1 commit 0150b38

1 file changed

Lines changed: 59 additions & 2 deletions

File tree

internal/github/contributions_test.go

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -301,9 +301,66 @@ func TestCurrentContributionStreak_String__NoStreak(t *testing.T) {
301301

302302
}
303303

304-
// TODO Tests: GetCurrentContributionStreakByUsername
305-
// labels: tests
306304
func TestGithubService_GetCurrentContributionStreakByUsername(t *testing.T) {
305+
assert := assert.New(t)
306+
githubClient := &MockGithubClient{}
307+
githubService := NewGithubService(githubClient)
308+
309+
ctx := context.Background()
310+
311+
username := "devy"
312+
to := time.Now()
313+
314+
from := time.Date(to.Year()-1, to.Month(), to.Day(), to.Hour(), to.Minute(), to.Second(), to.Nanosecond(), to.Location())
315+
316+
githubClient.On(
317+
"Query",
318+
ctx,
319+
mock.AnythingOfType("*github.contributionsQuery"),
320+
mock.MatchedBy(func(params map[string]interface{}) bool {
321+
assert.WithinDuration(from, params["from"].(githubv4.DateTime).Time, time.Millisecond)
322+
assert.WithinDuration(to, params["to"].(githubv4.DateTime).Time, time.Millisecond)
323+
return githubv4.String(username) == params["username"]
324+
}),
325+
).Return(nil).Run(func(args mock.Arguments) {
326+
a := args.Get(1).(*contributionsQuery)
327+
(*a) = contributionsQuery{
328+
User: user{
329+
ContributionsCollection: contributionsCollection{
330+
ContributionCalendar: contributionCalendar{
331+
TotalContributions: 100,
332+
Weeks: []week{
333+
{
334+
[]contributionDays{
335+
{
336+
ContributionCount: 5,
337+
Weekday: 7,
338+
Date: time.Date(time.Now().Year(), 7, 10, 0, 0, 0, 0, time.UTC).Format("2006-01-02"),
339+
},
340+
{
341+
ContributionCount: 5,
342+
Weekday: 6,
343+
Date: time.Date(time.Now().Year(), 7, 9, 0, 0, 0, 0, time.UTC).Format("2006-01-02"),
344+
},
345+
{
346+
ContributionCount: 0,
347+
Weekday: 5,
348+
Date: time.Date(time.Now().Year(), 7, 8, 0, 0, 0, 0, time.UTC).Format("2006-01-02"),
349+
},
350+
},
351+
},
352+
},
353+
},
354+
},
355+
},
356+
}
357+
}).Once()
358+
359+
resp, err := githubService.GetCurrentContributionStreakByUsername(ctx, username)
360+
361+
assert.NoError(err)
362+
assert.Equal(time.Date(time.Now().Year(), 7, 9, 0, 0, 0, 0, time.UTC), resp.StartedAt)
363+
assert.Equal(2, resp.Streak)
307364

308365
}
309366

0 commit comments

Comments
 (0)