@@ -13,7 +13,7 @@ describe('Kuzzle methods', function () {
1313 queryStub = function ( args , query , options , cb ) {
1414 emitted = true ;
1515 should ( args . collection ) . be . undefined ( ) ;
16- should ( args . index ) . be . undefined ( ) ;
16+ should ( args . index ) . be . eql ( expectedQuery . index ) ;
1717 should ( args . controller ) . be . exactly ( expectedQuery . controller ) ;
1818 should ( args . action ) . be . exactly ( expectedQuery . action ) ;
1919
@@ -207,6 +207,70 @@ describe('Kuzzle methods', function () {
207207 } ) ;
208208 } ) ;
209209
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+
210274 describe ( '#listCollections' , function ( ) {
211275 beforeEach ( function ( ) {
212276 kuzzle = new Kuzzle ( 'foo' ) ;
@@ -216,28 +280,36 @@ describe('Kuzzle methods', function () {
216280 error = null ;
217281 result = { result : { collections : { stored : [ ] , realtime : [ ] } } } ;
218282 expectedQuery = {
283+ index : 'foo' ,
219284 controller : 'read' ,
220285 action : 'listCollections' ,
221286 body : { type : 'all' }
222287 } ;
223288 } ) ;
224289
225290 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 ) ;
227292 } ) ;
228293
229294 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 ) ;
231296 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 ) ;
233305 should ( emitted ) . be . false ( ) ;
234306 } ) ;
235307
236308 it ( 'should call query with the right arguments' , function ( done ) {
237309 this . timeout ( 50 ) ;
238310 result = { result : { collections : { stored : [ 'foo' , 'bar' , 'baz' ] , realtime : [ 'qux' ] } } } ;
239311
240- kuzzle . listCollections ( function ( err , res ) {
312+ kuzzle . listCollections ( 'foo' , function ( err , res ) {
241313 should ( err ) . be . null ( ) ;
242314 should ( res ) . be . an . Object ( ) . and . match ( result . result . collections ) ;
243315 done ( ) ;
@@ -248,7 +320,7 @@ describe('Kuzzle methods', function () {
248320 this . timeout ( 50 ) ;
249321 error = 'foobar' ;
250322
251- kuzzle . listCollections ( function ( err , res ) {
323+ kuzzle . listCollections ( 'foo' , function ( err , res ) {
252324 should ( err ) . be . exactly ( 'foobar' ) ;
253325 should ( res ) . be . undefined ( ) ;
254326 done ( ) ;
@@ -257,8 +329,61 @@ describe('Kuzzle methods', function () {
257329
258330 it ( 'should handle options correctly' , function ( done ) {
259331 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+ } ;
261358 } ) ;
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+
262387 } ) ;
263388
264389 describe ( '#disconnect' , function ( ) {
0 commit comments