diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2023-05-19 22:17:48 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-05-19 22:17:48 +0800 |
commit | 38cf43d0606c13c38f459659f38e26cf31dceccb (patch) | |
tree | 53cae445e91b7448ae37a00a7ae398aa082f958d /models/issues/issue_test.go | |
parent | c757765a9e5c2d4f73b1a7c3debe3548c735bd54 (diff) | |
download | gitea-38cf43d0606c13c38f459659f38e26cf31dceccb.tar.gz gitea-38cf43d0606c13c38f459659f38e26cf31dceccb.zip |
Some refactors for issues stats (#24793)
This PR
- [x] Move some functions from `issues.go` to `issue_stats.go` and
`issue_label.go`
- [x] Remove duplicated issue options `UserIssueStatsOption` to keep
only one `IssuesOptions`
Diffstat (limited to 'models/issues/issue_test.go')
-rw-r--r-- | models/issues/issue_test.go | 69 |
1 files changed, 39 insertions, 30 deletions
diff --git a/models/issues/issue_test.go b/models/issues/issue_test.go index 5bf2f819be..80699a57b4 100644 --- a/models/issues/issue_test.go +++ b/models/issues/issue_test.go @@ -17,6 +17,7 @@ import ( repo_model "code.gitea.io/gitea/models/repo" "code.gitea.io/gitea/models/unittest" user_model "code.gitea.io/gitea/models/user" + "code.gitea.io/gitea/modules/util" "github.com/stretchr/testify/assert" "xorm.io/builder" @@ -204,14 +205,16 @@ func TestIssues(t *testing.T) { func TestGetUserIssueStats(t *testing.T) { assert.NoError(t, unittest.PrepareTestDatabase()) for _, test := range []struct { - Opts issues_model.UserIssueStatsOptions + FilterMode int + Opts issues_model.IssuesOptions ExpectedIssueStats issues_model.IssueStats }{ { - issues_model.UserIssueStatsOptions{ - UserID: 1, - RepoIDs: []int64{1}, - FilterMode: issues_model.FilterModeAll, + issues_model.FilterModeAll, + issues_model.IssuesOptions{ + User: unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}), + RepoIDs: []int64{1}, + IsPull: util.OptionalBoolFalse, }, issues_model.IssueStats{ YourRepositoriesCount: 1, // 6 @@ -222,11 +225,12 @@ func TestGetUserIssueStats(t *testing.T) { }, }, { - issues_model.UserIssueStatsOptions{ - UserID: 1, - RepoIDs: []int64{1}, - FilterMode: issues_model.FilterModeAll, - IsClosed: true, + issues_model.FilterModeAll, + issues_model.IssuesOptions{ + User: unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}), + RepoIDs: []int64{1}, + IsPull: util.OptionalBoolFalse, + IsClosed: util.OptionalBoolTrue, }, issues_model.IssueStats{ YourRepositoriesCount: 1, // 6 @@ -237,9 +241,10 @@ func TestGetUserIssueStats(t *testing.T) { }, }, { - issues_model.UserIssueStatsOptions{ - UserID: 1, - FilterMode: issues_model.FilterModeAssign, + issues_model.FilterModeAssign, + issues_model.IssuesOptions{ + User: unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}), + IsPull: util.OptionalBoolFalse, }, issues_model.IssueStats{ YourRepositoriesCount: 1, // 6 @@ -250,9 +255,10 @@ func TestGetUserIssueStats(t *testing.T) { }, }, { - issues_model.UserIssueStatsOptions{ - UserID: 1, - FilterMode: issues_model.FilterModeCreate, + issues_model.FilterModeCreate, + issues_model.IssuesOptions{ + User: unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}), + IsPull: util.OptionalBoolFalse, }, issues_model.IssueStats{ YourRepositoriesCount: 1, // 6 @@ -263,9 +269,10 @@ func TestGetUserIssueStats(t *testing.T) { }, }, { - issues_model.UserIssueStatsOptions{ - UserID: 1, - FilterMode: issues_model.FilterModeMention, + issues_model.FilterModeMention, + issues_model.IssuesOptions{ + User: unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}), + IsPull: util.OptionalBoolFalse, }, issues_model.IssueStats{ YourRepositoriesCount: 1, // 6 @@ -277,10 +284,11 @@ func TestGetUserIssueStats(t *testing.T) { }, }, { - issues_model.UserIssueStatsOptions{ - UserID: 1, - FilterMode: issues_model.FilterModeCreate, - IssueIDs: []int64{1}, + issues_model.FilterModeCreate, + issues_model.IssuesOptions{ + User: unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 1}), + IssueIDs: []int64{1}, + IsPull: util.OptionalBoolFalse, }, issues_model.IssueStats{ YourRepositoriesCount: 1, // 1 @@ -291,11 +299,12 @@ func TestGetUserIssueStats(t *testing.T) { }, }, { - issues_model.UserIssueStatsOptions{ - UserID: 2, - Org: unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: 3}), - Team: unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: 7}), - FilterMode: issues_model.FilterModeAll, + issues_model.FilterModeAll, + issues_model.IssuesOptions{ + User: unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: 2}), + Org: unittest.AssertExistsAndLoadBean(t, &organization.Organization{ID: 3}), + Team: unittest.AssertExistsAndLoadBean(t, &organization.Team{ID: 7}), + IsPull: util.OptionalBoolFalse, }, issues_model.IssueStats{ YourRepositoriesCount: 2, @@ -306,7 +315,7 @@ func TestGetUserIssueStats(t *testing.T) { }, } { t.Run(fmt.Sprintf("%#v", test.Opts), func(t *testing.T) { - stats, err := issues_model.GetUserIssueStats(test.Opts) + stats, err := issues_model.GetUserIssueStats(test.FilterMode, test.Opts) if !assert.NoError(t, err) { return } @@ -495,7 +504,7 @@ func TestCorrectIssueStats(t *testing.T) { // Now we will call the GetIssueStats with these IDs and if working, // get the correct stats back. issueStats, err := issues_model.GetIssueStats(&issues_model.IssuesOptions{ - RepoID: 1, + RepoIDs: []int64{1}, IssueIDs: ids, }) |