@@ -13,7 +13,7 @@ describe('Kuzzle methods', function () {
13
13
queryStub = function ( args , query , options , cb ) {
14
14
emitted = true ;
15
15
should ( args . collection ) . be . undefined ( ) ;
16
- should ( args . index ) . be . undefined ( ) ;
16
+ should ( args . index ) . be . eql ( expectedQuery . index ) ;
17
17
should ( args . controller ) . be . exactly ( expectedQuery . controller ) ;
18
18
should ( args . action ) . be . exactly ( expectedQuery . action ) ;
19
19
@@ -207,6 +207,70 @@ describe('Kuzzle methods', function () {
207
207
} ) ;
208
208
} ) ;
209
209
210
+ describe ( '#getServerInfo' , function ( ) {
211
+ beforeEach ( function ( ) {
212
+ kuzzle = new Kuzzle ( 'foo' ) ;
213
+ kuzzle . query = queryStub ;
214
+ emitted = false ;
215
+ passedOptions = null ;
216
+ error = null ;
217
+ result = { result : { serverInfo : {
218
+ kuzzle :
219
+ { version : '0.9.2' ,
220
+ api : { version : '1.0' , routes : { } } ,
221
+ nodeVersion : 'v4.2.1' ,
222
+ memoryUsed : 100020224 ,
223
+ uptime : '161089.628s' ,
224
+ plugins :
225
+ { 'kuzzle-plugin-logger' : { } ,
226
+ 'kuzzle-plugin-socketio' : { } ,
227
+ 'kuzzle-plugin-auth-passport-local' : { } } ,
228
+ system : { memory : { } , cpus : { } } } ,
229
+ services : {
230
+ writeEngine : {
231
+ type : 'elasticsearch' ,
232
+ api : '1.7' ,
233
+ version : '1.5.2' ,
234
+ lucene : '4.10.4' ,
235
+ status : 'red' ,
236
+ nodes : { } ,
237
+ spaceUsed : '14.5kb'
238
+ }
239
+ }
240
+ } } } ;
241
+ expectedQuery = {
242
+ controller : 'read' ,
243
+ action : 'serverInfo'
244
+ } ;
245
+ } ) ;
246
+
247
+ it ( 'should behave correctly when invoked' , function ( ) {
248
+ should ( kuzzle . getServerInfo ( function ( err , res ) {
249
+ should ( err ) . be . null ( ) ;
250
+ should ( res ) . be . eql ( result . result . serverInfo ) ;
251
+ } ) ) . be . eql ( kuzzle ) ;
252
+ } ) ;
253
+
254
+ it ( 'should throw an error if no callback is provided' , function ( ) {
255
+ should ( function ( ) { kuzzle . getServerInfo ( ) } ) . throw ( Error ) ;
256
+ should ( emitted ) . be . false ( ) ;
257
+
258
+ should ( function ( ) { kuzzle . getServerInfo ( { some : 'options' } ) } ) . throw ( Error ) ;
259
+ should ( emitted ) . be . false ( ) ;
260
+ } ) ;
261
+
262
+ it ( 'should execute the callback with an error if one occurs' , function ( done ) {
263
+ this . timeout ( 50 ) ;
264
+ error = 'foobar' ;
265
+
266
+ kuzzle . getServerInfo ( 'foo' , function ( err , res ) {
267
+ should ( err ) . be . exactly ( 'foobar' ) ;
268
+ should ( res ) . be . undefined ( ) ;
269
+ done ( ) ;
270
+ } ) ;
271
+ } ) ;
272
+ } ) ;
273
+
210
274
describe ( '#listCollections' , function ( ) {
211
275
beforeEach ( function ( ) {
212
276
kuzzle = new Kuzzle ( 'foo' ) ;
@@ -216,28 +280,36 @@ describe('Kuzzle methods', function () {
216
280
error = null ;
217
281
result = { result : { collections : { stored : [ ] , realtime : [ ] } } } ;
218
282
expectedQuery = {
283
+ index : 'foo' ,
219
284
controller : 'read' ,
220
285
action : 'listCollections' ,
221
286
body : { type : 'all' }
222
287
} ;
223
288
} ) ;
224
289
225
290
it ( 'should return the kuzzle instance when called' , function ( ) {
226
- should ( kuzzle . listCollections ( function ( ) { } ) ) . be . exactly ( kuzzle ) ;
291
+ should ( kuzzle . listCollections ( 'foo' , function ( ) { } ) ) . be . exactly ( kuzzle ) ;
227
292
} ) ;
228
293
229
294
it ( 'should throw an error if no callback has been provided' , function ( ) {
230
- should ( function ( ) { kuzzle . listCollections ( ) ; } ) . throw ( Error ) ;
295
+ should ( function ( ) { kuzzle . listCollections ( 'foo' ) ; } ) . throw ( Error ) ;
231
296
should ( emitted ) . be . false ( ) ;
232
- should ( function ( ) { kuzzle . listCollections ( { } ) ; } ) . throw ( Error ) ;
297
+ should ( function ( ) { kuzzle . listCollections ( 'foo' , { } ) ; } ) . throw ( Error ) ;
298
+ should ( emitted ) . be . false ( ) ;
299
+ } ) ;
300
+
301
+ it ( 'should throw an error if no index has been provided' , function ( ) {
302
+ should ( function ( ) { kuzzle . listCollections ( function ( ) { } ) } ) . throw ( Error ) ;
303
+ should ( emitted ) . be . false ( ) ;
304
+ should ( function ( ) { kuzzle . listCollections ( { } , function ( ) { } ) } ) . throw ( Error ) ;
233
305
should ( emitted ) . be . false ( ) ;
234
306
} ) ;
235
307
236
308
it ( 'should call query with the right arguments' , function ( done ) {
237
309
this . timeout ( 50 ) ;
238
310
result = { result : { collections : { stored : [ 'foo' , 'bar' , 'baz' ] , realtime : [ 'qux' ] } } } ;
239
311
240
- kuzzle . listCollections ( function ( err , res ) {
312
+ kuzzle . listCollections ( 'foo' , function ( err , res ) {
241
313
should ( err ) . be . null ( ) ;
242
314
should ( res ) . be . an . Object ( ) . and . match ( result . result . collections ) ;
243
315
done ( ) ;
@@ -248,7 +320,7 @@ describe('Kuzzle methods', function () {
248
320
this . timeout ( 50 ) ;
249
321
error = 'foobar' ;
250
322
251
- kuzzle . listCollections ( function ( err , res ) {
323
+ kuzzle . listCollections ( 'foo' , function ( err , res ) {
252
324
should ( err ) . be . exactly ( 'foobar' ) ;
253
325
should ( res ) . be . undefined ( ) ;
254
326
done ( ) ;
@@ -257,8 +329,61 @@ describe('Kuzzle methods', function () {
257
329
258
330
it ( 'should handle options correctly' , function ( done ) {
259
331
expectedQuery . body . type = 'foobar' ;
260
- kuzzle . listCollections ( { type : 'foobar' } , ( ) => done ( ) ) ;
332
+ kuzzle . listCollections ( 'foo' , { type : 'foobar' } , ( ) => done ( ) ) ;
333
+ } ) ;
334
+
335
+ it ( 'should use the default index if none is provided' , function ( ) {
336
+ kuzzle . setDefaultIndex ( 'foo' ) ;
337
+ should ( kuzzle . listCollections ( function ( ) { } ) ) . be . exactly ( kuzzle ) ;
338
+ should ( emitted ) . be . true ( ) ;
339
+
340
+ emitted = false ;
341
+ should ( kuzzle . listCollections ( { some : 'options' } , function ( ) { } ) ) . be . exactly ( kuzzle ) ;
342
+ should ( emitted ) . be . true ( ) ;
343
+ } ) ;
344
+ } ) ;
345
+
346
+ describe ( '#listIndexes' , function ( ) {
347
+ beforeEach ( function ( ) {
348
+ kuzzle = new Kuzzle ( 'foo' ) ;
349
+ kuzzle . query = queryStub ;
350
+ emitted = false ;
351
+ passedOptions = null ;
352
+ error = null ;
353
+ result = { result : { indexes : [ 'foo' , 'bar' ] } } ;
354
+ expectedQuery = {
355
+ controller : 'read' ,
356
+ action : 'listIndexes'
357
+ } ;
261
358
} ) ;
359
+
360
+ it ( 'should return the kuzzle instance when called' , function ( ) {
361
+ should ( kuzzle . listIndexes ( function ( err , res ) {
362
+ should ( err ) . be . null ( ) ;
363
+ should ( res ) . be . eql ( result . result . indexes ) ;
364
+ } ) ) . be . eql ( kuzzle ) ;
365
+ } ) ;
366
+
367
+ it ( 'should throw an error if no callback is provided' , function ( ) {
368
+ should ( function ( ) { kuzzle . listIndexes ( ) ; } ) . throw ( Error ) ;
369
+ should ( emitted ) . be . false ( ) ;
370
+
371
+ should ( function ( ) { kuzzle . listIndexes ( { some : 'options' } ) } ) . throw ( Error ) ;
372
+ should ( emitted ) . be . false ( ) ;
373
+ } ) ;
374
+
375
+ it ( 'should execute the callback with an error if one occurs' , function ( done ) {
376
+ this . timeout ( 50 ) ;
377
+ error = 'foobar' ;
378
+
379
+ kuzzle . listIndexes ( function ( err , res ) {
380
+ should ( err ) . be . exactly ( 'foobar' ) ;
381
+ should ( res ) . be . undefined ( ) ;
382
+ done ( ) ;
383
+ } ) ;
384
+ } ) ;
385
+
386
+
262
387
} ) ;
263
388
264
389
describe ( '#disconnect' , function ( ) {
0 commit comments