@@ -316,6 +316,43 @@ describe('Security user methods', function () {
316316    } ) ; 
317317  } ) ; 
318318
319+   describe ( '#replaceUser' ,  function  ( )  { 
320+     beforeEach ( function  ( )  { 
321+       kuzzle  =  new  Kuzzle ( 'foo' ,  { defaultIndex : 'bar' } ) ; 
322+       kuzzle . query  =  queryStub ; 
323+       error  =  null ; 
324+       result  =  {  result : { _id : 'foobar' ,  _index : '%kuzzle' ,  _type : 'users' ,  _source : { profileIds : [ 'foobar' ] }  }  } ; 
325+       expectedQuery  =  { 
326+         action : 'replaceUser' , 
327+         controller : 'security' 
328+       } ; 
329+     } ) ; 
330+ 
331+     it ( 'should send the right query to Kuzzle' ,  function ( done )  { 
332+       expectedQuery . _id  =  'foobar' ; 
333+       expectedQuery . body  =  { 'profileIds' : [ 'foobar' ] } ; 
334+ 
335+       should ( kuzzle . security . replaceUser ( expectedQuery . _id ,  expectedQuery . body ,  function  ( err ,  res )  { 
336+         should ( err ) . be . null ( ) ; 
337+         should ( res ) . be . instanceOf ( User ) ; 
338+         should ( res ) . containDeep ( new  User ( kuzzle . security ,  result . result . _id ,  result . result . _source ) ) ; 
339+         done ( ) ; 
340+       } ) ) ; 
341+     } ) ; 
342+ 
343+     it ( 'should send the right query to Kuzzle even without callback' ,  function  ( done )  { 
344+       expectedQuery . body  =  { 'foo' : 'bar' } ; 
345+       expectedQuery . _id  =  result . result . _id ; 
346+ 
347+       kuzzle . security . replaceUser ( result . result . _id ,  { 'foo' : 'bar' } ) ; 
348+       done ( ) ; 
349+     } ) ; 
350+ 
351+     it ( 'should throw an error if no id is provided' ,  function  ( )  { 
352+       should ( function  ( )  {  kuzzle . security . replaceUser ( null ,  { 'foo' : 'bar' } ) ;  } ) . throw ( Error ) ; 
353+     } ) ; 
354+   } ) ; 
355+ 
319356  describe ( '#updateUser' ,  function  ( )  { 
320357    beforeEach ( function  ( )  { 
321358      kuzzle  =  new  Kuzzle ( 'foo' ,  { defaultIndex : 'bar' } ) ; 
0 commit comments