mirror of
https://github.com/go-gitea/gitea
synced 2025-07-09 20:17:21 +00:00
Refactor topic Find functions and add more tests for pagination (#30127)
This also fixed #22238
This commit is contained in:
@ -26,14 +26,34 @@ func TestAPITopicSearch(t *testing.T) {
|
||||
TopicNames []*api.TopicResponse `json:"topics"`
|
||||
}
|
||||
|
||||
// search all topics
|
||||
res := MakeRequest(t, NewRequest(t, "GET", searchURL.String()), http.StatusOK)
|
||||
DecodeJSON(t, res, &topics)
|
||||
assert.Len(t, topics.TopicNames, 6)
|
||||
assert.EqualValues(t, "6", res.Header().Get("x-total-count"))
|
||||
|
||||
// pagination search topics first page
|
||||
topics.TopicNames = nil
|
||||
query := url.Values{"page": []string{"1"}, "limit": []string{"4"}}
|
||||
|
||||
searchURL.RawQuery = query.Encode()
|
||||
res := MakeRequest(t, NewRequest(t, "GET", searchURL.String()), http.StatusOK)
|
||||
res = MakeRequest(t, NewRequest(t, "GET", searchURL.String()), http.StatusOK)
|
||||
DecodeJSON(t, res, &topics)
|
||||
assert.Len(t, topics.TopicNames, 4)
|
||||
assert.EqualValues(t, "6", res.Header().Get("x-total-count"))
|
||||
|
||||
// pagination search topics second page
|
||||
topics.TopicNames = nil
|
||||
query = url.Values{"page": []string{"2"}, "limit": []string{"4"}}
|
||||
|
||||
searchURL.RawQuery = query.Encode()
|
||||
res = MakeRequest(t, NewRequest(t, "GET", searchURL.String()), http.StatusOK)
|
||||
DecodeJSON(t, res, &topics)
|
||||
assert.Len(t, topics.TopicNames, 2)
|
||||
assert.EqualValues(t, "6", res.Header().Get("x-total-count"))
|
||||
|
||||
// add keyword search
|
||||
query = url.Values{"page": []string{"1"}, "limit": []string{"4"}}
|
||||
query.Add("q", "topic")
|
||||
searchURL.RawQuery = query.Encode()
|
||||
res = MakeRequest(t, NewRequest(t, "GET", searchURL.String()), http.StatusOK)
|
||||
|
Reference in New Issue
Block a user