@@ -117,27 +117,33 @@ func TestAPIAddIssueLabels(t *testing.T) {
117
117
func TestAPIAddIssueLabelsWithLabelNames (t * testing.T ) {
118
118
assert .NoError (t , unittest .LoadFixtures ())
119
119
120
- repo := unittest .AssertExistsAndLoadBean (t , & repo_model.Repository {ID : 1 })
121
- issue := unittest .AssertExistsAndLoadBean (t , & issues_model.Issue {RepoID : repo .ID })
120
+ repo := unittest .AssertExistsAndLoadBean (t , & repo_model.Repository {ID : 3 })
121
+ issue := unittest .AssertExistsAndLoadBean (t , & issues_model.Issue {ID : 6 , RepoID : repo .ID })
122
122
owner := unittest .AssertExistsAndLoadBean (t , & user_model.User {ID : repo .OwnerID })
123
+ repoLabel := unittest .AssertExistsAndLoadBean (t , & issues_model.Label {ID : 10 , RepoID : repo .ID })
124
+ orgLabel := unittest .AssertExistsAndLoadBean (t , & issues_model.Label {ID : 4 , OrgID : owner .ID })
123
125
124
- session := loginUser (t , owner .Name )
125
- token := getTokenForLoggedInUser (t , session , auth_model .AccessTokenScopeWriteIssue )
126
- urlStr := fmt .Sprintf ("/api/v1/repos/%s/%s/issues/%d/labels" ,
127
- repo .OwnerName , repo .Name , issue .Index )
126
+ user1Session := loginUser (t , "user1" )
127
+ token := getTokenForLoggedInUser (t , user1Session , auth_model .AccessTokenScopeWriteIssue )
128
+
129
+ // add the org label and the repo label to the issue
130
+ urlStr := fmt .Sprintf ("/api/v1/repos/%s/%s/issues/%d/labels" , owner .Name , repo .Name , issue .Index )
128
131
req := NewRequestWithJSON (t , "POST" , urlStr , & api.IssueLabelsOption {
129
- Labels : []any {"label1" , "label2" },
132
+ Labels : []any {repoLabel . Name , orgLabel . Name },
130
133
}).AddTokenAuth (token )
131
134
resp := MakeRequest (t , req , http .StatusOK )
132
135
var apiLabels []* api.Label
133
136
DecodeJSON (t , resp , & apiLabels )
134
137
assert .Len (t , apiLabels , unittest .GetCount (t , & issues_model.IssueLabel {IssueID : issue .ID }))
135
-
136
138
var apiLabelNames []string
137
139
for _ , label := range apiLabels {
138
140
apiLabelNames = append (apiLabelNames , label .Name )
139
141
}
140
- assert .ElementsMatch (t , apiLabelNames , []string {"label1" , "label2" })
142
+ assert .ElementsMatch (t , apiLabelNames , []string {repoLabel .Name , orgLabel .Name })
143
+
144
+ // delete labels
145
+ req = NewRequest (t , "DELETE" , urlStr ).AddTokenAuth (token )
146
+ MakeRequest (t , req , http .StatusNoContent )
141
147
}
142
148
143
149
func TestAPIReplaceIssueLabels (t * testing.T ) {
0 commit comments