2017-04-29 01:52:25 -04: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 integrations
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
2017-06-14 23:09:03 -04:00
|
|
|
"strconv"
|
|
|
|
"strings"
|
2017-04-29 01:52:25 -04:00
|
|
|
"testing"
|
|
|
|
|
2017-06-14 23:09:03 -04:00
|
|
|
"code.gitea.io/gitea/models"
|
|
|
|
"code.gitea.io/gitea/modules/setting"
|
|
|
|
|
|
|
|
"github.com/PuerkitoBio/goquery"
|
2017-04-29 01:52:25 -04:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
2017-06-14 23:09:03 -04:00
|
|
|
func getIssuesSelection(htmlDoc *HtmlDoc) *goquery.Selection {
|
|
|
|
return htmlDoc.doc.Find(".issue.list").Find("li").Find(".title")
|
|
|
|
}
|
|
|
|
|
|
|
|
func getIssue(t *testing.T, repoID int64, issueSelection *goquery.Selection) *models.Issue {
|
|
|
|
href, exists := issueSelection.Attr("href")
|
|
|
|
assert.True(t, exists)
|
|
|
|
indexStr := href[strings.LastIndexByte(href, '/')+1:]
|
|
|
|
index, err := strconv.Atoi(indexStr)
|
|
|
|
assert.NoError(t, err, "Invalid issue href: %s", href)
|
|
|
|
return models.AssertExistsAndLoadBean(t, &models.Issue{RepoID: repoID, Index: int64(index)}).(*models.Issue)
|
|
|
|
}
|
|
|
|
|
2017-05-26 23:34:11 -04:00
|
|
|
func TestNoLoginViewIssues(t *testing.T) {
|
|
|
|
prepareTestEnv(t)
|
|
|
|
|
2017-06-09 20:41:36 -04:00
|
|
|
req := NewRequest(t, "GET", "/user2/repo1/issues")
|
2017-05-26 23:34:11 -04:00
|
|
|
resp := MakeRequest(req)
|
|
|
|
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
|
|
}
|
|
|
|
|
2017-06-14 23:09:03 -04:00
|
|
|
func TestNoLoginViewIssuesSortByType(t *testing.T) {
|
|
|
|
prepareTestEnv(t)
|
|
|
|
|
|
|
|
user := models.AssertExistsAndLoadBean(t, &models.User{ID: 1}).(*models.User)
|
|
|
|
repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
|
|
|
|
repo.Owner = models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
|
|
|
|
|
2017-06-17 00:49:45 -04:00
|
|
|
session := loginUser(t, user.Name)
|
2017-06-14 23:09:03 -04:00
|
|
|
req := NewRequest(t, "GET", repo.RelLink()+"/issues?type=created_by")
|
|
|
|
resp := session.MakeRequest(t, req)
|
|
|
|
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
|
|
|
2017-06-17 00:49:45 -04:00
|
|
|
htmlDoc := NewHtmlParser(t, resp.Body)
|
2017-06-14 23:09:03 -04:00
|
|
|
issuesSelection := getIssuesSelection(htmlDoc)
|
|
|
|
expectedNumIssues := models.GetCount(t,
|
|
|
|
&models.Issue{RepoID: repo.ID, PosterID: user.ID},
|
|
|
|
models.Cond("is_closed=?", false),
|
|
|
|
models.Cond("is_pull=?", false),
|
|
|
|
)
|
|
|
|
if expectedNumIssues > setting.UI.IssuePagingNum {
|
|
|
|
expectedNumIssues = setting.UI.IssuePagingNum
|
|
|
|
}
|
|
|
|
assert.EqualValues(t, expectedNumIssues, issuesSelection.Length())
|
|
|
|
|
|
|
|
issuesSelection.Each(func(_ int, selection *goquery.Selection) {
|
|
|
|
issue := getIssue(t, repo.ID, selection)
|
|
|
|
assert.EqualValues(t, user.ID, issue.PosterID)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2017-04-29 01:52:25 -04:00
|
|
|
func TestNoLoginViewIssue(t *testing.T) {
|
|
|
|
prepareTestEnv(t)
|
|
|
|
|
2017-06-09 20:41:36 -04:00
|
|
|
req := NewRequest(t, "GET", "/user2/repo1/issues/1")
|
2017-04-29 01:52:25 -04:00
|
|
|
resp := MakeRequest(req)
|
|
|
|
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
|
|
|
|
}
|