diff options
author | 6543 <6543@obermui.de> | 2021-06-17 00:33:37 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-06-16 18:33:37 -0400 |
commit | 0e081ff0ce61227d5f34f1d7f8213d9f407f1f3d (patch) | |
tree | ff3bf587cf5af0cea1226b2fa219b27a3336594c /integrations/api_issue_test.go | |
parent | ffbf35b7e9e2ea65525229f2c7d5a076c98e66ba (diff) | |
download | gitea-0e081ff0ce61227d5f34f1d7f8213d9f407f1f3d.tar.gz gitea-0e081ff0ce61227d5f34f1d7f8213d9f407f1f3d.zip |
[API] ListIssues add more filters (#16174)
* [API] ListIssues add more filters:
optional filter repo issues by:
- since
- before
- created_by
- assigned_by
- mentioned_by
* Add Tests
* Update routers/api/v1/repo/issue.go
Co-authored-by: Lanre Adelowo <adelowomailbox@gmail.com>
* Apply suggestions from code review
Co-authored-by: Lanre Adelowo <adelowomailbox@gmail.com>
Co-authored-by: techknowlogick <techknowlogick@gitea.io>
Diffstat (limited to 'integrations/api_issue_test.go')
-rw-r--r-- | integrations/api_issue_test.go | 32 |
1 files changed, 26 insertions, 6 deletions
diff --git a/integrations/api_issue_test.go b/integrations/api_issue_test.go index 109135b634..604e6d6381 100644 --- a/integrations/api_issue_test.go +++ b/integrations/api_issue_test.go @@ -25,9 +25,10 @@ func TestAPIListIssues(t *testing.T) { session := loginUser(t, owner.Name) token := getTokenForLoggedInUser(t, session) - req := NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues?state=all&token=%s", - owner.Name, repo.Name, token) - resp := session.MakeRequest(t, req, http.StatusOK) + link, _ := url.Parse(fmt.Sprintf("/api/v1/repos/%s/%s/issues", owner.Name, repo.Name)) + + link.RawQuery = url.Values{"token": {token}, "state": {"all"}}.Encode() + resp := session.MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK) var apiIssues []*api.Issue DecodeJSON(t, resp, &apiIssues) assert.Len(t, apiIssues, models.GetCount(t, &models.Issue{RepoID: repo.ID})) @@ -36,15 +37,34 @@ func TestAPIListIssues(t *testing.T) { } // test milestone filter - req = NewRequestf(t, "GET", "/api/v1/repos/%s/%s/issues?state=all&type=all&milestones=ignore,milestone1,3,4&token=%s", - owner.Name, repo.Name, token) - resp = session.MakeRequest(t, req, http.StatusOK) + link.RawQuery = url.Values{"token": {token}, "state": {"all"}, "type": {"all"}, "milestones": {"ignore,milestone1,3,4"}}.Encode() + resp = session.MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK) DecodeJSON(t, resp, &apiIssues) if assert.Len(t, apiIssues, 2) { assert.EqualValues(t, 3, apiIssues[0].Milestone.ID) assert.EqualValues(t, 1, apiIssues[1].Milestone.ID) } + link.RawQuery = url.Values{"token": {token}, "state": {"all"}, "created_by": {"user2"}}.Encode() + resp = session.MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK) + DecodeJSON(t, resp, &apiIssues) + if assert.Len(t, apiIssues, 1) { + assert.EqualValues(t, 5, apiIssues[0].ID) + } + + link.RawQuery = url.Values{"token": {token}, "state": {"all"}, "assigned_by": {"user1"}}.Encode() + resp = session.MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK) + DecodeJSON(t, resp, &apiIssues) + if assert.Len(t, apiIssues, 1) { + assert.EqualValues(t, 1, apiIssues[0].ID) + } + + link.RawQuery = url.Values{"token": {token}, "state": {"all"}, "mentioned_by": {"user4"}}.Encode() + resp = session.MakeRequest(t, NewRequest(t, "GET", link.String()), http.StatusOK) + DecodeJSON(t, resp, &apiIssues) + if assert.Len(t, apiIssues, 1) { + assert.EqualValues(t, 1, apiIssues[0].ID) + } } func TestAPICreateIssue(t *testing.T) { |