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.

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