@@ -139,6 +139,115 @@ class SearchTests: XCTestCase {
139139
140140 self . wait ( for: [ expectation] , timeout: 5.0 )
141141 }
142+
143+ func testShouldFilterValuesWithSpaces( ) {
144+ let jsonString = """
145+ {
146+ " hits " : [
147+ {
148+ " id " : 123,
149+ " title " : " Pride and Prejudice " ,
150+ " comment " : " A great book " ,
151+ " genre " : " romance " ,
152+ " poster " : " https://image.tmdb.org/t/p/w1280/jjHu128XLARc2k4cJrblAvZe0HE.jpg " ,
153+ " overview " : " Delve into the world of Batman and the vigilante justice tha " ,
154+ " release_date " : " 2020-04-04T19:59:49.259572Z "
155+ },
156+ {
157+ " id " : 456,
158+ " title " : " Le Petit Prince " ,
159+ " comment " : " A french book about a prince that walks on little cute planets " ,
160+ " genre " : " adventure " ,
161+ " poster " : " https://image.tmdb.org/t/p/w1280/jjHu128XLARc2k4cJrblAvZe0HE.jpg " ,
162+ " overview " : " Delve into the world of Batman and the vigilante justice tha " ,
163+ " release_date " : " 2020-04-04T19:59:49.259572Z "
164+ },
165+ {
166+ " id " : 2,
167+ " title " : " Le Rouge et le Noir " ,
168+ " comment " : " Another french book " ,
169+ " genre " : " romance " ,
170+ " poster " : " https://image.tmdb.org/t/p/w1280/jjHu128XLARc2k4cJrblAvZe0HE.jpg " ,
171+ " overview " : " Delve into the world of Batman and the vigilante justice tha " ,
172+ " release_date " : " 2020-04-04T19:59:49.259572Z "
173+ },
174+ {
175+ " id " : 1,
176+ " title " : " Alice In Wonderland " ,
177+ " comment " : " A weird book " ,
178+ " genre " : " adventure " ,
179+ " poster " : " https://image.tmdb.org/t/p/w1280/jjHu128XLARc2k4cJrblAvZe0HE.jpg " ,
180+ " overview " : " Delve into the world of Batman and the vigilante justice tha " ,
181+ " release_date " : " 2020-04-04T19:59:49.259572Z "
182+ },
183+ {
184+ " id " : 1344,
185+ " title " : " The Hobbit " ,
186+ " comment " : " An awesome book " ,
187+ " genre " : " sci fi " ,
188+ " poster " : " https://image.tmdb.org/t/p/w1280/jjHu128XLARc2k4cJrblAvZe0HE.jpg " ,
189+ " overview " : " Delve into the world of Batman and the vigilante justice tha " ,
190+ " release_date " : " 2020-04-04T19:59:49.259572Z "
191+ },
192+ {
193+ " id " : 4,
194+ " title " : " Harry Potter and the Half-Blood Prince " ,
195+ " comment " : " The best book " ,
196+ " genre " : " fantasy " ,
197+ " poster " : " https://image.tmdb.org/t/p/w1280/jjHu128XLARc2k4cJrblAvZe0HE.jpg " ,
198+ " overview " : " Delve into the world of Batman and the vigilante justice tha " ,
199+ " release_date " : " 2020-04-04T19:59:49.259572Z "
200+ },
201+ {
202+ " id " : 42,
203+ " title " : " The Hitchhiker's Guide to the Galaxy " ,
204+ " genre " : " fantasy " ,
205+ " poster " : " https://image.tmdb.org/t/p/w1280/jjHu128XLARc2k4cJrblAvZe0HE.jpg " ,
206+ " overview " : " Delve into the world of Batman and the vigilante justice tha " ,
207+ " release_date " : " 2020-04-04T19:59:49.259572Z "
208+ }
209+ ],
210+ " offset " : 0,
211+ " limit " : 20,
212+ " processingTimeMs " : 2,
213+ " nbHits " : 1,
214+ " query " : " h " ,
215+ " genre " : " sci fi "
216+ }
217+ """
218+
219+ // Prepare the mock server
220+ guard let data = jsonString. data ( using: . utf8) , let stubSearchResult = try ? Constants . customJSONDecoder. decode ( SearchResult< Movie> . self , from: data) else {
221+ XCTFail ( " Failed to encode JSON data " )
222+ return
223+ }
224+
225+ session. pushData ( jsonString)
226+
227+ // Start the test with the mocked server
228+ let searchParameters = SearchParameters (
229+ query: " h " ,
230+ filter: " genre = 'sci fi' " ,
231+ sort: [ " id:asc " ]
232+ )
233+
234+ let expectation = XCTestExpectation ( description: " Searching for the hobbit " )
235+ typealias MeiliResult = Result < SearchResult < Movie > , Swift . Error >
236+
237+ index . search ( searchParameters) { ( result: MeiliResult ) in
238+ switch result {
239+ case . success( let searchResult) :
240+ XCTAssertEqual ( stubSearchResult, searchResult)
241+ XCTAssertEqual ( searchResult. nbHits, 1 )
242+ case . failure:
243+ XCTFail ( " Failed to search for botman " )
244+ }
245+
246+ expectation. fulfill ( )
247+ }
248+
249+ wait ( for: [ expectation] , timeout: 5.0 )
250+ }
142251}
143252// swiftlint:enable force_unwrapping
144253// swiftlint:enable force_try
0 commit comments