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

api_comment_test.go 1.3 kB

123456789101112131415161718192021222324252627282930313233343536373839
  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. "fmt"
  7. "net/http"
  8. "testing"
  9. "code.gitea.io/gitea/models"
  10. api "code.gitea.io/sdk/gitea"
  11. "github.com/stretchr/testify/assert"
  12. )
  13. func TestAPIListComments(t *testing.T) {
  14. prepareTestEnv(t)
  15. comment := models.AssertExistsAndLoadBean(t, &models.Comment{},
  16. models.Cond("type = ?", models.CommentTypeComment)).(*models.Comment)
  17. issue := models.AssertExistsAndLoadBean(t, &models.Issue{ID: comment.IssueID}).(*models.Issue)
  18. repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: issue.RepoID}).(*models.Repository)
  19. repoOwner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
  20. session := loginUser(t, repoOwner.Name)
  21. requestUrl := fmt.Sprintf("/api/v1/repos/%s/%s/issues/%d/comments",
  22. repoOwner.Name, repo.Name, issue.Index)
  23. req := NewRequest(t, "GET", requestUrl)
  24. resp := session.MakeRequest(t, req)
  25. assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
  26. var comments []*api.Comment
  27. DecodeJSON(t, resp, &comments)
  28. expectedCount := models.GetCount(t, &models.Comment{IssueID: issue.ID},
  29. models.Cond("type = ?", models.CommentTypeComment))
  30. assert.EqualValues(t, expectedCount, len(comments))
  31. }