summaryrefslogtreecommitdiffstats
path: root/integrations/api_repo_test.go
diff options
context:
space:
mode:
authorEthan Koenig <etk39@cornell.edu>2017-07-10 07:07:39 -0400
committerLauris BH <lauris@nix.lv>2017-07-10 14:07:39 +0300
commit8f1d62ad3b038186320cd40c99165b23a7f0f05c (patch)
tree75555a077c31eec2bb2ad601687802f11175b577 /integrations/api_repo_test.go
parentc016d487357a6bc46d34be1a057f1a50abfeba57 (diff)
downloadgitea-8f1d62ad3b038186320cd40c99165b23a7f0f05c.tar.gz
gitea-8f1d62ad3b038186320cd40c99165b23a7f0f05c.zip
Fix GET /users/:username/repos endpoint (#2125)
Diffstat (limited to 'integrations/api_repo_test.go')
-rw-r--r--integrations/api_repo_test.go37
1 files changed, 33 insertions, 4 deletions
diff --git a/integrations/api_repo_test.go b/integrations/api_repo_test.go
index 180105d4c0..8f17fce391 100644
--- a/integrations/api_repo_test.go
+++ b/integrations/api_repo_test.go
@@ -6,19 +6,48 @@ package integrations
import (
"net/http"
+ "strings"
"testing"
+
+ "code.gitea.io/gitea/models"
+ api "code.gitea.io/sdk/gitea"
+
+ "github.com/stretchr/testify/assert"
)
func TestAPIUserReposNotLogin(t *testing.T) {
prepareTestEnv(t)
+ user := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User)
+
+ req := NewRequestf(t, "GET", "/api/v1/users/%s/repos", user.Name)
+ resp := MakeRequest(t, req, http.StatusOK)
- req := NewRequest(t, "GET", "/api/v1/users/user2/repos")
- MakeRequest(t, req, http.StatusOK)
+ var apiRepos []api.Repository
+ DecodeJSON(t, resp, &apiRepos)
+ expectedLen := models.GetCount(t, models.Repository{OwnerID: user.ID},
+ models.Cond("is_private = ?", false))
+ assert.Len(t, apiRepos, expectedLen)
+ for _, repo := range apiRepos {
+ assert.EqualValues(t, user.ID, repo.Owner.ID)
+ assert.False(t, repo.Private)
+ }
+}
+
+type searchResponseBody struct {
+ ok bool
+ data []api.Repository
}
func TestAPISearchRepoNotLogin(t *testing.T) {
prepareTestEnv(t)
+ const keyword = "test"
+
+ req := NewRequestf(t, "GET", "/api/v1/repos/search?q=%s", keyword)
+ resp := MakeRequest(t, req, http.StatusOK)
- req := NewRequest(t, "GET", "/api/v1/repos/search?q=Test")
- MakeRequest(t, req, http.StatusOK)
+ var body searchResponseBody
+ DecodeJSON(t, resp, &body)
+ for _, repo := range body.data {
+ assert.True(t, strings.Contains(repo.Name, keyword))
+ }
}