|
|
|
@ -117,27 +117,33 @@ func TestAPIAddIssueLabels(t *testing.T) {
|
|
|
|
|
func TestAPIAddIssueLabelsWithLabelNames(t *testing.T) {
|
|
|
|
|
assert.NoError(t, unittest.LoadFixtures())
|
|
|
|
|
|
|
|
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 1})
|
|
|
|
|
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{RepoID: repo.ID})
|
|
|
|
|
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 3})
|
|
|
|
|
issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 6, RepoID: repo.ID})
|
|
|
|
|
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
|
|
|
|
|
repoLabel := unittest.AssertExistsAndLoadBean(t, &issues_model.Label{ID: 10, RepoID: repo.ID})
|
|
|
|
|
orgLabel := unittest.AssertExistsAndLoadBean(t, &issues_model.Label{ID: 4, OrgID: owner.ID})
|
|
|
|
|
|
|
|
|
|
session := loginUser(t, owner.Name)
|
|
|
|
|
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue)
|
|
|
|
|
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/labels",
|
|
|
|
|
repo.OwnerName, repo.Name, issue.Index)
|
|
|
|
|
user1Session := loginUser(t, "user1")
|
|
|
|
|
token := getTokenForLoggedInUser(t, user1Session, auth_model.AccessTokenScopeWriteIssue)
|
|
|
|
|
|
|
|
|
|
// add the org label and the repo label to the issue
|
|
|
|
|
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/labels", owner.Name, repo.Name, issue.Index)
|
|
|
|
|
req := NewRequestWithJSON(t, "POST", urlStr, &api.IssueLabelsOption{
|
|
|
|
|
Labels: []any{"label1", "label2"},
|
|
|
|
|
Labels: []any{repoLabel.Name, orgLabel.Name},
|
|
|
|
|
}).AddTokenAuth(token)
|
|
|
|
|
resp := MakeRequest(t, req, http.StatusOK)
|
|
|
|
|
var apiLabels []*api.Label
|
|
|
|
|
DecodeJSON(t, resp, &apiLabels)
|
|
|
|
|
assert.Len(t, apiLabels, unittest.GetCount(t, &issues_model.IssueLabel{IssueID: issue.ID}))
|
|
|
|
|
|
|
|
|
|
var apiLabelNames []string
|
|
|
|
|
for _, label := range apiLabels {
|
|
|
|
|
apiLabelNames = append(apiLabelNames, label.Name)
|
|
|
|
|
}
|
|
|
|
|
assert.ElementsMatch(t, apiLabelNames, []string{"label1", "label2"})
|
|
|
|
|
assert.ElementsMatch(t, apiLabelNames, []string{repoLabel.Name, orgLabel.Name})
|
|
|
|
|
|
|
|
|
|
// delete labels
|
|
|
|
|
req = NewRequest(t, "DELETE", urlStr).AddTokenAuth(token)
|
|
|
|
|
MakeRequest(t, req, http.StatusNoContent)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestAPIReplaceIssueLabels(t *testing.T) {
|
|
|
|
|