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