@@ -11,8 +11,7 @@ const chai = require('chai'),
11
11
chalk = require ( 'chalk' ) ,
12
12
os = require ( "os" ) ,
13
13
crypto = require ( 'crypto' ) ,
14
- fs = require ( 'fs' ) ,
15
- axios = require ( 'axios' ) ;
14
+ fs = require ( 'fs' ) ;
16
15
const getmac = require ( 'getmac' ) . default ;
17
16
const usageReporting = require ( '../../../../bin/helpers/usageReporting' ) ;
18
17
const utils = require ( '../../../../bin/helpers/utils' ) ,
@@ -2555,75 +2554,75 @@ describe('utils', () => {
2555
2554
} ) ;
2556
2555
2557
2556
describe ( 'stopBrowserStackBuild' , ( ) => {
2558
- let axiosPostStub , getUserAgentStub , sendUsageReportStub , message , messageType , errorCode ;
2557
+ let getUserAgentStub , sendUsageReportStub , message , messageType , errorCode ;
2559
2558
let bsConfig = testObjects . sampleBsConfig ;
2560
2559
let args = { } ;
2561
2560
let rawArgs = { } ;
2562
2561
let buildId = 'build_id' ;
2563
2562
let body = testObjects . buildStopSampleBody ;
2564
2563
2565
2564
beforeEach ( ( ) => {
2566
- axiosPostStub = sandbox . stub ( axios , "post" ) ;
2567
2565
getUserAgentStub = sinon . stub ( utils , 'getUserAgent' ) . returns ( 'user-agent' ) ;
2568
2566
sendUsageReportStub = sinon . stub ( utils , 'sendUsageReport' ) ;
2569
2567
} ) ;
2570
2568
afterEach ( ( ) => {
2571
- axiosPostStub . restore ( ) ;
2572
2569
getUserAgentStub . restore ( ) ;
2573
2570
sendUsageReportStub . restore ( ) ;
2574
2571
sandbox . restore ( ) ;
2575
2572
} )
2576
2573
2577
2574
it ( 'message thrown if API deprecated' , async ( ) => {
2578
2575
let api_deprecated_response = {
2579
- status : 299
2576
+ statusCode : 299
2580
2577
}
2581
2578
message = constant . userMessages . API_DEPRECATED ;
2582
2579
messageType = constant . messageTypes . INFO ;
2583
2580
errorCode = 'api_deprecated' ;
2584
- axiosPostStub . resolves ( api_deprecated_response ) ;
2581
+ let requestStub = sinon . stub ( request , 'post' ) . yields ( undefined , api_deprecated_response , null ) ;
2585
2582
await utils . stopBrowserStackBuild ( bsConfig , args , buildId , rawArgs ) ;
2586
- sinon . assert . calledOnce ( axiosPostStub ) ;
2583
+ sinon . assert . calledOnce ( requestStub ) ;
2587
2584
sinon . assert . calledOnce ( getUserAgentStub ) ;
2588
2585
sinon . assert . calledOnceWithExactly ( sendUsageReportStub , bsConfig , args , message , messageType , errorCode , null , rawArgs ) ;
2586
+ requestStub . restore ( ) ;
2589
2587
} ) ;
2590
2588
2591
2589
it ( 'message thrown if build returned' , async ( ) => {
2592
2590
let api_deprecated_response = {
2593
- status : 299 ,
2594
- data : body
2591
+ statusCode : 299 ,
2595
2592
}
2596
2593
message = body . message ;
2597
2594
messageType = constant . messageTypes . INFO ;
2598
2595
errorCode = 'api_deprecated' ;
2599
- axiosPostStub . resolves ( api_deprecated_response ) ;
2596
+ let requestStub = sinon . stub ( request , 'post' ) . yields ( undefined , api_deprecated_response , JSON . stringify ( body ) ) ;
2600
2597
await utils . stopBrowserStackBuild ( bsConfig , args , buildId , rawArgs ) ;
2601
- sinon . assert . calledOnce ( axiosPostStub ) ;
2598
+ sinon . assert . calledOnce ( requestStub ) ;
2602
2599
sinon . assert . calledOnce ( getUserAgentStub ) ;
2603
2600
sinon . assert . calledOnceWithExactly ( sendUsageReportStub , bsConfig , args , message , messageType , errorCode , null , rawArgs ) ;
2601
+ requestStub . restore ( ) ;
2604
2602
} ) ;
2605
2603
2606
2604
it ( 'message thrown if statusCode != 200' , async ( ) => {
2607
2605
let non_200_status_response = {
2608
- status : 400
2606
+ statusCode : 400
2609
2607
}
2610
2608
message = constant . userMessages . BUILD_STOP_FAILED ;
2611
2609
messageType = constant . messageTypes . ERROR ;
2612
2610
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 ) ;
2614
2612
await utils . stopBrowserStackBuild ( bsConfig , args , buildId , rawArgs ) ;
2615
- sinon . assert . calledOnce ( axiosPostStub ) ;
2613
+ sinon . assert . calledOnce ( requestStub ) ;
2616
2614
sinon . assert . calledOnce ( getUserAgentStub ) ;
2617
2615
sinon . assert . calledOnceWithExactly ( sendUsageReportStub , bsConfig , args , message , messageType , errorCode , null , rawArgs ) ;
2616
+ requestStub . restore ( ) ;
2618
2617
} ) ;
2619
2618
2620
2619
it ( 'message thrown if statusCode != 200 and user unauthorized' , async ( ) => {
2621
2620
let body_with_message = {
2622
2621
...body ,
2623
- message : "Unauthorized" ,
2622
+ " message" : "Unauthorized" ,
2624
2623
} ;
2625
2624
let non_200_status_response = {
2626
- status : 401 ,
2625
+ statusCode : 401 ,
2627
2626
data : body_with_message
2628
2627
}
2629
2628
@@ -2632,45 +2631,46 @@ describe('utils', () => {
2632
2631
} with error: \n${ JSON . stringify ( body_with_message , null , 2 ) } `;
2633
2632
messageType = constant . messageTypes . ERROR ;
2634
2633
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 ) ) ;
2636
2635
await utils . stopBrowserStackBuild ( bsConfig , args , buildId , rawArgs ) ;
2637
- sinon . assert . calledOnce ( axiosPostStub ) ;
2636
+ sinon . assert . calledOnce ( requestStub ) ;
2638
2637
sinon . assert . calledOnce ( getUserAgentStub ) ;
2639
2638
sinon . assert . calledOnceWithExactly ( sendUsageReportStub , bsConfig , args , message , messageType , errorCode , null , rawArgs ) ;
2639
+ requestStub . restore ( ) ;
2640
2640
} ) ;
2641
2641
2642
2642
it ( 'message thrown if statusCode != 200 and build is present' , async ( ) => {
2643
2643
let non_200_status_response = {
2644
- status : 402 ,
2645
- data : body
2644
+ statusCode : 402 ,
2646
2645
}
2647
2646
2648
2647
message = `${
2649
2648
constant . userMessages . BUILD_STOP_FAILED
2650
2649
} with error: \n${ JSON . stringify ( body , null , 2 ) } `;
2651
2650
messageType = constant . messageTypes . ERROR ;
2652
2651
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 ) ) ;
2654
2653
await utils . stopBrowserStackBuild ( bsConfig , args , buildId , rawArgs ) ;
2655
- sinon . assert . calledOnce ( axiosPostStub ) ;
2654
+ sinon . assert . calledOnce ( requestStub ) ;
2656
2655
sinon . assert . calledOnce ( getUserAgentStub ) ;
2657
2656
sinon . assert . calledOnceWithExactly ( sendUsageReportStub , bsConfig , args , message , messageType , errorCode , null , rawArgs ) ;
2657
+ requestStub . restore ( ) ;
2658
2658
} ) ;
2659
2659
2660
2660
it ( 'message thrown if API success' , async ( ) => {
2661
2661
let success_response = {
2662
- status : 200 ,
2663
- data : body
2662
+ statusCode : 200 ,
2664
2663
}
2665
2664
2666
2665
message = `${ JSON . stringify ( body , null , 2 ) } ` ;
2667
2666
messageType = constant . messageTypes . SUCCESS ;
2668
2667
errorCode = null ;
2669
- axiosPostStub . resolves ( success_response ) ;
2668
+ let requestStub = sinon . stub ( request , 'post' ) . yields ( undefined , success_response , JSON . stringify ( body ) ) ;
2670
2669
await utils . stopBrowserStackBuild ( bsConfig , args , buildId , rawArgs ) ;
2671
- sinon . assert . calledOnce ( axiosPostStub ) ;
2670
+ sinon . assert . calledOnce ( requestStub ) ;
2672
2671
sinon . assert . calledOnce ( getUserAgentStub ) ;
2673
2672
sinon . assert . calledOnceWithExactly ( sendUsageReportStub , bsConfig , args , message , messageType , errorCode , null , rawArgs ) ;
2673
+ requestStub . restore ( ) ;
2674
2674
} ) ;
2675
2675
} ) ;
2676
2676
0 commit comments