1
+ import { numberWithSpaces } from 'src/utils/base.helper' ;
1
2
import {
2
3
expect ,
3
4
describe ,
@@ -34,6 +35,7 @@ const responseSchema = Joi.object({
34
35
cursor : Joi . number ( ) . integer ( ) . required ( ) ,
35
36
scanned : Joi . number ( ) . integer ( ) . required ( ) ,
36
37
total : Joi . number ( ) . integer ( ) . required ( ) ,
38
+ maxResults : Joi . number ( ) . integer ( ) . allow ( null ) . required ( ) ,
37
39
keys : Joi . array ( ) . items ( Joi . object ( {
38
40
name : JoiRedisString . required ( ) ,
39
41
} ) ) . required ( ) ,
@@ -62,6 +64,7 @@ describe('POST /databases/:id/redisearch/search', () => {
62
64
expect ( body . cursor ) . to . eq ( 10 ) ;
63
65
expect ( body . scanned ) . to . eq ( 10 ) ;
64
66
expect ( body . total ) . to . eq ( 2000 ) ;
67
+ expect ( body . maxResults ) . to . eq ( 10000 ) ;
65
68
} ,
66
69
} ,
67
70
{
@@ -77,8 +80,21 @@ describe('POST /databases/:id/redisearch/search', () => {
77
80
expect ( body . cursor ) . to . eq ( 110 ) ;
78
81
expect ( body . scanned ) . to . eq ( 110 ) ;
79
82
expect ( body . total ) . to . eq ( 2000 ) ;
83
+ expect ( body . maxResults ) . to . eq ( 10000 ) ;
80
84
} ,
81
85
} ,
86
+ {
87
+ name : 'Should return custom error message if MAXSEARCHRESULTS less than request.limit' ,
88
+ data : validInputData ,
89
+ statusCode : 400 ,
90
+ responseBody : {
91
+ statusCode : 400 ,
92
+ error : 'Bad Request' ,
93
+ message : `Set MAXSEARCHRESULTS to at least ${ numberWithSpaces ( validInputData . limit ) } .` ,
94
+ } ,
95
+ before : ( ) => rte . data . setRedisearchConfig ( 'MAXSEARCHRESULTS' , '1' ) ,
96
+ after : ( ) => rte . data . setRedisearchConfig ( 'MAXSEARCHRESULTS' , '10000' ) ,
97
+ } ,
82
98
] . map ( mainCheckFn ) ;
83
99
} ) ;
84
100
@@ -107,6 +123,20 @@ describe('POST /databases/:id/redisearch/search', () => {
107
123
} ,
108
124
before : ( ) => rte . data . setAclUserRules ( '~* +@all -ft.search' )
109
125
} ,
126
+ {
127
+ name : 'Should return response with maxResults = null if no permissions for "ft.config" command' ,
128
+ endpoint : ( ) => endpoint ( constants . TEST_INSTANCE_ACL_ID ) ,
129
+ data : validInputData ,
130
+ responseSchema,
131
+ checkFn : async ( { body } ) => {
132
+ expect ( body . keys . length ) . to . eq ( 10 ) ;
133
+ expect ( body . cursor ) . to . eq ( 10 ) ;
134
+ expect ( body . scanned ) . to . eq ( 10 ) ;
135
+ expect ( body . total ) . to . eq ( 2000 ) ;
136
+ expect ( body . maxResults ) . to . eq ( null ) ;
137
+ } ,
138
+ before : ( ) => rte . data . setAclUserRules ( '~* +@all -ft.config' )
139
+ } ,
110
140
] . map ( mainCheckFn ) ;
111
141
} ) ;
112
142
} ) ;
0 commit comments