mirror of
				https://github.com/go-gitea/gitea.git
				synced 2025-10-29 10:57:44 +09:00 
			
		
		
		
	[API] generalize list header (#16551)
* Add info about list endpoints to CONTRIBUTING.md * Let all list endpoints return X-Total-Count header * Add TODOs for GetCombinedCommitStatusByRef * Fix models/issue_stopwatch.go * Rrefactor models.ListDeployKeys * Introduce helper func and use them for SetLinkHeader related func
This commit is contained in:
		| @@ -7,6 +7,7 @@ package integrations | ||||
| import ( | ||||
| 	"fmt" | ||||
| 	"net/http" | ||||
| 	"net/url" | ||||
| 	"testing" | ||||
|  | ||||
| 	"code.gitea.io/gitea/models" | ||||
| @@ -15,6 +16,38 @@ import ( | ||||
| 	"github.com/stretchr/testify/assert" | ||||
| ) | ||||
|  | ||||
| func TestAPITopicSearch(t *testing.T) { | ||||
| 	defer prepareTestEnv(t)() | ||||
| 	searchURL, _ := url.Parse("/api/v1/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) | ||||
| 	} | ||||
| } | ||||
|  | ||||
| func TestAPIRepoTopic(t *testing.T) { | ||||
| 	defer prepareTestEnv(t)() | ||||
| 	user2 := models.AssertExistsAndLoadBean(t, &models.User{ID: 2}).(*models.User) // owner of repo2 | ||||
|   | ||||
		Reference in New Issue
	
	Block a user