@@ -134,6 +134,55 @@ class SearchTests: XCTestCase {
134134 self . wait ( for: [ expectation] , timeout: 10.0 )
135135 }
136136
137+ // MARK: Basic search
138+
139+ func testBasicSearch( ) {
140+
141+ let expectation = XCTestExpectation ( description: " Search for Books using limit " )
142+
143+ typealias MeiliResult = Result < SearchResult < Book > , Swift . Error >
144+ // let limit = 5
145+ let query = " A Moreninha "
146+
147+ self . client. search ( UID: self . uid, SearchParameters ( query: query) ) { ( result: MeiliResult ) in
148+ switch result {
149+ case . success( let documents) :
150+ XCTAssertTrue ( documents. query == query)
151+ XCTAssertTrue ( documents. limit == 20 )
152+ XCTAssertTrue ( documents. hits. count == 1 )
153+ XCTAssertEqual ( query, documents. hits [ 0 ] . title)
154+ XCTAssertNil ( documents. hits [ 0 ] . formatted)
155+ expectation. fulfill ( )
156+ case . failure:
157+ XCTFail ( " Failed to search with testBasicSearch " )
158+ }
159+ }
160+
161+ self . wait ( for: [ expectation] , timeout: 1.0 )
162+ }
163+
164+ func testBasicSearchWithNoQuery( ) {
165+
166+ let expectation = XCTestExpectation ( description: " Search for Books using limit " )
167+
168+ typealias MeiliResult = Result < SearchResult < Book > , Swift . Error >
169+
170+ self . client. search ( UID: self . uid, SearchParameters ( query: nil ) ) { ( result: MeiliResult ) in
171+ switch result {
172+ case . success( let documents) :
173+ XCTAssertEqual ( " " , documents. query)
174+ XCTAssertEqual ( 20 , documents. limit)
175+ XCTAssertEqual ( books. count, documents. hits. count)
176+ XCTAssertEqual ( " Pride and Prejudice " , documents. hits [ 0 ] . title)
177+ expectation. fulfill ( )
178+ case . failure:
179+ XCTFail ( " Failed to search with testBasicSearchWithNoQuery " )
180+ }
181+ }
182+
183+ self . wait ( for: [ expectation] , timeout: 1.0 )
184+ }
185+
137186 // MARK: Limit
138187
139188 func testSearchLimit( ) {
@@ -153,7 +202,7 @@ class SearchTests: XCTestCase {
153202 XCTAssertEqual ( query, documents. hits [ 0 ] . title)
154203 expectation. fulfill ( )
155204 case . failure:
156- XCTFail ( " Failed to get Books documents " )
205+ XCTFail ( " Failed to search with testSearchLimit " )
157206 }
158207 }
159208
@@ -176,7 +225,7 @@ class SearchTests: XCTestCase {
176225 XCTAssertTrue ( documents. hits. isEmpty)
177226 expectation. fulfill ( )
178227 case . failure:
179- XCTFail ( " Failed to get Books documents " )
228+ XCTFail ( " Failed to search with testSearchZeroLimit " )
180229 }
181230 }
182231
@@ -197,9 +246,10 @@ class SearchTests: XCTestCase {
197246 XCTAssertTrue ( documents. query == query)
198247 XCTAssertTrue ( documents. limit == limit)
199248 XCTAssertTrue ( documents. hits. count == limit)
249+ XCTAssertNil ( documents. hits [ 0 ] . formatted)
200250 expectation. fulfill ( )
201251 case . failure:
202- XCTFail ( " Failed to get Books documents " )
252+ XCTFail ( " Failed to search with testSearchLimitBiggerThanNumberOfBooks " )
203253 }
204254 }
205255
@@ -220,9 +270,10 @@ class SearchTests: XCTestCase {
220270 XCTAssertTrue ( documents. query == query)
221271 XCTAssertTrue ( documents. limit == limit)
222272 XCTAssertTrue ( documents. hits. count == 5 )
273+ XCTAssertNil ( documents. hits [ 0 ] . formatted)
223274 expectation. fulfill ( )
224275 case . failure:
225- XCTFail ( " Failed to get Books documents " )
276+ XCTFail ( " Failed to search with testSearchLimitEmptySearch " )
226277 }
227278 }
228279
@@ -249,7 +300,7 @@ class SearchTests: XCTestCase {
249300 XCTAssertTrue ( documents. hits. count == 2 )
250301 expectation. fulfill ( )
251302 case . failure:
252- XCTFail ( " Failed to get Books documents " )
303+ XCTFail ( " Failed to search with testSearchOffset " )
253304 }
254305 }
255306
@@ -274,7 +325,7 @@ class SearchTests: XCTestCase {
274325 XCTAssertTrue ( documents. hits. count == 2 )
275326 expectation. fulfill ( )
276327 case . failure:
277- XCTFail ( " Failed to get Books documents " )
328+ XCTFail ( " Failed to search with testSearchOffsetZero " )
278329 }
279330 }
280331
@@ -297,9 +348,10 @@ class SearchTests: XCTestCase {
297348 XCTAssertTrue ( documents. limit == limit)
298349 XCTAssertTrue ( documents. offset == offset)
299350 XCTAssertTrue ( documents. hits. count == 1 )
351+ XCTAssertNil ( documents. hits [ 0 ] . formatted)
300352 expectation. fulfill ( )
301353 case . failure:
302- XCTFail ( " Failed to get Books documents " )
354+ XCTFail ( " Failed to search with testSearchOffsetLastPage " )
303355 }
304356 }
305357
@@ -328,7 +380,7 @@ class SearchTests: XCTestCase {
328380 XCTAssertEqual ( " Manuel de Macedo " , book. formatted!. comment!)
329381 expectation. fulfill ( )
330382 case . failure:
331- XCTFail ( " Failed to get Books documents " )
383+ XCTFail ( " Failed to search with testSearchAttributesToCrop " )
332384 }
333385 }
334386
@@ -363,7 +415,7 @@ class SearchTests: XCTestCase {
363415
364416 expectation. fulfill ( )
365417 case . failure:
366- XCTFail ( " Failed to get Books documents " )
418+ XCTFail ( " Failed to search with testSearchCropLength " )
367419 }
368420 }
369421
@@ -396,7 +448,7 @@ class SearchTests: XCTestCase {
396448 XCTAssertEqual ( 1 , info. length)
397449 expectation. fulfill ( )
398450 case . failure:
399- XCTFail ( " Failed to get Books documents " )
451+ XCTFail ( " Failed to search with testSearchMatches " )
400452 }
401453 }
402454
@@ -426,7 +478,7 @@ class SearchTests: XCTestCase {
426478 XCTAssertTrue ( book. formatted!. comment!. contains ( " <em>Joaquim</em> <em>Manuel</em> <em>de</em> <em>Macedo</em> " ) )
427479 expectation. fulfill ( )
428480 case . failure:
429- XCTFail ( " Failed to get Books documents " )
481+ XCTFail ( " Failed to search with testSearchAttributesToHighlight " )
430482 }
431483 }
432484
@@ -457,7 +509,7 @@ class SearchTests: XCTestCase {
457509 XCTAssertNil ( book. comment)
458510 expectation. fulfill ( )
459511 case . failure:
460- XCTFail ( " Failed to get Books documents " )
512+ XCTFail ( " Failed to search with testSearchAttributesToRetrieve " )
461513 }
462514 }
463515
@@ -488,7 +540,7 @@ class SearchTests: XCTestCase {
488540 XCTAssertEqual ( " A french book " , book. comment)
489541 expectation. fulfill ( )
490542 case . failure:
491- XCTFail ( " Failed to get Books documents " )
543+ XCTFail ( " Failed to search with testSearchFilters " )
492544 }
493545 }
494546
@@ -513,7 +565,7 @@ class SearchTests: XCTestCase {
513565 XCTAssertTrue ( documents. hits. isEmpty)
514566 expectation. fulfill ( )
515567 case . failure:
516- XCTFail ( " Failed to get Books documents " )
568+ XCTFail ( " Failed to search with testSearchFiltersNotMatching " )
517569 }
518570 }
519571
@@ -535,7 +587,7 @@ class SearchTests: XCTestCase {
535587 Thread . sleep ( forTimeInterval: 0.5 )
536588 completion ( )
537589 case . failure:
538- XCTFail ( " Failed to get Books documents " )
590+ XCTFail ( " Failed to update the settings " )
539591 }
540592
541593 }
@@ -568,7 +620,7 @@ class SearchTests: XCTestCase {
568620 XCTAssertEqual ( " Le Petit Prince " , petitBook. title)
569621 expectation. fulfill ( )
570622 case . failure:
571- XCTFail ( " Failed to get Books documents " )
623+ XCTFail ( " Failed to search with testSearchFacetsFilters " )
572624 }
573625 }
574626
@@ -614,7 +666,7 @@ class SearchTests: XCTestCase {
614666
615667 expectation. fulfill ( )
616668 case . failure:
617- XCTFail ( " Failed to get Books documents " )
669+ XCTFail ( " Failed to search with testSearchFacetsDistribution " )
618670 }
619671 }
620672
0 commit comments