2017-04-28 21:33:25 -07:00
|
|
|
// 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"
|
2017-07-10 04:07:39 -07:00
|
|
|
"strings"
|
2017-04-28 21:33:25 -07:00
|
|
|
"testing"
|
2017-07-10 04:07:39 -07:00
|
|
|
|
|
|
|
"code.gitea.io/gitea/models"
|
|
|
|
api "code.gitea.io/sdk/gitea"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
2017-04-28 21:33:25 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestAPIUserReposNotLogin(t *testing.T) {
|
2017-06-25 02:34:30 -07:00
|
|
|
prepareTestEnv(t)
|
2017-07-10 04:07:39 -07:00
|
|
|
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)
|
2017-04-28 21:33:25 -07:00
|
|
|
|
2017-07-10 04:07:39 -07:00
|
|
|
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
|
2017-04-28 21:33:25 -07:00
|
|
|
}
|
2017-04-29 22:08:09 -07:00
|
|
|
|
|
|
|
func TestAPISearchRepoNotLogin(t *testing.T) {
|
2017-06-25 02:34:30 -07:00
|
|
|
prepareTestEnv(t)
|
2017-07-10 04:07:39 -07:00
|
|
|
const keyword = "test"
|
|
|
|
|
|
|
|
req := NewRequestf(t, "GET", "/api/v1/repos/search?q=%s", keyword)
|
|
|
|
resp := MakeRequest(t, req, http.StatusOK)
|
2017-04-29 22:08:09 -07:00
|
|
|
|
2017-07-10 04:07:39 -07:00
|
|
|
var body searchResponseBody
|
|
|
|
DecodeJSON(t, resp, &body)
|
|
|
|
for _, repo := range body.data {
|
|
|
|
assert.True(t, strings.Contains(repo.Name, keyword))
|
|
|
|
}
|
2017-04-29 22:08:09 -07:00
|
|
|
}
|