summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorLunny Xiao <xiaolunwen@gmail.com>2024-03-29 11:38:16 +0800
committerGitHub <noreply@github.com>2024-03-29 11:38:16 +0800
commit8acc7aab4c254c4819f45e512b86cf5a4255091f (patch)
treef99c44d3af0198977f1b5685bef7d56154beb812 /tests
parentdd8dde2be89921b2b1497c6cc5eafdde213429cb (diff)
downloadgitea-8acc7aab4c254c4819f45e512b86cf5a4255091f.tar.gz
gitea-8acc7aab4c254c4819f45e512b86cf5a4255091f.zip
Refactor topic Find functions and add more tests for pagination (#30127)
This also fixed #22238
Diffstat (limited to 'tests')
-rw-r--r--tests/integration/api_repo_topic_test.go22
-rw-r--r--tests/integration/repo_topic_test.go24
2 files changed, 44 insertions, 2 deletions
diff --git a/tests/integration/api_repo_topic_test.go b/tests/integration/api_repo_topic_test.go
index c41bc4abb6..a10e159b78 100644
--- a/tests/integration/api_repo_topic_test.go
+++ b/tests/integration/api_repo_topic_test.go
@@ -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)
diff --git a/tests/integration/repo_topic_test.go b/tests/integration/repo_topic_test.go
index 58fee8418f..f198397007 100644
--- a/tests/integration/repo_topic_test.go
+++ b/tests/integration/repo_topic_test.go
@@ -21,20 +21,42 @@ func TestTopicSearch(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
+ 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"))
+ // 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
+ topics.TopicNames = nil
+ 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)
DecodeJSON(t, res, &topics)
assert.Len(t, topics.TopicNames, 2)
+ topics.TopicNames = nil
query.Set("q", "database")
searchURL.RawQuery = query.Encode()
res = MakeRequest(t, NewRequest(t, "GET", searchURL.String()), http.StatusOK)