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

api_issue_test.go 1.9KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. "fmt"
  11. "github.com/stretchr/testify/assert"
  12. )
  13. func TestAPIListIssues(t *testing.T) {
  14. prepareTestEnv(t)
  15. repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
  16. owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
  17. session := loginUser(t, owner.Name)
  18. req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues?state=all",
  19. owner.Name, repo.Name)
  20. resp := session.MakeRequest(t, req, http.StatusOK)
  21. var apiIssues []*api.Issue
  22. DecodeJSON(t, resp, &apiIssues)
  23. assert.Len(t, apiIssues, models.GetCount(t, &models.Issue{RepoID: repo.ID}))
  24. for _, apiIssue := range apiIssues {
  25. models.AssertExistsAndLoadBean(t, &models.Issue{ID: apiIssue.ID, RepoID: repo.ID})
  26. }
  27. }
  28. func TestAPICreateIssue(t *testing.T) {
  29. prepareTestEnv(t)
  30. const body, title = "apiTestBody", "apiTestTitle"
  31. repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
  32. owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
  33. session := loginUser(t, owner.Name)
  34. urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues?state=all", owner.Name, repo.Name)
  35. req := NewRequestWithJSON(t, "POST", urlStr, &api.CreateIssueOption{
  36. Body: body,
  37. Title: title,
  38. Assignee: owner.Name,
  39. })
  40. resp := session.MakeRequest(t, req, http.StatusCreated)
  41. var apiIssue api.Issue
  42. DecodeJSON(t, resp, &apiIssue)
  43. assert.Equal(t, apiIssue.Body, body)
  44. assert.Equal(t, apiIssue.Title, title)
  45. models.AssertExistsAndLoadBean(t, &models.Issue{
  46. RepoID: repo.ID,
  47. AssigneeID: owner.ID,
  48. Content: body,
  49. Title: title,
  50. })
  51. }