|
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) |
@@ -435,9 +436,9 @@ func TestGithubService_GetLongestContributionStreakByUsername(t *testing.T) { |
435 | 436 | ctx, |
436 | 437 | mock.AnythingOfType("*github.contributionsQuery"), |
437 | 438 | mock.MatchedBy(func(params map[string]interface{}) bool { |
438 | | - assert.WithinDuration(from, params["from"].(githubv4.DateTime).Time, time.Millisecond) |
439 | | - assert.WithinDuration(year, params["to"].(githubv4.DateTime).Time, time.Millisecond) |
440 | | - return githubv4.String(username) == params["username"] |
| 439 | + return githubv4.String(username) == params["username"] && |
| 440 | + date.WithinDuration(from, params["from"].(githubv4.DateTime).Time, time.Millisecond) && |
| 441 | + date.WithinDuration(year, params["to"].(githubv4.DateTime).Time, time.Millisecond) |
441 | 442 | }), |
442 | 443 | ).Return(nil).Run(func(args mock.Arguments) { |
443 | 444 | a := args.Get(1).(*contributionsQuery) |
@@ -528,9 +529,9 @@ func TestGithubService_GetLongestContributionStreakByUsername__NoEndDateCurrentS |
528 | 529 | ctx, |
529 | 530 | mock.AnythingOfType("*github.contributionsQuery"), |
530 | 531 | mock.MatchedBy(func(params map[string]interface{}) bool { |
531 | | - assert.WithinDuration(from, params["from"].(githubv4.DateTime).Time, time.Millisecond) |
532 | | - assert.WithinDuration(year, params["to"].(githubv4.DateTime).Time, time.Millisecond) |
533 | | - return githubv4.String(username) == params["username"] |
| 532 | + return githubv4.String(username) == params["username"] && |
| 533 | + date.WithinDuration(from, params["from"].(githubv4.DateTime).Time, time.Millisecond) && |
| 534 | + date.WithinDuration(year, params["to"].(githubv4.DateTime).Time, time.Millisecond) |
534 | 535 | }), |
535 | 536 | ).Return(nil).Run(func(args mock.Arguments) { |
536 | 537 | a := args.Get(1).(*contributionsQuery) |
@@ -611,9 +612,9 @@ func TestGithubService_GetLongestContributionStreakByUsername__NoContributionDay |
611 | 612 | ctx, |
612 | 613 | mock.AnythingOfType("*github.contributionsQuery"), |
613 | 614 | mock.MatchedBy(func(params map[string]interface{}) bool { |
614 | | - assert.WithinDuration(from, params["from"].(githubv4.DateTime).Time, time.Millisecond) |
615 | | - assert.WithinDuration(year, params["to"].(githubv4.DateTime).Time, time.Millisecond) |
616 | | - return githubv4.String(username) == params["username"] |
| 615 | + return githubv4.String(username) == params["username"] && |
| 616 | + date.WithinDuration(from, params["from"].(githubv4.DateTime).Time, time.Millisecond) && |
| 617 | + date.WithinDuration(year, params["to"].(githubv4.DateTime).Time, time.Millisecond) |
617 | 618 | }), |
618 | 619 | ).Return(nil).Run(func(args mock.Arguments) { |
619 | 620 | a := args.Get(1).(*contributionsQuery) |
@@ -678,9 +679,9 @@ func TestGithubService_GetTotalContributionsByUsername(t *testing.T) { |
678 | 679 | ctx, |
679 | 680 | mock.AnythingOfType("*github.contributionsQuery"), |
680 | 681 | mock.MatchedBy(func(params map[string]interface{}) bool { |
681 | | - assert.WithinDuration(year, params["from"].(githubv4.DateTime).Time, time.Millisecond) |
682 | | - assert.WithinDuration(time.Now(), params["to"].(githubv4.DateTime).Time, time.Millisecond) |
683 | | - return githubv4.String(username) == params["username"] |
| 682 | + return githubv4.String(username) == params["username"] && |
| 683 | + date.WithinDuration(year, params["from"].(githubv4.DateTime).Time, time.Millisecond) && |
| 684 | + date.WithinDuration(time.Now(), params["to"].(githubv4.DateTime).Time, time.Millisecond) |
684 | 685 | }), |
685 | 686 | ).Return(nil).Run(func(args mock.Arguments) { |
686 | 687 | a := args.Get(1).(*contributionsQuery) |
|
0 commit comments