Refactor topic Find functions and add more tests for pagination (#30127)
This also fixed #22238
This commit is contained in:
parent
dd8dde2be8
commit
8acc7aab4c
7 changed files with 70 additions and 32 deletions
|
@ -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)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue