|
|
|
@ -104,7 +104,7 @@ func TestAPIAddIssueLabels(t *testing.T) {
|
|
|
|
|
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/labels",
|
|
|
|
|
repo.OwnerName, repo.Name, issue.Index)
|
|
|
|
|
req := NewRequestWithJSON(t, "POST", urlStr, &api.IssueLabelsOption{
|
|
|
|
|
Labels: []int64{1, 2},
|
|
|
|
|
Labels: []any{1, 2},
|
|
|
|
|
}).AddTokenAuth(token)
|
|
|
|
|
resp := MakeRequest(t, req, http.StatusOK)
|
|
|
|
|
var apiLabels []*api.Label
|
|
|
|
@ -114,6 +114,32 @@ func TestAPIAddIssueLabels(t *testing.T) {
|
|
|
|
|
unittest.AssertExistsAndLoadBean(t, &issues_model.IssueLabel{IssueID: issue.ID, LabelID: 2})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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})
|
|
|
|
|
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
req := NewRequestWithJSON(t, "POST", urlStr, &api.IssueLabelsOption{
|
|
|
|
|
Labels: []any{"label1", "label2"},
|
|
|
|
|
}).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"})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestAPIReplaceIssueLabels(t *testing.T) {
|
|
|
|
|
assert.NoError(t, unittest.LoadFixtures())
|
|
|
|
|
|
|
|
|
@ -127,7 +153,7 @@ func TestAPIReplaceIssueLabels(t *testing.T) {
|
|
|
|
|
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/labels",
|
|
|
|
|
owner.Name, repo.Name, issue.Index)
|
|
|
|
|
req := NewRequestWithJSON(t, "PUT", urlStr, &api.IssueLabelsOption{
|
|
|
|
|
Labels: []int64{label.ID},
|
|
|
|
|
Labels: []any{label.ID},
|
|
|
|
|
}).AddTokenAuth(token)
|
|
|
|
|
resp := MakeRequest(t, req, http.StatusOK)
|
|
|
|
|
var apiLabels []*api.Label
|
|
|
|
@ -140,6 +166,29 @@ func TestAPIReplaceIssueLabels(t *testing.T) {
|
|
|
|
|
unittest.AssertExistsAndLoadBean(t, &issues_model.IssueLabel{IssueID: issue.ID, LabelID: label.ID})
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestAPIReplaceIssueLabelsWithLabelNames(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})
|
|
|
|
|
label := unittest.AssertExistsAndLoadBean(t, &issues_model.Label{RepoID: repo.ID})
|
|
|
|
|
owner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
|
|
|
|
|
|
|
|
|
|
session := loginUser(t, owner.Name)
|
|
|
|
|
token := getTokenForLoggedInUser(t, session, auth_model.AccessTokenScopeWriteIssue)
|
|
|
|
|
urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/labels",
|
|
|
|
|
owner.Name, repo.Name, issue.Index)
|
|
|
|
|
req := NewRequestWithJSON(t, "PUT", urlStr, &api.IssueLabelsOption{
|
|
|
|
|
Labels: []any{label.Name},
|
|
|
|
|
}).AddTokenAuth(token)
|
|
|
|
|
resp := MakeRequest(t, req, http.StatusOK)
|
|
|
|
|
var apiLabels []*api.Label
|
|
|
|
|
DecodeJSON(t, resp, &apiLabels)
|
|
|
|
|
if assert.Len(t, apiLabels, 1) {
|
|
|
|
|
assert.EqualValues(t, label.Name, apiLabels[0].Name)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestAPIModifyOrgLabels(t *testing.T) {
|
|
|
|
|
assert.NoError(t, unittest.LoadFixtures())
|
|
|
|
|
|
|
|
|
|