loading up the forgejo repo on tangled to test page performance
at forgejo 483 lines 20 kB view raw
1// Copyright 2017 The Gitea Authors. All rights reserved. 2// SPDX-License-Identifier: MIT 3 4package integration 5 6import ( 7 "fmt" 8 "net/http" 9 "net/url" 10 "testing" 11 "time" 12 13 auth_model "forgejo.org/models/auth" 14 "forgejo.org/models/db" 15 issues_model "forgejo.org/models/issues" 16 repo_model "forgejo.org/models/repo" 17 "forgejo.org/models/unittest" 18 user_model "forgejo.org/models/user" 19 "forgejo.org/modules/references" 20 api "forgejo.org/modules/structs" 21 "forgejo.org/services/convert" 22 "forgejo.org/tests" 23 24 "github.com/stretchr/testify/assert" 25 "github.com/stretchr/testify/require" 26) 27 28const IssueIDNotExist = 10000 29 30func TestAPIListRepoComments(t *testing.T) { 31 defer tests.PrepareTestEnv(t)() 32 33 comment := unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{}, 34 unittest.Cond("type = ?", issues_model.CommentTypeComment)) 35 issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: comment.IssueID}) 36 repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue.RepoID}) 37 repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) 38 39 link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/issues/comments", repoOwner.Name, repo.Name)) 40 req := NewRequest(t, "GET", link.String()) 41 resp := MakeRequest(t, req, http.StatusOK) 42 43 var apiComments []*api.Comment 44 DecodeJSON(t, resp, &apiComments) 45 assert.Len(t, apiComments, 3) 46 for _, apiComment := range apiComments { 47 c := &issues_model.Comment{ID: apiComment.ID} 48 unittest.AssertExistsAndLoadBean(t, c, 49 unittest.Cond("type = ?", issues_model.CommentTypeComment)) 50 unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: c.IssueID, RepoID: repo.ID}) 51 } 52 53 // test before and since filters 54 query := url.Values{} 55 before := "2000-01-01T00:00:11+00:00" // unix: 946684811 56 since := "2000-01-01T00:00:12+00:00" // unix: 946684812 57 query.Add("before", before) 58 link.RawQuery = query.Encode() 59 req = NewRequest(t, "GET", link.String()) 60 resp = MakeRequest(t, req, http.StatusOK) 61 DecodeJSON(t, resp, &apiComments) 62 assert.Len(t, apiComments, 1) 63 assert.EqualValues(t, 2, apiComments[0].ID) 64 65 query.Del("before") 66 query.Add("since", since) 67 link.RawQuery = query.Encode() 68 req = NewRequest(t, "GET", link.String()) 69 resp = MakeRequest(t, req, http.StatusOK) 70 DecodeJSON(t, resp, &apiComments) 71 assert.Len(t, apiComments, 2) 72 assert.EqualValues(t, 3, apiComments[0].ID) 73} 74 75func TestAPIListIssueComments(t *testing.T) { 76 defer tests.PrepareTestEnv(t)() 77 78 comment := unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{}, 79 unittest.Cond("type = ?", issues_model.CommentTypeComment)) 80 issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: comment.IssueID}) 81 repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue.RepoID}) 82 repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) 83 84 token := getUserToken(t, repoOwner.Name, auth_model.AccessTokenScopeReadIssue) 85 req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues/%d/comments", repoOwner.Name, repo.Name, issue.Index). 86 AddTokenAuth(token) 87 resp := MakeRequest(t, req, http.StatusOK) 88 89 var comments []*api.Comment 90 DecodeJSON(t, resp, &comments) 91 expectedCount := unittest.GetCount(t, &issues_model.Comment{IssueID: issue.ID}, 92 unittest.Cond("type = ?", issues_model.CommentTypeComment)) 93 assert.Len(t, comments, expectedCount) 94 95 req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues/%d/comments", repoOwner.Name, repo.Name, IssueIDNotExist). 96 AddTokenAuth(token) 97 MakeRequest(t, req, http.StatusNotFound) 98} 99 100func TestAPICreateComment(t *testing.T) { 101 defer tests.PrepareTestEnv(t)() 102 const commentBody = "Comment body" 103 104 issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{}) 105 repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue.RepoID}) 106 repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) 107 108 token := getUserToken(t, repoOwner.Name, auth_model.AccessTokenScopeWriteIssue) 109 urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/comments", 110 repoOwner.Name, repo.Name, issue.Index) 111 req := NewRequestWithValues(t, "POST", urlStr, map[string]string{ 112 "body": commentBody, 113 }).AddTokenAuth(token) 114 resp := MakeRequest(t, req, http.StatusCreated) 115 116 var updatedComment api.Comment 117 DecodeJSON(t, resp, &updatedComment) 118 assert.Equal(t, commentBody, updatedComment.Body) 119 unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: updatedComment.ID, IssueID: issue.ID, Content: commentBody}) 120 121 urlStr = fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/comments", 122 repoOwner.Name, repo.Name, IssueIDNotExist) 123 req = NewRequestWithValues(t, "POST", urlStr, map[string]string{ 124 "body": commentBody, 125 }).AddTokenAuth(token) 126 MakeRequest(t, req, http.StatusNotFound) 127} 128 129func TestAPICreateCommentAutoDate(t *testing.T) { 130 defer tests.PrepareTestEnv(t)() 131 132 issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{}) 133 repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue.RepoID}) 134 repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) 135 token := getUserToken(t, repoOwner.Name, auth_model.AccessTokenScopeWriteIssue) 136 137 urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/comments", 138 repoOwner.Name, repo.Name, issue.Index) 139 const commentBody = "Comment body" 140 141 t.Run("WithAutoDate", func(t *testing.T) { 142 defer tests.PrintCurrentTest(t)() 143 144 req := NewRequestWithValues(t, "POST", urlStr, map[string]string{ 145 "body": commentBody, 146 }).AddTokenAuth(token) 147 resp := MakeRequest(t, req, http.StatusCreated) 148 var updatedComment api.Comment 149 DecodeJSON(t, resp, &updatedComment) 150 151 // the execution of the API call supposedly lasted less than one minute 152 updatedSince := time.Since(updatedComment.Updated) 153 assert.LessOrEqual(t, updatedSince, time.Minute) 154 155 commentAfter := unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: updatedComment.ID, IssueID: issue.ID, Content: commentBody}) 156 updatedSince = time.Since(commentAfter.UpdatedUnix.AsTime()) 157 assert.LessOrEqual(t, updatedSince, time.Minute) 158 }) 159 160 t.Run("WithUpdateDate", func(t *testing.T) { 161 defer tests.PrintCurrentTest(t)() 162 163 updatedAt := time.Now().Add(-time.Hour).Truncate(time.Second) 164 165 req := NewRequestWithJSON(t, "POST", urlStr, &api.CreateIssueCommentOption{ 166 Body: commentBody, 167 Updated: &updatedAt, 168 }).AddTokenAuth(token) 169 resp := MakeRequest(t, req, http.StatusCreated) 170 var updatedComment api.Comment 171 DecodeJSON(t, resp, &updatedComment) 172 173 // dates will be converted into the same tz, in order to compare them 174 utcTZ, _ := time.LoadLocation("UTC") 175 assert.Equal(t, updatedAt.In(utcTZ), updatedComment.Updated.In(utcTZ)) 176 commentAfter := unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: updatedComment.ID, IssueID: issue.ID, Content: commentBody}) 177 assert.Equal(t, updatedAt.In(utcTZ), commentAfter.UpdatedUnix.AsTime().In(utcTZ)) 178 }) 179} 180 181func TestAPICommentXRefAutoDate(t *testing.T) { 182 defer tests.PrepareTestEnv(t)() 183 184 issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 1}) 185 repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue.RepoID}) 186 repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) 187 token := getUserToken(t, repoOwner.Name, auth_model.AccessTokenScopeWriteIssue) 188 189 t.Run("WithAutoDate", func(t *testing.T) { 190 defer tests.PrintCurrentTest(t)() 191 192 // Create a comment mentioning issue #2 and check that a xref comment was added 193 // in issue #2 194 urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/comments", 195 repoOwner.Name, repo.Name, issue.Index) 196 197 commentBody := "mention #2" 198 req := NewRequestWithJSON(t, "POST", urlStr, &api.CreateIssueCommentOption{ 199 Body: commentBody, 200 }).AddTokenAuth(token) 201 resp := MakeRequest(t, req, http.StatusCreated) 202 var createdComment api.Comment 203 DecodeJSON(t, resp, &createdComment) 204 205 ref := unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{IssueID: 2, RefIssueID: 1, RefCommentID: createdComment.ID}) 206 assert.Equal(t, issues_model.CommentTypeCommentRef, ref.Type) 207 assert.Equal(t, references.XRefActionNone, ref.RefAction) 208 // the execution of the API call supposedly lasted less than one minute 209 updatedSince := time.Since(ref.UpdatedUnix.AsTime()) 210 assert.LessOrEqual(t, updatedSince, time.Minute) 211 212 // Remove the mention to issue #2 and check that the xref was neutered 213 urlStr = fmt.Sprintf("/api/v1/repos/%s/%s/issues/comments/%d", 214 repoOwner.Name, repo.Name, createdComment.ID) 215 216 newCommentBody := "no mention" 217 req = NewRequestWithJSON(t, "PATCH", urlStr, &api.EditIssueCommentOption{ 218 Body: newCommentBody, 219 }).AddTokenAuth(token) 220 resp = MakeRequest(t, req, http.StatusOK) 221 var updatedComment api.Comment 222 DecodeJSON(t, resp, &updatedComment) 223 224 ref = unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{IssueID: 2, RefIssueID: 1, RefCommentID: updatedComment.ID}) 225 assert.Equal(t, issues_model.CommentTypeCommentRef, ref.Type) 226 assert.Equal(t, references.XRefActionNeutered, ref.RefAction) 227 // the execution of the API call supposedly lasted less than one minute 228 updatedSince = time.Since(ref.UpdatedUnix.AsTime()) 229 assert.LessOrEqual(t, updatedSince, time.Minute) 230 }) 231 232 t.Run("WithUpdateDate", func(t *testing.T) { 233 defer tests.PrintCurrentTest(t)() 234 235 // dates will be converted into the same tz, in order to compare them 236 utcTZ, _ := time.LoadLocation("UTC") 237 238 // Create a comment mentioning issue #2 and check that a xref comment was added 239 // in issue #2 240 urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/comments", 241 repoOwner.Name, repo.Name, issue.Index) 242 243 commentBody := "re-mention #2" 244 updatedAt := time.Now().Add(-time.Hour).Truncate(time.Second) 245 req := NewRequestWithJSON(t, "POST", urlStr, &api.CreateIssueCommentOption{ 246 Body: commentBody, 247 Updated: &updatedAt, 248 }).AddTokenAuth(token) 249 resp := MakeRequest(t, req, http.StatusCreated) 250 var createdComment api.Comment 251 DecodeJSON(t, resp, &createdComment) 252 253 ref := unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{IssueID: 2, RefIssueID: 1, RefCommentID: createdComment.ID}) 254 assert.Equal(t, issues_model.CommentTypeCommentRef, ref.Type) 255 assert.Equal(t, references.XRefActionNone, ref.RefAction) 256 assert.Equal(t, updatedAt.In(utcTZ), ref.UpdatedUnix.AsTimeInLocation(utcTZ)) 257 258 // Remove the mention to issue #2 and check that the xref was neutered 259 urlStr = fmt.Sprintf("/api/v1/repos/%s/%s/issues/comments/%d", 260 repoOwner.Name, repo.Name, createdComment.ID) 261 262 newCommentBody := "no mention" 263 updatedAt = time.Now().Add(-time.Hour).Truncate(time.Second) 264 req = NewRequestWithJSON(t, "PATCH", urlStr, &api.EditIssueCommentOption{ 265 Body: newCommentBody, 266 Updated: &updatedAt, 267 }).AddTokenAuth(token) 268 resp = MakeRequest(t, req, http.StatusOK) 269 var updatedComment api.Comment 270 DecodeJSON(t, resp, &updatedComment) 271 272 ref = unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{IssueID: 2, RefIssueID: 1, RefCommentID: updatedComment.ID}) 273 assert.Equal(t, issues_model.CommentTypeCommentRef, ref.Type) 274 assert.Equal(t, references.XRefActionNeutered, ref.RefAction) 275 assert.Equal(t, updatedAt.In(utcTZ), ref.UpdatedUnix.AsTimeInLocation(utcTZ)) 276 }) 277} 278 279func TestAPIGetComment(t *testing.T) { 280 defer tests.PrepareTestEnv(t)() 281 282 comment := unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: 2}) 283 require.NoError(t, comment.LoadIssue(db.DefaultContext)) 284 repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: comment.Issue.RepoID}) 285 repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) 286 287 token := getUserToken(t, repoOwner.Name, auth_model.AccessTokenScopeReadIssue) 288 req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues/comments/%d", repoOwner.Name, repo.Name, comment.ID) 289 MakeRequest(t, req, http.StatusOK) 290 req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues/comments/%d", repoOwner.Name, repo.Name, comment.ID). 291 AddTokenAuth(token) 292 resp := MakeRequest(t, req, http.StatusOK) 293 294 var apiComment api.Comment 295 DecodeJSON(t, resp, &apiComment) 296 297 require.NoError(t, comment.LoadPoster(db.DefaultContext)) 298 expect := convert.ToAPIComment(db.DefaultContext, repo, comment) 299 300 assert.Equal(t, expect.ID, apiComment.ID) 301 assert.Equal(t, expect.Poster.FullName, apiComment.Poster.FullName) 302 assert.Equal(t, expect.Body, apiComment.Body) 303 assert.Equal(t, expect.Created.Unix(), apiComment.Created.Unix()) 304} 305 306func TestAPIGetSystemUserComment(t *testing.T) { 307 defer tests.PrepareTestEnv(t)() 308 309 issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{}) 310 repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue.RepoID}) 311 repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) 312 313 for _, systemUser := range []*user_model.User{ 314 user_model.NewGhostUser(), 315 user_model.NewActionsUser(), 316 } { 317 body := fmt.Sprintf("Hello %s", systemUser.Name) 318 comment, err := issues_model.CreateComment(db.DefaultContext, &issues_model.CreateCommentOptions{ 319 Type: issues_model.CommentTypeComment, 320 Doer: systemUser, 321 Repo: repo, 322 Issue: issue, 323 Content: body, 324 }) 325 require.NoError(t, err) 326 327 req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues/comments/%d", repoOwner.Name, repo.Name, comment.ID) 328 resp := MakeRequest(t, req, http.StatusOK) 329 330 var apiComment api.Comment 331 DecodeJSON(t, resp, &apiComment) 332 333 if assert.NotNil(t, apiComment.Poster) { 334 if assert.Equal(t, systemUser.ID, apiComment.Poster.ID) { 335 require.NoError(t, comment.LoadPoster(db.DefaultContext)) 336 assert.Equal(t, systemUser.Name, apiComment.Poster.UserName) 337 } 338 } 339 assert.Equal(t, body, apiComment.Body) 340 } 341} 342 343func TestAPIEditComment(t *testing.T) { 344 defer tests.PrepareTestEnv(t)() 345 const newCommentBody = "This is the new comment body" 346 347 comment := unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: 8}, 348 unittest.Cond("type = ?", issues_model.CommentTypeComment)) 349 issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: comment.IssueID}) 350 repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue.RepoID}) 351 repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) 352 353 t.Run("UnrelatedCommentID", func(t *testing.T) { 354 // Using the ID of a comment that does not belong to the repository must fail 355 repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4}) 356 repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) 357 token := getUserToken(t, repoOwner.Name, auth_model.AccessTokenScopeWriteIssue) 358 urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/comments/%d", 359 repoOwner.Name, repo.Name, comment.ID) 360 req := NewRequestWithValues(t, "PATCH", urlStr, map[string]string{ 361 "body": newCommentBody, 362 }).AddTokenAuth(token) 363 MakeRequest(t, req, http.StatusNotFound) 364 }) 365 366 token := getUserToken(t, repoOwner.Name, auth_model.AccessTokenScopeWriteIssue) 367 urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/comments/%d", 368 repoOwner.Name, repo.Name, comment.ID) 369 req := NewRequestWithValues(t, "PATCH", urlStr, map[string]string{ 370 "body": newCommentBody, 371 }).AddTokenAuth(token) 372 resp := MakeRequest(t, req, http.StatusOK) 373 374 var updatedComment api.Comment 375 DecodeJSON(t, resp, &updatedComment) 376 assert.Equal(t, comment.ID, updatedComment.ID) 377 assert.Equal(t, newCommentBody, updatedComment.Body) 378 unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: comment.ID, IssueID: issue.ID, Content: newCommentBody}) 379} 380 381func TestAPIEditCommentWithDate(t *testing.T) { 382 defer tests.PrepareTestEnv(t)() 383 384 comment := unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{}, 385 unittest.Cond("type = ?", issues_model.CommentTypeComment)) 386 issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: comment.IssueID}) 387 repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue.RepoID}) 388 repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) 389 token := getUserToken(t, repoOwner.Name, auth_model.AccessTokenScopeWriteIssue) 390 391 urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues/comments/%d", 392 repoOwner.Name, repo.Name, comment.ID) 393 const newCommentBody = "This is the new comment body" 394 395 t.Run("WithAutoDate", func(t *testing.T) { 396 defer tests.PrintCurrentTest(t)() 397 398 req := NewRequestWithValues(t, "PATCH", urlStr, map[string]string{ 399 "body": newCommentBody, 400 }).AddTokenAuth(token) 401 resp := MakeRequest(t, req, http.StatusOK) 402 var updatedComment api.Comment 403 DecodeJSON(t, resp, &updatedComment) 404 405 // the execution of the API call supposedly lasted less than one minute 406 updatedSince := time.Since(updatedComment.Updated) 407 assert.LessOrEqual(t, updatedSince, time.Minute) 408 409 commentAfter := unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: comment.ID, IssueID: issue.ID, Content: newCommentBody}) 410 updatedSince = time.Since(commentAfter.UpdatedUnix.AsTime()) 411 assert.LessOrEqual(t, updatedSince, time.Minute) 412 }) 413 414 t.Run("WithUpdateDate", func(t *testing.T) { 415 defer tests.PrintCurrentTest(t)() 416 417 updatedAt := time.Now().Add(-time.Hour).Truncate(time.Second) 418 419 req := NewRequestWithJSON(t, "PATCH", urlStr, &api.EditIssueCommentOption{ 420 Body: newCommentBody, 421 Updated: &updatedAt, 422 }).AddTokenAuth(token) 423 resp := MakeRequest(t, req, http.StatusOK) 424 var updatedComment api.Comment 425 DecodeJSON(t, resp, &updatedComment) 426 427 // dates will be converted into the same tz, in order to compare them 428 utcTZ, _ := time.LoadLocation("UTC") 429 assert.Equal(t, updatedAt.In(utcTZ), updatedComment.Updated.In(utcTZ)) 430 commentAfter := unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: comment.ID, IssueID: issue.ID, Content: newCommentBody}) 431 assert.Equal(t, updatedAt.In(utcTZ), commentAfter.UpdatedUnix.AsTime().In(utcTZ)) 432 }) 433} 434 435func TestAPIDeleteComment(t *testing.T) { 436 defer tests.PrepareTestEnv(t)() 437 438 comment := unittest.AssertExistsAndLoadBean(t, &issues_model.Comment{ID: 8}, 439 unittest.Cond("type = ?", issues_model.CommentTypeComment)) 440 issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: comment.IssueID}) 441 repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue.RepoID}) 442 repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) 443 444 t.Run("UnrelatedCommentID", func(t *testing.T) { 445 // Using the ID of a comment that does not belong to the repository must fail 446 repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: 4}) 447 repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) 448 token := getUserToken(t, repoOwner.Name, auth_model.AccessTokenScopeWriteIssue) 449 req := NewRequestf(t, "DELETE", "/api/v1/repos/%s/%s/issues/comments/%d", repoOwner.Name, repo.Name, comment.ID). 450 AddTokenAuth(token) 451 MakeRequest(t, req, http.StatusNotFound) 452 }) 453 454 token := getUserToken(t, repoOwner.Name, auth_model.AccessTokenScopeWriteIssue) 455 req := NewRequestf(t, "DELETE", "/api/v1/repos/%s/%s/issues/comments/%d", repoOwner.Name, repo.Name, comment.ID). 456 AddTokenAuth(token) 457 MakeRequest(t, req, http.StatusNoContent) 458 459 unittest.AssertNotExistsBean(t, &issues_model.Comment{ID: comment.ID}) 460} 461 462func TestAPIListIssueTimeline(t *testing.T) { 463 defer tests.PrepareTestEnv(t)() 464 465 // load comment 466 issue := unittest.AssertExistsAndLoadBean(t, &issues_model.Issue{ID: 1}) 467 repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{ID: issue.RepoID}) 468 repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) 469 470 // make request 471 req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues/%d/timeline", repoOwner.Name, repo.Name, issue.Index) 472 resp := MakeRequest(t, req, http.StatusOK) 473 474 // check if lens of list returned by API and 475 // lists extracted directly from DB are the same 476 var comments []*api.TimelineComment 477 DecodeJSON(t, resp, &comments) 478 expectedCount := unittest.GetCount(t, &issues_model.Comment{IssueID: issue.ID}) 479 assert.Len(t, comments, expectedCount) 480 481 req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues/%d/timeline", repoOwner.Name, repo.Name, IssueIDNotExist) 482 MakeRequest(t, req, http.StatusNotFound) 483}