diff options
author | Lunny Xiao <xiaolunwen@gmail.com> | 2020-01-29 14:36:32 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-01-29 08:36:32 +0200 |
commit | c09e020558318feebbdce477f91c94411e8959b6 (patch) | |
tree | 49a83b33103c114c7068a33bb246e066ae1062e0 /integrations/api_issue_milestone_test.go | |
parent | f29c301040a9de42130b1b1d15f94b5869137f08 (diff) | |
download | gitea-c09e020558318feebbdce477f91c94411e8959b6.tar.gz gitea-c09e020558318feebbdce477f91c94411e8959b6.zip |
Fix milestone API state parameter unhandled (#10049)
* Fix milestone API state parameter unhandled
* Fix test
Diffstat (limited to 'integrations/api_issue_milestone_test.go')
-rw-r--r-- | integrations/api_issue_milestone_test.go | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/integrations/api_issue_milestone_test.go b/integrations/api_issue_milestone_test.go new file mode 100644 index 0000000000..35e5053cba --- /dev/null +++ b/integrations/api_issue_milestone_test.go @@ -0,0 +1,47 @@ +// Copyright 2020 The Gitea Authors. All rights reserved. +// Use of this source code is governed by a MIT-style +// license that can be found in the LICENSE file. + +package integrations + +import ( + "fmt" + "net/http" + "testing" + + "code.gitea.io/gitea/models" + "code.gitea.io/gitea/modules/structs" + + "github.com/stretchr/testify/assert" +) + +func TestAPIIssuesMilestone(t *testing.T) { + defer prepareTestEnv(t)() + + milestone := models.AssertExistsAndLoadBean(t, &models.Milestone{ID: 1}).(*models.Milestone) + repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: milestone.RepoID}).(*models.Repository) + owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User) + assert.Equal(t, int64(1), int64(milestone.NumIssues)) + assert.Equal(t, structs.StateOpen, milestone.State()) + + session := loginUser(t, owner.Name) + token := getTokenForLoggedInUser(t, session) + + // update values of issue + milestoneState := "closed" + + urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/milestones/%d?token=%s", owner.Name, repo.Name, milestone.ID, token) + req := NewRequestWithJSON(t, "PATCH", urlStr, structs.EditMilestoneOption{ + State: &milestoneState, + }) + resp := session.MakeRequest(t, req, http.StatusOK) + var apiMilestone structs.Milestone + DecodeJSON(t, resp, &apiMilestone) + assert.EqualValues(t, "closed", apiMilestone.State) + + req = NewRequest(t, "GET", urlStr) + resp = session.MakeRequest(t, req, http.StatusOK) + var apiMilestone2 structs.Milestone + DecodeJSON(t, resp, &apiMilestone2) + assert.EqualValues(t, "closed", apiMilestone2.State) +} |