2022-04-07 21:59:56 +03:00
// Copyright 2022 The Gitea Authors. All rights reserved.
2022-11-27 21:20:29 +03:00
// SPDX-License-Identifier: MIT
2022-04-07 21:59:56 +03:00
2022-09-02 22:18:23 +03:00
package integration
2022-04-07 21:59:56 +03:00
import (
"net/http"
"net/url"
"testing"
api "code.gitea.io/gitea/modules/structs"
2022-09-02 22:18:23 +03:00
"code.gitea.io/gitea/tests"
2022-04-08 08:21:05 +03:00
2022-04-07 21:59:56 +03:00
"github.com/stretchr/testify/assert"
)
func TestTopicSearch ( t * testing . T ) {
2022-09-02 22:18:23 +03:00
defer tests . PrepareTestEnv ( t ) ( )
2022-04-07 21:59:56 +03: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 )
}
}