2017-08-03 07:09:16 +02:00
|
|
|
// Copyright 2017 The Gitea Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a MIT-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
package user
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models"
|
2021-11-12 15:36:47 +01:00
|
|
|
"code.gitea.io/gitea/models/unittest"
|
2019-08-23 18:40:30 +02:00
|
|
|
"code.gitea.io/gitea/modules/setting"
|
2017-08-03 07:09:16 +02:00
|
|
|
"code.gitea.io/gitea/modules/test"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2021-01-13 05:19:17 +01:00
|
|
|
func TestArchivedIssues(t *testing.T) {
|
|
|
|
// Arrange
|
|
|
|
setting.UI.IssuePagingNum = 1
|
2021-11-12 15:36:47 +01:00
|
|
|
assert.NoError(t, unittest.LoadFixtures())
|
2021-01-13 05:19:17 +01:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
2021-06-07 07:27:09 +02:00
|
|
|
assert.False(t, IsArchived[50])
|
2021-01-13 05:19:17 +01:00
|
|
|
assert.EqualValues(t, 1, NumIssues[50])
|
2021-06-07 07:27:09 +02:00
|
|
|
assert.True(t, IsArchived[51])
|
2021-01-13 05:19:17 +01:00
|
|
|
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 07:09:16 +02:00
|
|
|
func TestIssues(t *testing.T) {
|
|
|
|
setting.UI.IssuePagingNum = 1
|
2021-11-12 15:36:47 +01:00
|
|
|
assert.NoError(t, unittest.LoadFixtures())
|
2017-08-03 07:09:16 +02:00
|
|
|
|
2017-11-30 16:52:15 +01:00
|
|
|
ctx := test.MockContext(t, "issues")
|
|
|
|
test.LoadUser(t, ctx, 2)
|
2017-08-03 07:09:16 +02:00
|
|
|
ctx.Req.Form.Set("state", "closed")
|
|
|
|
Issues(ctx)
|
|
|
|
assert.EqualValues(t, http.StatusOK, ctx.Resp.Status())
|
|
|
|
|
2020-01-05 00:20:08 +01:00
|
|
|
assert.EqualValues(t, map[int64]int64{1: 1, 2: 1}, ctx.Data["Counts"])
|
2017-08-03 07:09:16 +02:00
|
|
|
assert.EqualValues(t, true, ctx.Data["IsShowClosed"])
|
|
|
|
assert.Len(t, ctx.Data["Issues"], 1)
|
2020-01-05 00:20:08 +01:00
|
|
|
assert.Len(t, ctx.Data["Repos"], 2)
|
2017-08-03 07:09:16 +02:00
|
|
|
}
|
2019-12-15 15:20:08 +01:00
|
|
|
|
2021-01-13 05:19:17 +01:00
|
|
|
func TestPulls(t *testing.T) {
|
|
|
|
setting.UI.IssuePagingNum = 20
|
2021-11-12 15:36:47 +01:00
|
|
|
assert.NoError(t, unittest.LoadFixtures())
|
2021-01-13 05:19:17 +01:00
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
|
|
|
|
2019-12-15 15:20:08 +01:00
|
|
|
func TestMilestones(t *testing.T) {
|
|
|
|
setting.UI.IssuePagingNum = 1
|
2021-11-12 15:36:47 +01:00
|
|
|
assert.NoError(t, unittest.LoadFixtures())
|
2019-12-15 15:20:08 +01:00
|
|
|
|
|
|
|
ctx := test.MockContext(t, "milestones")
|
|
|
|
test.LoadUser(t, ctx, 2)
|
|
|
|
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 09:47:00 +02:00
|
|
|
assert.Len(t, ctx.Data["Repos"], 2) // both repo 42 and 1 have milestones and both are owned by user 2
|
2019-12-15 15:20:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestMilestonesForSpecificRepo(t *testing.T) {
|
|
|
|
setting.UI.IssuePagingNum = 1
|
2021-11-12 15:36:47 +01:00
|
|
|
assert.NoError(t, unittest.LoadFixtures())
|
2019-12-15 15:20:08 +01:00
|
|
|
|
|
|
|
ctx := test.MockContext(t, "milestones")
|
|
|
|
test.LoadUser(t, ctx, 2)
|
|
|
|
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 09:47:00 +02:00
|
|
|
assert.Len(t, ctx.Data["Repos"], 2) // both repo 42 and 1 have milestones and both are owned by user 2
|
2019-12-15 15:20:08 +01:00
|
|
|
}
|