@@ -2,14 +2,13 @@ package suite
22
33import clientAnswers
44import com.algolia.search.ExperimentalAlgoliaClientAPI
5+ import com.algolia.search.model.Attribute
56import com.algolia.search.model.IndexName
67import com.algolia.search.model.search.AnswersQuery
78import com.algolia.search.model.search.Language
8- import kotlinx.serialization.json.jsonObject
9- import kotlinx.serialization.json.jsonPrimitive
10- import runBlocking
11- import shouldEqual
129import kotlin.test.Test
10+ import kotlin.test.assertFalse
11+ import runBlocking
1312
1413internal class TestSuiteAnswers {
1514
@@ -18,55 +17,18 @@ internal class TestSuiteAnswers {
1817
1918 @OptIn(ExperimentalAlgoliaClientAPI ::class )
2019 @Test
21- fun withResult () {
22- runBlocking {
23- val query = AnswersQuery (
24- query = " sir ken robinson" ,
25- queryLanguages = listOf (Language .English )
26- )
27-
28- val response = answers.findAnswers(query)
29-
30- response.nbHits shouldEqual 10
31- }
32- }
33-
34- @OptIn(ExperimentalAlgoliaClientAPI ::class )
35- @Test
36- fun withoutResult () {
20+ fun testFindAnswers () {
3721 runBlocking {
3822 val query = AnswersQuery (
39- query = " what" ,
40- queryLanguages = listOf (Language .English )
41- )
42-
43- val response = answers.findAnswers(query)
44-
45- response.nbHits shouldEqual 0
46- }
47- }
48-
49- @OptIn(ExperimentalAlgoliaClientAPI ::class )
50- @Test
51- fun withHighlight () {
52- runBlocking {
53- val query = AnswersQuery (
54- query = " sarah jones" ,
23+ query = " when do babies start learning?" ,
5524 queryLanguages = listOf (Language .English ),
56- nbHits = 2 ,
57- ).apply {
58- highlightPreTag = " _pre_"
59- highlightPostTag = " _post_"
60- }
25+ nbHits = 20 ,
26+ attributesForPrediction = listOf (Attribute (" description" ), Attribute (" title" ), Attribute (" transcript" ))
27+ )
6128
6229 val response = answers.findAnswers(query)
6330
64- response.nbHits shouldEqual 2
65- response.hits[0 ]
66- .highlightResult[" main_speaker" ]
67- ?.jsonObject?.get(" value" )
68- ?.jsonPrimitive?.content shouldEqual " _pre_Sarah_post_ _pre_Jones_post_"
69-
31+ assertFalse(response.hits.map { it.answer }.isEmpty())
7032 }
7133 }
7234}
0 commit comments