2017-06-25 14:51:07 +00: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 (
|
2018-09-13 02:33:48 +00:00
|
|
|
"fmt"
|
2017-06-25 14:51:07 +00:00
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models"
|
2019-05-11 10:21:34 +00:00
|
|
|
api "code.gitea.io/gitea/modules/structs"
|
2017-06-25 14:51:07 +00:00
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAPIListIssues(t *testing.T) {
|
|
|
|
prepareTestEnv(t)
|
|
|
|
|
|
|
|
repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
|
|
|
|
owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
|
|
|
|
|
|
|
|
session := loginUser(t, owner.Name)
|
2018-09-10 16:15:52 +00:00
|
|
|
token := getTokenForLoggedInUser(t, session)
|
|
|
|
req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues?state=all&token=%s",
|
|
|
|
owner.Name, repo.Name, token)
|
2017-07-07 19:36:47 +00:00
|
|
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
2017-06-25 14:51:07 +00:00
|
|
|
var apiIssues []*api.Issue
|
|
|
|
DecodeJSON(t, resp, &apiIssues)
|
|
|
|
assert.Len(t, apiIssues, models.GetCount(t, &models.Issue{RepoID: repo.ID}))
|
|
|
|
for _, apiIssue := range apiIssues {
|
|
|
|
models.AssertExistsAndLoadBean(t, &models.Issue{ID: apiIssue.ID, RepoID: repo.ID})
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAPICreateIssue(t *testing.T) {
|
|
|
|
prepareTestEnv(t)
|
|
|
|
const body, title = "apiTestBody", "apiTestTitle"
|
|
|
|
|
|
|
|
repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
|
|
|
|
owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
|
|
|
|
|
|
|
|
session := loginUser(t, owner.Name)
|
2018-09-10 16:15:52 +00:00
|
|
|
token := getTokenForLoggedInUser(t, session)
|
|
|
|
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues?state=all&token=%s", owner.Name, repo.Name, token)
|
2017-06-25 14:51:07 +00:00
|
|
|
req := NewRequestWithJSON(t, "POST", urlStr, &api.CreateIssueOption{
|
|
|
|
Body: body,
|
|
|
|
Title: title,
|
|
|
|
Assignee: owner.Name,
|
|
|
|
})
|
2017-07-07 19:36:47 +00:00
|
|
|
resp := session.MakeRequest(t, req, http.StatusCreated)
|
2017-06-25 14:51:07 +00:00
|
|
|
var apiIssue api.Issue
|
|
|
|
DecodeJSON(t, resp, &apiIssue)
|
|
|
|
assert.Equal(t, apiIssue.Body, body)
|
|
|
|
assert.Equal(t, apiIssue.Title, title)
|
|
|
|
|
|
|
|
models.AssertExistsAndLoadBean(t, &models.Issue{
|
|
|
|
RepoID: repo.ID,
|
|
|
|
AssigneeID: owner.ID,
|
|
|
|
Content: body,
|
|
|
|
Title: title,
|
|
|
|
})
|
|
|
|
}
|