2022-04-08 02:59:56 +08:00
|
|
|
// Copyright 2022 The Gitea Authors. All rights reserved.
|
2022-11-28 02:20:29 +08:00
|
|
|
// SPDX-License-Identifier: MIT
|
2022-04-08 02:59:56 +08:00
|
|
|
|
2022-09-03 03:18:23 +08:00
|
|
|
package integration
|
2022-04-08 02:59:56 +08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
"net/url"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
api "code.gitea.io/gitea/modules/structs"
|
2022-09-03 03:18:23 +08:00
|
|
|
"code.gitea.io/gitea/tests"
|
2022-04-08 13:21:05 +08:00
|
|
|
|
2022-04-08 02:59:56 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestTopicSearch(t *testing.T) {
|
2022-09-03 03:18:23 +08:00
|
|
|
defer tests.PrepareTestEnv(t)()
|
2022-04-08 02:59:56 +08:00
|
|
|
searchURL, _ := url.Parse("/explore/topics/search")
|
|
|
|
var topics struct {
|
|
|
|
TopicNames []*api.TopicResponse `json:"topics"`
|
|
|
|
}
|
|
|
|
|
|
|
|
query := url.Values{"page": []string{"1"}, "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, 4)
|
|
|
|
assert.EqualValues(t, "6", res.Header().Get("x-total-count"))
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
|
|
|
query.Set("q", "database")
|
|
|
|
searchURL.RawQuery = query.Encode()
|
|
|
|
res = MakeRequest(t, NewRequest(t, "GET", searchURL.String()), http.StatusOK)
|
|
|
|
DecodeJSON(t, res, &topics)
|
|
|
|
if assert.Len(t, topics.TopicNames, 1) {
|
|
|
|
assert.EqualValues(t, 2, topics.TopicNames[0].ID)
|
|
|
|
assert.EqualValues(t, "database", topics.TopicNames[0].Name)
|
|
|
|
assert.EqualValues(t, 1, topics.TopicNames[0].RepoCount)
|
|
|
|
}
|
|
|
|
}
|