@@ -779,6 +779,70 @@ describe("capabilityHelper.js", () => {
779779 } ) ;
780780 } ) ;
781781
782+ describe ( "validates username and password" , ( ) => {
783+ beforeEach ( ( ) => {
784+ //Stub for cypress json validation
785+ sinon . stub ( fs , 'existsSync' ) . returns ( true ) ;
786+ sinon . stub ( fs , 'readFileSync' ) . returns ( "{}" ) ;
787+
788+ bsConfig = {
789+ auth : { } ,
790+ browsers : [
791+ {
792+ browser : "chrome" ,
793+ os : "Windows 10" ,
794+ versions : [ "78" , "77" ] ,
795+ } ,
796+ ] ,
797+ run_settings : {
798+ cypress_proj_dir : "random path" ,
799+ cypressConfigFilePath : "random path"
800+ } ,
801+ } ;
802+ } ) ;
803+
804+ afterEach ( ( ) => {
805+ fs . existsSync . restore ( ) ;
806+ fs . readFileSync . restore ( ) ;
807+ } ) ;
808+
809+ it ( 'throws an error if the user has given username as null' , ( ) => {
810+ return capabilityHelper
811+ . validate ( bsConfig , { username : "" } )
812+ . then ( function ( data ) {
813+ chai . assert . fail ( "Promise error" ) ;
814+ } )
815+ . catch ( ( error ) => {
816+ chai . assert . equal ( error , Constants . validationMessages . EMPTY_ARGS . replace ( "<argsNotGiven>" , "Username" ) ) ;
817+ } ) ;
818+ } ) ;
819+
820+ it ( 'throws an error if the user has given password as null' , ( ) => {
821+ return capabilityHelper
822+ . validate ( bsConfig , { key : "" } )
823+ . then ( function ( data ) {
824+ chai . assert . fail ( "Promise error" ) ;
825+ } )
826+ . catch ( ( error ) => {
827+ chai . assert . equal ( error , Constants . validationMessages . EMPTY_ARGS . replace ( "<argsNotGiven>" , "Password" ) ) ;
828+ } ) ;
829+ } ) ;
830+
831+ it ( 'throws an error if the user has given username and password both as null' , ( ) => {
832+ return capabilityHelper
833+ . validate ( bsConfig , {
834+ username : "" ,
835+ key : ""
836+ } )
837+ . then ( function ( data ) {
838+ chai . assert . fail ( "Promise error" ) ;
839+ } )
840+ . catch ( ( error ) => {
841+ chai . assert . equal ( error , Constants . validationMessages . EMPTY_ARGS . replace ( "<argsNotGiven>" , "Username and Password" ) ) ;
842+ } ) ;
843+ } ) ;
844+ } ) ;
845+
782846 it ( "validate bsConfig" , ( ) => {
783847 let bsConfig = undefined ;
784848 return capabilityHelper
0 commit comments