From 0b3aaa61964faa85b8008b04487388cc362ab436 Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Mon, 13 Jan 2020 17:02:24 +0100 Subject: [API] Add "before" query to ListIssueComments and ListRepoIssue… (#9685) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * add "before" query to ListIssueComments and ListRepoIssueComments * Add TEST Co-authored-by: Lunny Xiao Co-authored-by: Antoine GIRARD --- integrations/api_comment_test.go | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'integrations') diff --git a/integrations/api_comment_test.go b/integrations/api_comment_test.go index d21f56aaf8..2c754272e5 100644 --- a/integrations/api_comment_test.go +++ b/integrations/api_comment_test.go @@ -7,6 +7,7 @@ package integrations import ( "fmt" "net/http" + "net/url" "testing" "code.gitea.io/gitea/models" @@ -25,18 +26,40 @@ func TestAPIListRepoComments(t *testing.T) { repoOwner := models.AssertExistsAndLoadBean(t, &models.User{ID: repo.OwnerID}).(*models.User) session := loginUser(t, repoOwner.Name) - req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues/comments", - repoOwner.Name, repo.Name) + link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/issues/comments", repoOwner.Name, repo.Name)) + req := NewRequest(t, "GET", link.String()) resp := session.MakeRequest(t, req, http.StatusOK) var apiComments []*api.Comment DecodeJSON(t, resp, &apiComments) + assert.Len(t, apiComments, 2) for _, apiComment := range apiComments { c := &models.Comment{ID: apiComment.ID} models.AssertExistsAndLoadBean(t, c, models.Cond("type = ?", models.CommentTypeComment)) models.AssertExistsAndLoadBean(t, &models.Issue{ID: c.IssueID, RepoID: repo.ID}) } + + //test before and since filters + query := url.Values{} + before := "2000-01-01T00:00:11+00:00" //unix: 946684811 + since := "2000-01-01T00:00:12+00:00" //unix: 946684812 + query.Add("before", before) + link.RawQuery = query.Encode() + req = NewRequest(t, "GET", link.String()) + resp = session.MakeRequest(t, req, http.StatusOK) + DecodeJSON(t, resp, &apiComments) + assert.Len(t, apiComments, 1) + assert.EqualValues(t, 2, apiComments[0].ID) + + query.Del("before") + query.Add("since", since) + link.RawQuery = query.Encode() + req = NewRequest(t, "GET", link.String()) + resp = session.MakeRequest(t, req, http.StatusOK) + DecodeJSON(t, resp, &apiComments) + assert.Len(t, apiComments, 1) + assert.EqualValues(t, 3, apiComments[0].ID) } func TestAPIListIssueComments(t *testing.T) { -- cgit v1.2.3