Skip to content

Commit d8bbd9e

Browse files
author
Mura Li
committed
Add integration test for issue creating
1 parent 90f9bb1 commit d8bbd9e

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

integrations/issue_test.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package integrations
66

77
import (
88
"net/http"
9+
"path"
910
"strconv"
1011
"strings"
1112
"testing"
@@ -75,3 +76,33 @@ func TestNoLoginViewIssue(t *testing.T) {
7576
resp := MakeRequest(req)
7677
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
7778
}
79+
80+
func testNewIssue(t *testing.T, session *TestSession, user, repo, title string) {
81+
82+
req := NewRequest(t, "GET", path.Join(user, repo, "issues", "new"))
83+
resp := session.MakeRequest(t, req)
84+
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
85+
86+
htmlDoc := NewHTMLParser(t, resp.Body)
87+
link, exists := htmlDoc.doc.Find("form.ui.form").Attr("action")
88+
assert.True(t, exists, "The template has changed")
89+
req = NewRequestWithValues(t, "POST", link, map[string]string{
90+
"_csrf": htmlDoc.GetCSRF(),
91+
"title": title,
92+
})
93+
req.Header.Add("Content-Type", "application/x-www-form-urlencoded")
94+
resp = session.MakeRequest(t, req)
95+
assert.EqualValues(t, http.StatusFound, resp.HeaderCode)
96+
redirectedURL := resp.Headers["Location"]
97+
assert.NotEmpty(t, redirectedURL, "Redirected URL is not found")
98+
99+
req = NewRequest(t, "GET", redirectedURL[0])
100+
resp = session.MakeRequest(t, req)
101+
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
102+
}
103+
104+
func TestNewIssue(t *testing.T) {
105+
prepareTestEnv(t)
106+
session := loginUser(t, "user2")
107+
testNewIssue(t, session, "user2", "repo1", "Title")
108+
}

0 commit comments

Comments
 (0)