2017-08-03 10:39:16 +05:30
|
|
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
2022-11-27 23:50:29 +05:30
|
|
|
// SPDX-License-Identifier: MIT
|
2017-08-03 10:39:16 +05:30
|
|
|
|
|
|
|
package user
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
2023-10-15 21:16:06 +05:30
|
|
|
"code.gitea.io/gitea/models/db"
|
2022-06-06 13:31:49 +05:30
|
|
|
repo_model "code.gitea.io/gitea/models/repo"
|
2021-11-12 20:06:47 +05:30
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2023-09-01 16:56:07 +05:30
|
|
|
"code.gitea.io/gitea/modules/contexttest"
|
2019-08-23 22:10:30 +05:30
|
|
|
"code.gitea.io/gitea/modules/setting"
|
2017-08-03 10:39:16 +05:30
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2021-01-13 09:49:17 +05:30
|
|
|
func TestArchivedIssues(t *testing.T) {
|
|
|
|
// Arrange
|
|
|
|
setting.UI.IssuePagingNum = 1
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.LoadFixtures())
|
2021-01-13 09:49:17 +05:30
|
|
|
|
2023-09-01 16:56:07 +05:30
|
|
|
ctx, _ := contexttest.MockContext(t, "issues")
|
|
|
|
contexttest.LoadUser(t, ctx, 30)
|
2021-01-13 09:49:17 +05:30
|
|
|
ctx.Req.Form.Set("state", "open")
|
|
|
|
|
|
|
|
// Assume: User 30 has access to two Repos with Issues, one of the Repos being archived.
|
2023-10-15 21:16:06 +05:30
|
|
|
repos, _, _ := repo_model.GetUserRepositories(db.DefaultContext, &repo_model.SearchRepoOptions{Actor: ctx.Doer})
|
2022-12-12 18:15:21 +05:30
|
|
|
assert.Len(t, repos, 3)
|
2021-01-13 09:49:17 +05:30
|
|
|
IsArchived := make(map[int64]bool)
|
|
|
|
NumIssues := make(map[int64]int)
|
|
|
|
for _, repo := range repos {
|
|
|
|
IsArchived[repo.ID] = repo.IsArchived
|
|
|
|
NumIssues[repo.ID] = repo.NumIssues
|
|
|
|
}
|
2021-06-07 10:57:09 +05:30
|
|
|
assert.False(t, IsArchived[50])
|
2021-01-13 09:49:17 +05:30
|
|
|
assert.EqualValues(t, 1, NumIssues[50])
|
2021-06-07 10:57:09 +05:30
|
|
|
assert.True(t, IsArchived[51])
|
2021-01-13 09:49:17 +05:30
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2017-08-03 10:39:16 +05:30
|
|
|
func TestIssues(t *testing.T) {
|
|
|
|
setting.UI.IssuePagingNum = 1
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.LoadFixtures())
|
2017-08-03 10:39:16 +05:30
|
|
|
|
2023-09-01 16:56:07 +05:30
|
|
|
ctx, _ := contexttest.MockContext(t, "issues")
|
|
|
|
contexttest.LoadUser(t, ctx, 2)
|
2017-08-03 10:39:16 +05:30
|
|
|
ctx.Req.Form.Set("state", "closed")
|
|
|
|
Issues(ctx)
|
|
|
|
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
|
|
|
|
|
2020-01-05 04:50:08 +05:30
|
|
|
assert.EqualValues(t, map[int64]int64{1: 1, 2: 1}, ctx.Data["Counts"])
|
2017-08-03 10:39:16 +05:30
|
|
|
assert.EqualValues(t, true, ctx.Data["IsShowClosed"])
|
|
|
|
assert.Len(t, ctx.Data["Issues"], 1)
|
2020-01-05 04:50:08 +05:30
|
|
|
assert.Len(t, ctx.Data["Repos"], 2)
|
2017-08-03 10:39:16 +05:30
|
|
|
}
|
2019-12-15 19:50:08 +05:30
|
|
|
|
2021-01-13 09:49:17 +05:30
|
|
|
func TestPulls(t *testing.T) {
|
|
|
|
setting.UI.IssuePagingNum = 20
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.LoadFixtures())
|
2021-01-13 09:49:17 +05:30
|
|
|
|
2023-09-01 16:56:07 +05:30
|
|
|
ctx, _ := contexttest.MockContext(t, "pulls")
|
|
|
|
contexttest.LoadUser(t, ctx, 2)
|
2021-01-13 09:49:17 +05:30
|
|
|
ctx.Req.Form.Set("state", "open")
|
|
|
|
Pulls(ctx)
|
|
|
|
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
|
|
|
|
|
2023-07-29 00:48:12 +05:30
|
|
|
assert.Len(t, ctx.Data["Issues"], 5)
|
2021-01-13 09:49:17 +05:30
|
|
|
}
|
|
|
|
|
2019-12-15 19:50:08 +05:30
|
|
|
func TestMilestones(t *testing.T) {
|
|
|
|
setting.UI.IssuePagingNum = 1
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.LoadFixtures())
|
2019-12-15 19:50:08 +05:30
|
|
|
|
2023-09-01 16:56:07 +05:30
|
|
|
ctx, _ := contexttest.MockContext(t, "milestones")
|
|
|
|
contexttest.LoadUser(t, ctx, 2)
|
2019-12-15 19:50:08 +05:30
|
|
|
ctx.SetParams("sort", "issues")
|
|
|
|
ctx.Req.Form.Set("state", "closed")
|
|
|
|
ctx.Req.Form.Set("sort", "furthestduedate")
|
|
|
|
Milestones(ctx)
|
|
|
|
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
|
|
|
|
assert.EqualValues(t, map[int64]int64{1: 1}, ctx.Data["Counts"])
|
|
|
|
assert.EqualValues(t, true, ctx.Data["IsShowClosed"])
|
|
|
|
assert.EqualValues(t, "furthestduedate", ctx.Data["SortType"])
|
|
|
|
assert.EqualValues(t, 1, ctx.Data["Total"])
|
|
|
|
assert.Len(t, ctx.Data["Milestones"], 1)
|
2020-03-31 13:17:00 +05:30
|
|
|
assert.Len(t, ctx.Data["Repos"], 2) // both repo 42 and 1 have milestones and both are owned by user 2
|
2019-12-15 19:50:08 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
func TestMilestonesForSpecificRepo(t *testing.T) {
|
|
|
|
setting.UI.IssuePagingNum = 1
|
2021-11-12 20:06:47 +05:30
|
|
|
assert.NoError(t, unittest.LoadFixtures())
|
2019-12-15 19:50:08 +05:30
|
|
|
|
2023-09-01 16:56:07 +05:30
|
|
|
ctx, _ := contexttest.MockContext(t, "milestones")
|
|
|
|
contexttest.LoadUser(t, ctx, 2)
|
2019-12-15 19:50:08 +05:30
|
|
|
ctx.SetParams("sort", "issues")
|
|
|
|
ctx.SetParams("repo", "1")
|
|
|
|
ctx.Req.Form.Set("state", "closed")
|
|
|
|
ctx.Req.Form.Set("sort", "furthestduedate")
|
|
|
|
Milestones(ctx)
|
|
|
|
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
|
|
|
|
assert.EqualValues(t, map[int64]int64{1: 1}, ctx.Data["Counts"])
|
|
|
|
assert.EqualValues(t, true, ctx.Data["IsShowClosed"])
|
|
|
|
assert.EqualValues(t, "furthestduedate", ctx.Data["SortType"])
|
|
|
|
assert.EqualValues(t, 1, ctx.Data["Total"])
|
|
|
|
assert.Len(t, ctx.Data["Milestones"], 1)
|
2020-03-31 13:17:00 +05:30
|
|
|
assert.Len(t, ctx.Data["Repos"], 2) // both repo 42 and 1 have milestones and both are owned by user 2
|
2019-12-15 19:50:08 +05:30
|
|
|
}
|