summaryrefslogtreecommitdiffstats
path: root/integrations/api_issue_test.go
diff options
context:
space:
mode:
authorEthan Koenig <etk39@cornell.edu>2017-06-25 10:51:07 -0400
committerLunny Xiao <xiaolunwen@gmail.com>2017-06-25 22:51:07 +0800
commit735676267e48e6a57b250825e2e77edbb513e11d (patch)
treeaaa4a5bedd2ab32fd11849d37bea234097a9bd99 /integrations/api_issue_test.go
parent4c0e5670625f6d4de7e58a6338f2c10dd4d62b5b (diff)
downloadgitea-735676267e48e6a57b250825e2e77edbb513e11d.tar.gz
gitea-735676267e48e6a57b250825e2e77edbb513e11d.zip
Integration tests for issues API (#2059)
Diffstat (limited to 'integrations/api_issue_test.go')
-rw-r--r--integrations/api_issue_test.go65
1 files changed, 65 insertions, 0 deletions
diff --git a/integrations/api_issue_test.go b/integrations/api_issue_test.go
new file mode 100644
index 0000000000..63dd9459b0
--- /dev/null
+++ b/integrations/api_issue_test.go
@@ -0,0 +1,65 @@
+// Copyright 2017 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 (
+ "net/http"
+ "testing"
+
+ "code.gitea.io/gitea/models"
+ api "code.gitea.io/sdk/gitea"
+
+ "fmt"
+ "github.com/stretchr/testify/assert"
+)
+
+func TestAPIListIssues(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)
+
+ session := loginUser(t, owner.Name)
+ req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues?state=all",
+ owner.Name, repo.Name)
+ resp := session.MakeRequest(t, req)
+ assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
+ var apiIssues []*api.Issue
+ DecodeJSON(t, resp, &apiIssues)
+ assert.Len(t, apiIssues, models.GetCount(t, &models.Issue{RepoID: repo.ID}))
+ for _, apiIssue := range apiIssues {
+ models.AssertExistsAndLoadBean(t, &models.Issue{ID: apiIssue.ID, RepoID: repo.ID})
+ }
+}
+
+func TestAPICreateIssue(t *testing.T) {
+ prepareTestEnv(t)
+ const body, title = "apiTestBody", "apiTestTitle"
+
+ repo := models.AssertExistsAndLoadBean(t, &models.Repository{ID: 1}).(*models.Repository)
+ owner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User)
+
+ session := loginUser(t, owner.Name)
+
+ urlStr := fmt.Sprintf("/api/v1/repos/%s/%s/issues?state=all", owner.Name, repo.Name)
+ req := NewRequestWithJSON(t, "POST", urlStr, &api.CreateIssueOption{
+ Body: body,
+ Title: title,
+ Assignee: owner.Name,
+ })
+ resp := session.MakeRequest(t, req)
+ assert.EqualValues(t, http.StatusCreated, resp.HeaderCode)
+ var apiIssue api.Issue
+ DecodeJSON(t, resp, &apiIssue)
+ assert.Equal(t, apiIssue.Body, body)
+ assert.Equal(t, apiIssue.Title, title)
+
+ models.AssertExistsAndLoadBean(t, &models.Issue{
+ RepoID: repo.ID,
+ AssigneeID: owner.ID,
+ Content: body,
+ Title: title,
+ })
+}