Skip to content

Commit 0308d44

Browse files
lunnyappleboy
authored andcommitted
fix #1643 and improve integration test (#1645)
1 parent 00324ce commit 0308d44

File tree

4 files changed

+36
-10
lines changed

4 files changed

+36
-10
lines changed

integrations/api_repo_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,12 @@ func TestAPIUserReposNotLogin(t *testing.T) {
2121
resp := MakeRequest(req)
2222
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
2323
}
24+
25+
func TestAPISearchRepoNotLogin(t *testing.T) {
26+
assert.NoError(t, models.LoadFixtures())
27+
28+
req, err := http.NewRequest("GET", "/api/v1/repos/search?q=Test", nil)
29+
assert.NoError(t, err)
30+
resp := MakeRequest(req)
31+
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
32+
}

integrations/view_test.go renamed to integrations/repo_test.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,3 @@ func TestViewRepo(t *testing.T) {
1919
resp := MakeRequest(req)
2020
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
2121
}
22-
23-
func TestViewUser(t *testing.T) {
24-
prepareTestEnv(t)
25-
26-
req, err := http.NewRequest("GET", "/user2", nil)
27-
assert.NoError(t, err)
28-
resp := MakeRequest(req)
29-
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
30-
}

integrations/user_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
// Copyright 2017 The Gitea Authors. All rights reserved.
2+
// Use of this source code is governed by a MIT-style
3+
// license that can be found in the LICENSE file.
4+
5+
package integrations
6+
7+
import (
8+
"net/http"
9+
"testing"
10+
11+
"github.com/stretchr/testify/assert"
12+
)
13+
14+
func TestViewUser(t *testing.T) {
15+
prepareTestEnv(t)
16+
17+
req, err := http.NewRequest("GET", "/user2", nil)
18+
assert.NoError(t, err)
19+
resp := MakeRequest(req)
20+
assert.EqualValues(t, http.StatusOK, resp.HeaderCode)
21+
}

routers/api/v1/repo/repo.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,11 @@ func Search(ctx *context.APIContext) {
5555
return
5656
}
5757

58+
var userID int64
59+
if ctx.IsSigned {
60+
userID = ctx.User.ID
61+
}
62+
5863
results := make([]*api.Repository, len(repos))
5964
for i, repo := range repos {
6065
if err = repo.GetOwner(); err != nil {
@@ -64,7 +69,7 @@ func Search(ctx *context.APIContext) {
6469
})
6570
return
6671
}
67-
accessMode, err := models.AccessLevel(ctx.User.ID, repo)
72+
accessMode, err := models.AccessLevel(userID, repo)
6873
if err != nil {
6974
ctx.JSON(500, map[string]interface{}{
7075
"ok": false,

0 commit comments

Comments
 (0)