11package api
22
33import (
4+ "encoding/json"
5+ "github.com/stretchr/testify/require"
46 "mokapi/config/dynamic"
7+ "mokapi/config/dynamic/asyncApi/asyncapitest"
58 "mokapi/config/dynamic/dynamictest"
69 "mokapi/config/static"
7- "mokapi/providers/openapi "
10+ "mokapi/engine/enginetest "
811 "mokapi/providers/openapi/openapitest"
912 "mokapi/runtime"
13+ "mokapi/runtime/search"
1014 "mokapi/try"
1115 "net/http"
1216 "testing"
1317)
1418
1519func TestHandler_SearchQuery (t * testing.T ) {
16- toConfig := func (c * openapi. Config ) * dynamic.Config {
20+ toConfig := func (c any ) * dynamic.Config {
1721 cfg := & dynamic.Config {
1822 Info : dynamictest .NewConfigInfo (),
1923 Data : c ,
@@ -34,7 +38,7 @@ func TestHandler_SearchQuery(t *testing.T) {
3438 response : []try.ResponseCondition {
3539 try .HasStatusCode (200 ),
3640 try .HasHeader ("Content-Type" , "application/json" ),
37- try .HasBody (`{"results":[{"type":"HTTP","title":"foo","params":{"service":"foo","type":"http"}}],"total":1}` ),
41+ try .HasBody (`{"results":[{"type":"HTTP","title":"foo","params":{"service":"foo","type":"http"}}],"facets":{"type":[{"value":"HTTP","count":1}]}," total":1}` ),
3842 },
3943 app : func () * runtime.App {
4044 app := runtime .New (& static.Config {Api : static.Api {Search : static.Search {
@@ -53,7 +57,7 @@ func TestHandler_SearchQuery(t *testing.T) {
5357 response : []try.ResponseCondition {
5458 try .HasStatusCode (200 ),
5559 try .HasHeader ("Content-Type" , "application/json" ),
56- try .HasBody (`{"results":[{"type":"HTTP","title":"foo","fragments":["\u003cmark\u003efoo\u003c/mark\u003e"],"params":{"service":"foo","type":"http"}}],"total":1}` ),
60+ try .HasBody (`{"results":[{"type":"HTTP","title":"foo","fragments":["\u003cmark\u003efoo\u003c/mark\u003e"],"params":{"service":"foo","type":"http"}}],"facets":{"type":[{"value":"HTTP","count":1}]}," total":1}` ),
5761 },
5862 app : func () * runtime.App {
5963 app := runtime .New (& static.Config {Api : static.Api {Search : static.Search {
@@ -72,7 +76,7 @@ func TestHandler_SearchQuery(t *testing.T) {
7276 response : []try.ResponseCondition {
7377 try .HasStatusCode (200 ),
7478 try .HasHeader ("Content-Type" , "application/json" ),
75- try .HasBody (`{"results":[{"type":"HTTP","title":"foo","fragments":["\u003cmark\u003efoo\u003c/mark\u003e"],"params":{"service":"foo","type":"http"}}],"total":1}` ),
79+ try .HasBody (`{"results":[{"type":"HTTP","title":"foo","fragments":["\u003cmark\u003efoo\u003c/mark\u003e"],"params":{"service":"foo","type":"http"}}],"facets":{"type":[{"value":"HTTP","count":1}]}," total":1}` ),
7680 },
7781 app : func () * runtime.App {
7882 app := runtime .New (& static.Config {Api : static.Api {Search : static.Search {
@@ -105,6 +109,36 @@ func TestHandler_SearchQuery(t *testing.T) {
105109 cfg = openapitest .NewConfig ("3.0" , openapitest .WithInfo ("bar" , "" , "" ))
106110 app .AddHttp (toConfig (cfg ))
107111
112+ return app
113+ },
114+ },
115+ {
116+ name : "using facet type=Kafka should filter out HTTP (case insensitive)" ,
117+ requestUrl : "/api/search/query?q=foo&type=Kafka" ,
118+ response : []try.ResponseCondition {
119+ try .HasStatusCode (200 ),
120+ try .HasHeader ("Content-Type" , "application/json" ),
121+ try .AssertBody (func (t * testing.T , body string ) {
122+ var result search.Result
123+ err := json .Unmarshal ([]byte (body ), & result )
124+ require .NoError (t , err )
125+ require .Len (t , result .Facets , 1 )
126+ require .Equal (t , []search.FacetValue {{Value : "HTTP" , Count : 1 }, {Value : "Kafka" , Count : 1 }}, result .Facets ["type" ])
127+ require .Len (t , result .Results , 1 )
128+ require .Equal (t , result .Results [0 ].Type , "Kafka" )
129+ }),
130+ },
131+ app : func () * runtime.App {
132+ app := runtime .New (& static.Config {Api : static.Api {Search : static.Search {
133+ Enabled : true ,
134+ }}})
135+
136+ h := openapitest .NewConfig ("3.0" , openapitest .WithInfo ("foo" , "" , "" ))
137+ app .AddHttp (toConfig (h ))
138+ k := asyncapitest .NewConfig (asyncapitest .WithInfo ("foo" , "" , "" ))
139+ _ , err := app .Kafka .Add (toConfig (k ), enginetest .NewEngine ())
140+ require .NoError (t , err )
141+
108142 return app
109143 },
110144 },
0 commit comments