mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2025-06-04 05:40:13 +00:00
Issues overview should not show issues from archived repos (#13220)
* Add lots of comments to user.Issues() * Answered some questions from comments * fix typo in comment * Refac user.Issues(): add func repoIDs * Refac user.Issues(): add func userRepoIDs * Refac user.Issues(): add func issueIDsFromSearch * Refac user.Issues(): improve error handling * Refac user.Issues(): add inline documentation and move variable declarations closer to their usages * Refac user.Issues(): add func repoIDMap * Refac user.Issues(): cleanup * Refac: Separate Issues from Pulls during routing * fix typo in comment * Adapt Unittests to Refactoring * Issue13171: Issue and PR Overviews now ignore archived Repositories * changed some verbatim SQL conditions to builder.Eq * models/issue.go: use OptionalBool properly Co-authored-by: 6543 <6543@obermui.de> * Use IsArchived rather than ExcludeArchivedRepos * fixed broken test after merge * added nil check * Added Unit Test securing Issue 13171 fix * Improved IsArchived filtering in issue.GetUserIssueStats * Removed unused func * Added grouping to avoid returning duplicate repo IDs Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: Gitea <gitea@fake.local> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
This commit is contained in:
parent
81467e6f35
commit
564030336d
14 changed files with 494 additions and 167 deletions
|
@ -15,13 +15,46 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestArchivedIssues(t *testing.T) {
|
||||
// Arrange
|
||||
setting.UI.IssuePagingNum = 1
|
||||
assert.NoError(t, models.LoadFixtures())
|
||||
|
||||
ctx := test.MockContext(t, "issues")
|
||||
test.LoadUser(t, ctx, 30)
|
||||
ctx.Req.Form.Set("state", "open")
|
||||
|
||||
// Assume: User 30 has access to two Repos with Issues, one of the Repos being archived.
|
||||
repos, _, _ := models.GetUserRepositories(&models.SearchRepoOptions{Actor: ctx.User})
|
||||
assert.Len(t, repos, 2)
|
||||
IsArchived := make(map[int64]bool)
|
||||
NumIssues := make(map[int64]int)
|
||||
for _, repo := range repos {
|
||||
IsArchived[repo.ID] = repo.IsArchived
|
||||
NumIssues[repo.ID] = repo.NumIssues
|
||||
}
|
||||
assert.EqualValues(t, false, IsArchived[50])
|
||||
assert.EqualValues(t, 1, NumIssues[50])
|
||||
assert.EqualValues(t, true, IsArchived[51])
|
||||
assert.EqualValues(t, 1, NumIssues[51])
|
||||
|
||||
// Act
|
||||
Issues(ctx)
|
||||
|
||||
// Assert: One Issue (ID 30) from one Repo (ID 50) is retrieved, while nothing from archived Repo 51 is retrieved
|
||||
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
|
||||
|
||||
assert.EqualValues(t, map[int64]int64{50: 1}, ctx.Data["Counts"])
|
||||
assert.Len(t, ctx.Data["Issues"], 1)
|
||||
assert.Len(t, ctx.Data["Repos"], 1)
|
||||
}
|
||||
|
||||
func TestIssues(t *testing.T) {
|
||||
setting.UI.IssuePagingNum = 1
|
||||
assert.NoError(t, models.LoadFixtures())
|
||||
|
||||
ctx := test.MockContext(t, "issues")
|
||||
test.LoadUser(t, ctx, 2)
|
||||
ctx.SetParams(":type", "issues")
|
||||
ctx.Req.Form.Set("state", "closed")
|
||||
Issues(ctx)
|
||||
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
|
||||
|
@ -32,6 +65,19 @@ func TestIssues(t *testing.T) {
|
|||
assert.Len(t, ctx.Data["Repos"], 2)
|
||||
}
|
||||
|
||||
func TestPulls(t *testing.T) {
|
||||
setting.UI.IssuePagingNum = 20
|
||||
assert.NoError(t, models.LoadFixtures())
|
||||
|
||||
ctx := test.MockContext(t, "pulls")
|
||||
test.LoadUser(t, ctx, 2)
|
||||
ctx.Req.Form.Set("state", "open")
|
||||
Pulls(ctx)
|
||||
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
|
||||
|
||||
assert.Len(t, ctx.Data["Issues"], 3)
|
||||
}
|
||||
|
||||
func TestMilestones(t *testing.T) {
|
||||
setting.UI.IssuePagingNum = 1
|
||||
assert.NoError(t, models.LoadFixtures())
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue