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.

47 lines
1.5 KiB

  1. // Copyright 2020 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. "code.gitea.io/gitea/modules/structs"
  11. "github.com/stretchr/testify/assert"
  12. )
  13. func TestAPIIssuesMilestone(t *testing.T) {
  14. defer prepareTestEnv(t)()
  15. milestone := models.AssertExistsAndLoadBean(t, &models.Milestone{ID: 1}).(*models.Milestone)
  16. repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: milestone.RepoID}).(*models.Repository)
  17. owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
  18. assert.Equal(t, int64(1), int64(milestone.NumIssues))
  19. assert.Equal(t, structs.StateOpen, milestone.State())
  20. session := loginUser(t, owner.Name)
  21. token := getTokenForLoggedInUser(t, session)
  22. // update values of issue
  23. milestoneState := "closed"
  24. urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/milestones/%d?token=%s", owner.Name, repo.Name, milestone.ID, token)
  25. req := NewRequestWithJSON(t, "PATCH", urlStr, structs.EditMilestoneOption{
  26. State: &milestoneState,
  27. })
  28. resp := session.MakeRequest(t, req, http.StatusOK)
  29. var apiMilestone structs.Milestone
  30. DecodeJSON(t, resp, &apiMilestone)
  31. assert.EqualValues(t, "closed", apiMilestone.State)
  32. req = NewRequest(t, "GET", urlStr)
  33. resp = session.MakeRequest(t, req, http.StatusOK)
  34. var apiMilestone2 structs.Milestone
  35. DecodeJSON(t, resp, &apiMilestone2)
  36. assert.EqualValues(t, "closed", apiMilestone2.State)
  37. }