Skip to content

Commit 951b207

Browse files
bors[bot]damien-rivetbidoubiwa
authored
Merge #233
233: Fix filter tests failing because of an invisible character r=bidoubiwa a=bidoubiwa Fixes #210 Co-authored-by: Damien Rivet <[email protected]> Co-authored-by: cvermand <[email protected]> Co-authored-by: Charlotte Vermandel <[email protected]>
2 parents 4fde150 + 0711837 commit 951b207

File tree

2 files changed

+145
-3
lines changed

2 files changed

+145
-3
lines changed

Tests/MeiliSearchIntegrationTests/SearchTests.swift

Lines changed: 36 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private let books: [Book] = [
6262
Book(id: 456, title: "Le Petit Prince", comment: "A french book", genres: ["Novel"]),
6363
Book(id: 2, title: "Le Rouge et le Noir", comment: "Another french book", genres: ["Bildungsroman"]),
6464
Book(id: 1, title: "Alice In Wonderland", comment: "A weird book", genres: ["Fantasy"]),
65-
Book(id: 1344, title: "The Hobbit", comment: "An awesome book", genres: ["High fantasy"]),
65+
Book(id: 1344, title: "The Hobbit", comment: "An awesome book", genres: ["High fantasy"]),
6666
Book(id: 4, title: "Harry Potter and the Half-Blood Prince", comment: "The best book", genres: ["Fantasy"]),
6767
Book(id: 42, title: "The Hitchhiker's Guide to the Galaxy", genres: ["Novel"]),
6868
Book(id: 1844, title: "A Moreninha", comment: "A Book from Joaquim Manuel de Macedo", genres: ["Novel"])
@@ -666,10 +666,43 @@ class SearchTests: XCTestCase {
666666
XCTFail("Failed to search with testSearchFacetsFilters")
667667
}
668668
}
669+
}
670+
self.wait(for: [expectation], timeout: 2.0)
671+
}
672+
673+
func testSearchFilterWithEmptySpace() {
674+
let expectation = XCTestExpectation(description: "Search for Books using filters with a space in the value")
675+
676+
configureFilters {
677+
typealias MeiliResult = Result<SearchResult<Book>, Error>
678+
679+
let query = ""
680+
let limit = 5
681+
let filter = "genres = 'High fantasy'"
682+
let parameters = SearchParameters(query: query, limit: limit, filter: filter)
683+
684+
self.index.search(parameters) { (result: MeiliResult) in
685+
switch result {
686+
case .success(let documents):
687+
XCTAssertEqual(documents.query, query)
688+
XCTAssertEqual(documents.limit, limit)
689+
XCTAssertEqual(documents.hits.count, 1)
690+
guard let book: Book = documents.hits.first(where: { book in book.id == 1344 }) else {
691+
XCTFail("Failed to search with testSearchFilterWithEmptySpace")
692+
return
693+
}
694+
695+
XCTAssertEqual("The Hobbit", book.title)
669696

697+
expectation.fulfill()
698+
699+
case .failure:
700+
XCTFail("Failed to search with testSearchFilterWithEmptySpace")
701+
}
702+
}
670703
}
671704

672-
self.wait(for: [expectation], timeout: 2.0)
705+
wait(for: [expectation], timeout: 5.0)
673706
}
674707

675708
// MARK: Facets distribution
@@ -698,7 +731,7 @@ class SearchTests: XCTestCase {
698731
let expected: [String: [String: Int]] = [
699732
"genres": [
700733
"Classic Regency nove": 1,
701-
"High fantasy": 1,
734+
"High fantasy": 1,
702735
"Fantasy": 2,
703736
"Novel": 2,
704737
"Bildungsroman": 1

Tests/MeiliSearchUnitTests/SearchTests.swift

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)