summaryrefslogtreecommitdiffstats
path: root/integrations/api_pull_test.go
diff options
context:
space:
mode:
Diffstat (limited to 'integrations/api_pull_test.go')
-rw-r--r--integrations/api_pull_test.go26
1 files changed, 26 insertions, 0 deletions
diff --git a/integrations/api_pull_test.go b/integrations/api_pull_test.go
index b9bab920e1..e56b91d8b9 100644
--- a/integrations/api_pull_test.go
+++ b/integrations/api_pull_test.go
@@ -5,10 +5,13 @@
package integrations
import (
+ "fmt"
"net/http"
"testing"
"code.gitea.io/gitea/models"
+ "code.gitea.io/gitea/modules/auth"
+ "code.gitea.io/gitea/modules/setting"
api "code.gitea.io/sdk/gitea"
"github.com/stretchr/testify/assert"
@@ -28,3 +31,26 @@ func TestAPIViewPulls(t *testing.T) {
expectedLen := models.GetCount(t, &models.Issue{RepoID: repo.ID}, models.Cond("is_pull = ?", true))
assert.Len(t, pulls, expectedLen)
}
+
+// TestAPIMergePullWIP ensures that we can't merge a WIP pull request
+func TestAPIMergePullWIP(t *testing.T) {
+ prepareTestEnv(t)
+ repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+ pr := models.AssertExistsAndLoadBean(t, &models.PullRequest{Status: models.PullRequestStatusMergeable}, models.Cond("has_merged = ?", false)).(*models.PullRequest)
+ pr.LoadIssue()
+ pr.Issue.ChangeTitle(owner, setting.Repository.PullRequest.WorkInProgressPrefixes[0]+" "+pr.Issue.Title)
+
+ // force reload
+ pr.LoadAttributes()
+
+ assert.Contains(t, pr.Issue.Title, setting.Repository.PullRequest.WorkInProgressPrefixes[0])
+
+ session := loginUser(t, owner.Name)
+ req := NewRequestWithJSON(t, http.MethodPost, fmt.Sprintf("/api/v1/repos/%s/%s/pulls/%d/merge", owner.Name, repo.Name, pr.Index), &auth.MergePullRequestForm{
+ MergeMessageField: pr.Issue.Title,
+ Do: string(models.MergeStyleMerge),
+ })
+
+ session.MakeRequest(t, req, http.StatusMethodNotAllowed)
+}