@@ -750,6 +750,115 @@ describe('Kuzzle constructor', () => {
750750 } ) ;
751751 } ) ;
752752
753+ it ( 'should handle login with only one argument and without callback' , function ( done ) {
754+ var
755+ kuzzle ;
756+
757+ this . timeout ( 200 ) ;
758+
759+ kuzzle = new Kuzzle ( 'nowhere' , {
760+ connect : 'manual'
761+ } ) ;
762+
763+ kuzzle . query = function ( queryArgs , query , options , cb ) {
764+ done ( ) ;
765+ } ;
766+ kuzzle . login ( 'local' ) ;
767+ } ) ;
768+
769+ it ( 'should handle login with credentials and without callback' , function ( done ) {
770+ var
771+ kuzzle ,
772+ loginCredentials = { username : 'foo' , password : 'bar' } ;
773+
774+ this . timeout ( 200 ) ;
775+
776+ kuzzle = new Kuzzle ( 'nowhere' , {
777+ connect : 'manual'
778+ } ) ;
779+
780+ kuzzle . query = function ( queryArgs , query , options , cb ) {
781+ done ( ) ;
782+ } ;
783+
784+ kuzzle . login ( 'local' , loginCredentials ) ;
785+ } ) ;
786+
787+ it ( 'should handle login without credentials, with expiresIn and without callback' , function ( done ) {
788+ var
789+ kuzzle ;
790+
791+ this . timeout ( 200 ) ;
792+
793+ kuzzle = new Kuzzle ( 'nowhere' , {
794+ connect : 'manual'
795+ } ) ;
796+
797+ kuzzle . query = function ( queryArgs , query , options , cb ) {
798+ done ( ) ;
799+ } ;
800+
801+ kuzzle . login ( 'local' , '1h' ) ;
802+ } ) ;
803+
804+ it ( 'should handle login without credentials, without expiresIn and with callback' , function ( done ) {
805+ var
806+ kuzzle ;
807+
808+ this . timeout ( 200 ) ;
809+
810+ kuzzle = new Kuzzle ( 'nowhere' , {
811+ connect : 'manual'
812+ } ) ;
813+
814+ kuzzle . query = function ( queryArgs , query , options , cb ) {
815+ cb ( null , { result : { jwt : 'test-toto' } } ) ;
816+ } ;
817+ console . log ( '## before' ) ;
818+ kuzzle . login ( 'local' , '1h' , function ( ) {
819+ done ( ) ;
820+ } ) ;
821+ } ) ;
822+
823+ it ( 'should handle login without credentials, without expiresIn and with callback' , function ( done ) {
824+ var
825+ kuzzle ;
826+
827+ this . timeout ( 200 ) ;
828+
829+ kuzzle = new Kuzzle ( 'nowhere' , {
830+ connect : 'manual'
831+ } ) ;
832+
833+ kuzzle . query = function ( queryArgs , query , options , cb ) {
834+ cb ( null , { result : { jwt : 'test-toto' } } ) ;
835+ } ;
836+
837+ kuzzle . login ( 'local' , function ( ) {
838+ done ( ) ;
839+ } ) ;
840+ } ) ;
841+
842+ it ( 'should handle login with credentials' , function ( done ) {
843+ var
844+ kuzzle ,
845+ loginCredentials = { username : 'foo' , password : 'bar' } ;
846+
847+ this . timeout ( 200 ) ;
848+
849+ kuzzle = new Kuzzle ( 'nowhere' , {
850+ connect : 'manual'
851+ } ) ;
852+
853+ kuzzle . query = function ( queryArgs , query , options , cb ) {
854+ cb ( null , { result : { jwt : 'test-toto' } } ) ;
855+ } ;
856+
857+ kuzzle . login ( 'local' , loginCredentials , function ( ) {
858+ done ( ) ;
859+ } ) ;
860+ } ) ;
861+
753862 it ( 'should send a failed loginAttempt event if logging in fails' , function ( done ) {
754863 var
755864 kuzzle = new Kuzzle ( 'nowhere' , { connect : 'manual' } ) ,
0 commit comments