|
1 | 1 | package github |
2 | 2 |
|
3 | 3 | import ( |
| 4 | + "bot/pkg/date" |
4 | 5 | "context" |
5 | 6 | "testing" |
6 | 7 | "time" |
@@ -191,9 +192,9 @@ func TestGithubService_GetContributionsByUsername__DatesZeroValue(t *testing.T) |
191 | 192 | ctx, |
192 | 193 | mock.AnythingOfType("*github.contributionsQuery"), |
193 | 194 | mock.MatchedBy(func(params map[string]interface{}) bool { |
194 | | - assert.WithinDuration(time.Now(), params["to"].(githubv4.DateTime).Time, time.Millisecond) |
195 | | - assert.WithinDuration(time.Now().AddDate(-1, 0, 0), params["from"].(githubv4.DateTime).Time, time.Millisecond) |
196 | | - return githubv4.String(options.Username) == params["username"] |
| 195 | + return githubv4.String(options.Username) == params["username"] && |
| 196 | + date.WithinDuration(time.Now(), params["to"].(githubv4.DateTime).Time, time.Millisecond) && |
| 197 | + date.WithinDuration(time.Now().AddDate(-1, 0, 0), params["from"].(githubv4.DateTime).Time, time.Millisecond) |
197 | 198 | }), |
198 | 199 | ).Return(nil).Run(func(args mock.Arguments) { |
199 | 200 | a := args.Get(1).(*contributionsQuery) |
@@ -378,9 +379,9 @@ func TestGithubService_GetLongestContributionStreakByUsername(t *testing.T) { |
378 | 379 | ctx, |
379 | 380 | mock.AnythingOfType("*github.contributionsQuery"), |
380 | 381 | mock.MatchedBy(func(params map[string]interface{}) bool { |
381 | | - assert.WithinDuration(from, params["from"].(githubv4.DateTime).Time, time.Millisecond) |
382 | | - assert.WithinDuration(year, params["to"].(githubv4.DateTime).Time, time.Millisecond) |
383 | | - return githubv4.String(username) == params["username"] |
| 382 | + return githubv4.String(username) == params["username"] && |
| 383 | + date.WithinDuration(from, params["from"].(githubv4.DateTime).Time, time.Millisecond) && |
| 384 | + date.WithinDuration(year, params["to"].(githubv4.DateTime).Time, time.Millisecond) |
384 | 385 | }), |
385 | 386 | ).Return(nil).Run(func(args mock.Arguments) { |
386 | 387 | a := args.Get(1).(*contributionsQuery) |
@@ -471,9 +472,9 @@ func TestGithubService_GetLongestContributionStreakByUsername__NoEndDateCurrentS |
471 | 472 | ctx, |
472 | 473 | mock.AnythingOfType("*github.contributionsQuery"), |
473 | 474 | mock.MatchedBy(func(params map[string]interface{}) bool { |
474 | | - assert.WithinDuration(from, params["from"].(githubv4.DateTime).Time, time.Millisecond) |
475 | | - assert.WithinDuration(year, params["to"].(githubv4.DateTime).Time, time.Millisecond) |
476 | | - return githubv4.String(username) == params["username"] |
| 475 | + return githubv4.String(username) == params["username"] && |
| 476 | + date.WithinDuration(from, params["from"].(githubv4.DateTime).Time, time.Millisecond) && |
| 477 | + date.WithinDuration(year, params["to"].(githubv4.DateTime).Time, time.Millisecond) |
477 | 478 | }), |
478 | 479 | ).Return(nil).Run(func(args mock.Arguments) { |
479 | 480 | a := args.Get(1).(*contributionsQuery) |
@@ -554,9 +555,9 @@ func TestGithubService_GetLongestContributionStreakByUsername__NoContributionDay |
554 | 555 | ctx, |
555 | 556 | mock.AnythingOfType("*github.contributionsQuery"), |
556 | 557 | mock.MatchedBy(func(params map[string]interface{}) bool { |
557 | | - assert.WithinDuration(from, params["from"].(githubv4.DateTime).Time, time.Millisecond) |
558 | | - assert.WithinDuration(year, params["to"].(githubv4.DateTime).Time, time.Millisecond) |
559 | | - return githubv4.String(username) == params["username"] |
| 558 | + return githubv4.String(username) == params["username"] && |
| 559 | + date.WithinDuration(from, params["from"].(githubv4.DateTime).Time, time.Millisecond) && |
| 560 | + date.WithinDuration(year, params["to"].(githubv4.DateTime).Time, time.Millisecond) |
560 | 561 | }), |
561 | 562 | ).Return(nil).Run(func(args mock.Arguments) { |
562 | 563 | a := args.Get(1).(*contributionsQuery) |
@@ -621,9 +622,9 @@ func TestGithubService_GetTotalContributionsByUsername(t *testing.T) { |
621 | 622 | ctx, |
622 | 623 | mock.AnythingOfType("*github.contributionsQuery"), |
623 | 624 | mock.MatchedBy(func(params map[string]interface{}) bool { |
624 | | - assert.WithinDuration(year, params["from"].(githubv4.DateTime).Time, time.Millisecond) |
625 | | - assert.WithinDuration(time.Now(), params["to"].(githubv4.DateTime).Time, time.Millisecond) |
626 | | - return githubv4.String(username) == params["username"] |
| 625 | + return githubv4.String(username) == params["username"] && |
| 626 | + date.WithinDuration(year, params["from"].(githubv4.DateTime).Time, time.Millisecond) && |
| 627 | + date.WithinDuration(time.Now(), params["to"].(githubv4.DateTime).Time, time.Millisecond) |
627 | 628 | }), |
628 | 629 | ).Return(nil).Run(func(args mock.Arguments) { |
629 | 630 | a := args.Get(1).(*contributionsQuery) |
|
0 commit comments