@@ -750,7 +750,7 @@ describe('Kuzzle constructor', () => {
750750 } ) ;
751751 } ) ;
752752
753- it ( 'should get the url redirection from OAUTH ' , function ( done ) {
753+ it ( 'should handle login with only one argument and without callback ' , function ( done ) {
754754 var
755755 kuzzle ;
756756
@@ -761,11 +761,100 @@ describe('Kuzzle constructor', () => {
761761 } ) ;
762762
763763 kuzzle . query = function ( queryArgs , query , options , cb ) {
764- cb ( null , { result : { url : 'redirect' } } ) ;
764+ done ( ) ;
765765 } ;
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' } ;
766773
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' ) ;
767818 kuzzle . login ( 'local' , '1h' , function ( ) {
768- should ( kuzzle . jwtToken ) . be . undefined ( ) ;
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 ( ) {
769858 done ( ) ;
770859 } ) ;
771860 } ) ;
0 commit comments