You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

37 lines
1.3 KiB

  1. // Copyright 2017 The Gitea Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package integrations
  5. import (
  6. "net/http"
  7. "testing"
  8. "code.gitea.io/gitea/models"
  9. api "code.gitea.io/sdk/gitea"
  10. "github.com/stretchr/testify/assert"
  11. )
  12. func TestAPIListComments(t *testing.T) {
  13. prepareTestEnv(t)
  14. comment := models.AssertExistsAndLoadBean(t, &models.Comment{},
  15. models.Cond("type = ?", models.CommentTypeComment)).(*models.Comment)
  16. issue := models.AssertExistsAndLoadBean(t, &models.Issue{ID: comment.IssueID}).(*models.Issue)
  17. repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: issue.RepoID}).(*models.Repository)
  18. repoOwner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
  19. session := loginUser(t, repoOwner.Name)
  20. req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues/%d/comments",
  21. repoOwner.Name, repo.Name, issue.Index)
  22. resp := session.MakeRequest(t, req)
  23. assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
  24. var comments []*api.Comment
  25. DecodeJSON(t, resp, &comments)
  26. expectedCount := models.GetCount(t, &models.Comment{IssueID: issue.ID},
  27. models.Cond("type = ?", models.CommentTypeComment))
  28. assert.EqualValues(t, expectedCount, len(comments))
  29. }