@@ -11,8 +11,7 @@ const chai = require('chai'),
1111 chalk = require ( 'chalk' ) ,
1212 os = require ( "os" ) ,
1313 crypto = require ( 'crypto' ) ,
14- fs = require ( 'fs' ) ,
15- axios = require ( 'axios' ) ;
14+ fs = require ( 'fs' ) ;
1615const getmac = require ( 'getmac' ) . default ;
1716const usageReporting = require ( '../../../../bin/helpers/usageReporting' ) ;
1817const utils = require ( '../../../../bin/helpers/utils' ) ,
@@ -2555,75 +2554,75 @@ describe('utils', () => {
25552554 } ) ;
25562555
25572556 describe ( 'stopBrowserStackBuild' , ( ) => {
2558- let axiosPostStub , getUserAgentStub , sendUsageReportStub , message , messageType , errorCode ;
2557+ let getUserAgentStub , sendUsageReportStub , message , messageType , errorCode ;
25592558 let bsConfig = testObjects . sampleBsConfig ;
25602559 let args = { } ;
25612560 let rawArgs = { } ;
25622561 let buildId = 'build_id' ;
25632562 let body = testObjects . buildStopSampleBody ;
25642563
25652564 beforeEach ( ( ) => {
2566- axiosPostStub = sandbox . stub ( axios , "post" ) ;
25672565 getUserAgentStub = sinon . stub ( utils , 'getUserAgent' ) . returns ( 'user-agent' ) ;
25682566 sendUsageReportStub = sinon . stub ( utils , 'sendUsageReport' ) ;
25692567 } ) ;
25702568 afterEach ( ( ) => {
2571- axiosPostStub . restore ( ) ;
25722569 getUserAgentStub . restore ( ) ;
25732570 sendUsageReportStub . restore ( ) ;
25742571 sandbox . restore ( ) ;
25752572 } )
25762573
25772574 it ( 'message thrown if API deprecated' , async ( ) => {
25782575 let api_deprecated_response = {
2579- status : 299
2576+ statusCode : 299
25802577 }
25812578 message = constant . userMessages . API_DEPRECATED ;
25822579 messageType = constant . messageTypes . INFO ;
25832580 errorCode = 'api_deprecated' ;
2584- axiosPostStub . resolves ( api_deprecated_response ) ;
2581+ let requestStub = sinon . stub ( request , 'post' ) . yields ( undefined , api_deprecated_response , null ) ;
25852582 await utils . stopBrowserStackBuild ( bsConfig , args , buildId , rawArgs ) ;
2586- sinon . assert . calledOnce ( axiosPostStub ) ;
2583+ sinon . assert . calledOnce ( requestStub ) ;
25872584 sinon . assert . calledOnce ( getUserAgentStub ) ;
25882585 sinon . assert . calledOnceWithExactly ( sendUsageReportStub , bsConfig , args , message , messageType , errorCode , null , rawArgs ) ;
2586+ requestStub . restore ( ) ;
25892587 } ) ;
25902588
25912589 it ( 'message thrown if build returned' , async ( ) => {
25922590 let api_deprecated_response = {
2593- status : 299 ,
2594- data : body
2591+ statusCode : 299 ,
25952592 }
25962593 message = body . message ;
25972594 messageType = constant . messageTypes . INFO ;
25982595 errorCode = 'api_deprecated' ;
2599- axiosPostStub . resolves ( api_deprecated_response ) ;
2596+ let requestStub = sinon . stub ( request , 'post' ) . yields ( undefined , api_deprecated_response , JSON . stringify ( body ) ) ;
26002597 await utils . stopBrowserStackBuild ( bsConfig , args , buildId , rawArgs ) ;
2601- sinon . assert . calledOnce ( axiosPostStub ) ;
2598+ sinon . assert . calledOnce ( requestStub ) ;
26022599 sinon . assert . calledOnce ( getUserAgentStub ) ;
26032600 sinon . assert . calledOnceWithExactly ( sendUsageReportStub , bsConfig , args , message , messageType , errorCode , null , rawArgs ) ;
2601+ requestStub . restore ( ) ;
26042602 } ) ;
26052603
26062604 it ( 'message thrown if statusCode != 200' , async ( ) => {
26072605 let non_200_status_response = {
2608- status : 400
2606+ statusCode : 400
26092607 }
26102608 message = constant . userMessages . BUILD_STOP_FAILED ;
26112609 messageType = constant . messageTypes . ERROR ;
26122610 errorCode = 'api_failed_build_stop' ;
2613- axiosPostStub . resolves ( non_200_status_response ) ;
2611+ let requestStub = sinon . stub ( request , 'post' ) . yields ( undefined , non_200_status_response , null ) ;
26142612 await utils . stopBrowserStackBuild ( bsConfig , args , buildId , rawArgs ) ;
2615- sinon . assert . calledOnce ( axiosPostStub ) ;
2613+ sinon . assert . calledOnce ( requestStub ) ;
26162614 sinon . assert . calledOnce ( getUserAgentStub ) ;
26172615 sinon . assert . calledOnceWithExactly ( sendUsageReportStub , bsConfig , args , message , messageType , errorCode , null , rawArgs ) ;
2616+ requestStub . restore ( ) ;
26182617 } ) ;
26192618
26202619 it ( 'message thrown if statusCode != 200 and user unauthorized' , async ( ) => {
26212620 let body_with_message = {
26222621 ...body ,
2623- message : "Unauthorized" ,
2622+ " message" : "Unauthorized" ,
26242623 } ;
26252624 let non_200_status_response = {
2626- status : 401 ,
2625+ statusCode : 401 ,
26272626 data : body_with_message
26282627 }
26292628
@@ -2632,45 +2631,46 @@ describe('utils', () => {
26322631 } with error: \n${ JSON . stringify ( body_with_message , null , 2 ) } `;
26332632 messageType = constant . messageTypes . ERROR ;
26342633 errorCode = 'api_auth_failed' ;
2635- axiosPostStub . resolves ( non_200_status_response ) ;
2634+ let requestStub = sinon . stub ( request , 'post' ) . yields ( undefined , non_200_status_response , JSON . stringify ( body_with_message ) ) ;
26362635 await utils . stopBrowserStackBuild ( bsConfig , args , buildId , rawArgs ) ;
2637- sinon . assert . calledOnce ( axiosPostStub ) ;
2636+ sinon . assert . calledOnce ( requestStub ) ;
26382637 sinon . assert . calledOnce ( getUserAgentStub ) ;
26392638 sinon . assert . calledOnceWithExactly ( sendUsageReportStub , bsConfig , args , message , messageType , errorCode , null , rawArgs ) ;
2639+ requestStub . restore ( ) ;
26402640 } ) ;
26412641
26422642 it ( 'message thrown if statusCode != 200 and build is present' , async ( ) => {
26432643 let non_200_status_response = {
2644- status : 402 ,
2645- data : body
2644+ statusCode : 402 ,
26462645 }
26472646
26482647 message = `${
26492648 constant . userMessages . BUILD_STOP_FAILED
26502649 } with error: \n${ JSON . stringify ( body , null , 2 ) } `;
26512650 messageType = constant . messageTypes . ERROR ;
26522651 errorCode = 'api_failed_build_stop' ;
2653- axiosPostStub . resolves ( non_200_status_response ) ;
2652+ let requestStub = sinon . stub ( request , 'post' ) . yields ( undefined , non_200_status_response , JSON . stringify ( body ) ) ;
26542653 await utils . stopBrowserStackBuild ( bsConfig , args , buildId , rawArgs ) ;
2655- sinon . assert . calledOnce ( axiosPostStub ) ;
2654+ sinon . assert . calledOnce ( requestStub ) ;
26562655 sinon . assert . calledOnce ( getUserAgentStub ) ;
26572656 sinon . assert . calledOnceWithExactly ( sendUsageReportStub , bsConfig , args , message , messageType , errorCode , null , rawArgs ) ;
2657+ requestStub . restore ( ) ;
26582658 } ) ;
26592659
26602660 it ( 'message thrown if API success' , async ( ) => {
26612661 let success_response = {
2662- status : 200 ,
2663- data : body
2662+ statusCode : 200 ,
26642663 }
26652664
26662665 message = `${ JSON . stringify ( body , null , 2 ) } ` ;
26672666 messageType = constant . messageTypes . SUCCESS ;
26682667 errorCode = null ;
2669- axiosPostStub . resolves ( success_response ) ;
2668+ let requestStub = sinon . stub ( request , 'post' ) . yields ( undefined , success_response , JSON . stringify ( body ) ) ;
26702669 await utils . stopBrowserStackBuild ( bsConfig , args , buildId , rawArgs ) ;
2671- sinon . assert . calledOnce ( axiosPostStub ) ;
2670+ sinon . assert . calledOnce ( requestStub ) ;
26722671 sinon . assert . calledOnce ( getUserAgentStub ) ;
26732672 sinon . assert . calledOnceWithExactly ( sendUsageReportStub , bsConfig , args , message , messageType , errorCode , null , rawArgs ) ;
2673+ requestStub . restore ( ) ;
26742674 } ) ;
26752675 } ) ;
26762676
0 commit comments