Fork to maintain patches against the official gitea for https://code.ceondo.com https://github.com/go-gitea/gitea

api_comment_test.go 1.2KB

12345678910111213141516171819202122232425262728293031323334353637
  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, http.StatusOK)
  23. var comments []*api.Comment
  24. DecodeJSON(t, resp, &comments)
  25. expectedCount := models.GetCount(t, &models.Comment{IssueID: issue.ID},
  26. models.Cond("type = ?", models.CommentTypeComment))
  27. assert.EqualValues(t, expectedCount, len(comments))
  28. }