2017-06-25 07:52:51 +08: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 (
|
|
|
|
"fmt"
|
|
|
|
"net/http"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"code.gitea.io/gitea/models"
|
|
|
|
api "code.gitea.io/sdk/gitea"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAPIAddIssueLabels(t *testing.T) {
|
|
|
|
assert.NoError(t, models.LoadFixtures())
|
|
|
|
|
|
|
|
repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
|
|
|
|
issue := models.AssertExistsAndLoadBean(t, &models.Issue{RepoID: repo.ID}).(*models.Issue)
|
|
|
|
label := models.AssertExistsAndLoadBean(t, &models.Label{RepoID: repo.ID}).(*models.Label)
|
|
|
|
owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
|
|
|
|
|
2018-09-11 00:15:52 +08:00
|
|
|
session := loginUser(t, owner.Name)
|
|
|
|
token := getTokenForLoggedInUser(t, session)
|
|
|
|
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/labels?token=%s",
|
|
|
|
owner.Name, repo.Name, issue.Index, token)
|
2017-06-25 07:52:51 +08:00
|
|
|
req := NewRequestWithJSON(t, "POST", urlStr, &api.IssueLabelsOption{
|
|
|
|
Labels: []int64{label.ID},
|
|
|
|
})
|
2017-07-08 03:36:47 +08:00
|
|
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
2017-06-25 07:52:51 +08:00
|
|
|
var apiLabels []*api.Label
|
|
|
|
DecodeJSON(t, resp, &apiLabels)
|
|
|
|
assert.Len(t, apiLabels, models.GetCount(t, &models.IssueLabel{IssueID: issue.ID}))
|
|
|
|
|
|
|
|
models.AssertExistsAndLoadBean(t, &models.IssueLabel{IssueID: issue.ID, LabelID: label.ID})
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestAPIReplaceIssueLabels(t *testing.T) {
|
|
|
|
assert.NoError(t, models.LoadFixtures())
|
|
|
|
|
|
|
|
repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
|
|
|
|
issue := models.AssertExistsAndLoadBean(t, &models.Issue{RepoID: repo.ID}).(*models.Issue)
|
|
|
|
label := models.AssertExistsAndLoadBean(t, &models.Label{RepoID: repo.ID}).(*models.Label)
|
|
|
|
owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
|
|
|
|
|
2018-09-11 00:15:52 +08:00
|
|
|
session := loginUser(t, owner.Name)
|
|
|
|
token := getTokenForLoggedInUser(t, session)
|
|
|
|
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/labels?token=%s",
|
|
|
|
owner.Name, repo.Name, issue.Index, token)
|
2017-06-25 07:52:51 +08:00
|
|
|
req := NewRequestWithJSON(t, "PUT", urlStr, &api.IssueLabelsOption{
|
|
|
|
Labels: []int64{label.ID},
|
|
|
|
})
|
2017-07-08 03:36:47 +08:00
|
|
|
resp := session.MakeRequest(t, req, http.StatusOK)
|
2017-06-25 07:52:51 +08:00
|
|
|
var apiLabels []*api.Label
|
|
|
|
DecodeJSON(t, resp, &apiLabels)
|
2017-08-28 17:17:45 +08:00
|
|
|
if assert.Len(t, apiLabels, 1) {
|
|
|
|
assert.EqualValues(t, label.ID, apiLabels[0].ID)
|
|
|
|
}
|
2017-06-25 07:52:51 +08:00
|
|
|
|
|
|
|
models.AssertCount(t, &models.IssueLabel{IssueID: issue.ID}, 1)
|
|
|
|
models.AssertExistsAndLoadBean(t, &models.IssueLabel{IssueID: issue.ID, LabelID: label.ID})
|
|
|
|
}
|