@@ -73,8 +73,6 @@ class ClientTests: XCTestCase {
7373 XCTFail ( " Error during waitTask: \( error) " )
7474 expectation. fulfill ( )
7575 } else {
76- XCTAssertEqual ( JSON![ " status " ] as String , " published " , " Wait task failed " )
77-
7876 self . client. listIndexes ( { ( JSON, error) -> Void in
7977 if let error = error {
8078 XCTFail ( " Error during listIndexes: \( error) " )
@@ -127,8 +125,6 @@ class ClientTests: XCTestCase {
127125 XCTFail ( " Error during waitTask: \( error) " )
128126 expecation. fulfill ( )
129127 } else {
130- XCTAssertEqual ( JSON![ " status " ] as String , " published " , " Wait task failed " )
131-
132128 let dstIndex = self . client. getIndex ( " algol?à-swift2 " )
133129 dstIndex. search ( Query ( ) , block: { ( JSON, error) -> Void in
134130 if let error = error {
@@ -187,11 +183,7 @@ class ClientTests: XCTestCase {
187183 self . index. waitTask ( JSON![ " taskID " ] as Int , block: { ( JSON, error) -> Void in
188184 if let error = error {
189185 XCTFail ( " Error during waitTask: \( error) " )
190- expecation. fulfill ( )
191186 } else {
192- XCTAssertEqual ( JSON![ " status " ] as String , " published " , " Wait task failed " )
193- expecation. fulfill ( )
194-
195187 self . index. search ( Query ( ) , block: { ( JSON, error) -> Void in
196188 if let error = error {
197189 XCTFail ( " Error during search: \( error) " )
@@ -215,6 +207,8 @@ class ClientTests: XCTestCase {
215207 dstIndexExpectation. fulfill ( )
216208 } )
217209 }
210+
211+ expecation. fulfill ( )
218212 } )
219213 }
220214 } )
@@ -233,4 +227,135 @@ class ClientTests: XCTestCase {
233227
234228 waitForExpectationsWithTimeout ( expectationTimeout, handler: nil )
235229 }
230+
231+ func testGetLogs( ) {
232+ let expecation = expectationWithDescription ( " testGetLogs " )
233+ let object = [ " city " : " San Francisco " , " objectID " : " a/go/?à " ]
234+
235+ index. addObject ( object, block: { ( JSON, error) -> Void in
236+ if let error = error {
237+ XCTFail ( " Error during addObject: \( error) " )
238+ expecation. fulfill ( )
239+ } else {
240+ self . index. waitTask ( JSON![ " taskID " ] as Int , block: { ( JSON, error) -> Void in
241+ if let error = error {
242+ XCTFail ( " Error during waitTask: \( error) " )
243+ expecation. fulfill ( )
244+ } else {
245+ self . client. getLogs ( { ( JSON, error) -> Void in
246+ if let error = error {
247+ XCTFail ( " Error during getLogs: \( error) " )
248+ } else {
249+ let logs = JSON![ " logs " ] as [ AnyObject ]
250+ XCTAssertNotEqual ( logs. count, 0 , " Get logs failed " )
251+ }
252+
253+ expecation. fulfill ( )
254+ } )
255+ }
256+ } )
257+ }
258+ } )
259+
260+ waitForExpectationsWithTimeout ( expectationTimeout, handler: nil )
261+ }
262+
263+ func testGetLogsWithOffset( ) {
264+ let expecation = expectationWithDescription ( " testGetLogsWithOffset " )
265+ let object = [ " city " : " San Francisco " , " objectID " : " a/go/?à " ]
266+
267+ index. addObject ( object, block: { ( JSON, error) -> Void in
268+ if let error = error {
269+ XCTFail ( " Error during addObject: \( error) " )
270+ expecation. fulfill ( )
271+ } else {
272+ self . index. waitTask ( JSON![ " taskID " ] as Int , block: { ( JSON, error) -> Void in
273+ if let error = error {
274+ XCTFail ( " Error during waitTask: \( error) " )
275+ expecation. fulfill ( )
276+ } else {
277+ self . client. getLogsWithOffset ( 0 , length: 1 , block: { ( JSON, error) -> Void in
278+ if let error = error {
279+ XCTFail ( " Error during getLogs: \( error) " )
280+ } else {
281+ let logs = JSON![ " logs " ] as [ AnyObject ]
282+ XCTAssertEqual ( logs. count, 1 , " Get logs failed " )
283+ }
284+
285+ expecation. fulfill ( )
286+ } )
287+ }
288+ } )
289+ }
290+ } )
291+
292+ waitForExpectationsWithTimeout ( expectationTimeout, handler: nil )
293+ }
294+
295+ func testGetLogsWithType( ) {
296+ let expecation = expectationWithDescription ( " testGetLogsWithType " )
297+ let object = [ " city " : " San Francisco " , " objectID " : " a/go/?à " ]
298+
299+ index. addObject ( object, block: { ( JSON, error) -> Void in
300+ if let error = error {
301+ XCTFail ( " Error during addObject: \( error) " )
302+ expecation. fulfill ( )
303+ } else {
304+ self . index. waitTask ( JSON![ " taskID " ] as Int , block: { ( JSON, error) -> Void in
305+ if let error = error {
306+ XCTFail ( " Error during waitTask: \( error) " )
307+ expecation. fulfill ( )
308+ } else {
309+ self . client. getLogsWithType ( " error " , offset: 0 , length: 1 , block: { ( JSON, error) -> Void in
310+ if let error = error {
311+ XCTFail ( " Error during getLogs: \( error) " )
312+ } else {
313+ let logs = JSON![ " logs " ] as [ AnyObject ]
314+ XCTAssertEqual ( logs. count, 1 , " Get logs failed " )
315+ }
316+
317+ expecation. fulfill ( )
318+ } )
319+ }
320+ } )
321+ }
322+ } )
323+
324+ waitForExpectationsWithTimeout ( expectationTimeout, handler: nil )
325+ }
326+
327+ func testMultipleQueries( ) {
328+ let expectation = expectationWithDescription ( " testMultipleQueries " )
329+ let object = [ " city " : " San Francisco " ]
330+
331+ index. addObject ( object, block: { ( JSON, error) -> Void in
332+ if let error = error {
333+ XCTFail ( " Error during addObject: \( error) " )
334+ expectation. fulfill ( )
335+ } else {
336+ self . index. waitTask ( JSON![ " taskID " ] as Int , block: { ( JSON, error) -> Void in
337+ if let error = error {
338+ XCTFail ( " Error during waitTask: \( error) " )
339+ expectation. fulfill ( )
340+ } else {
341+ let queries = [ [ " indexName " : self . index. indexName, " query " : Query ( ) ] ]
342+
343+ self . client. multipleQueries ( queries, block: { ( JSON, error) -> Void in
344+ if let error = error {
345+ XCTFail ( " Error during multipleQueries: \( error) " )
346+ } else {
347+ let items = JSON![ " results " ] as [ [ String : AnyObject ] ]
348+ let nbHits = items [ 0 ] [ " nbHits " ] as Int
349+ XCTAssertEqual ( nbHits, 1 , " Wrong number of object in the index " )
350+ }
351+
352+ expectation. fulfill ( )
353+ } )
354+ }
355+ } )
356+ }
357+ } )
358+
359+ waitForExpectationsWithTimeout ( expectationTimeout, handler: nil )
360+ }
236361}
0 commit comments