@@ -55,7 +55,7 @@ describe("zipUpload", () => {
5555 } ) ;
5656 } ) ;
5757
58- it ( "reject with error (if error present in response) if statusCode != 200 " , ( ) => {
58+ it ( "reject with error (if error present in response) if statusCode == 401 " , ( ) => {
5959 let error = "non 200 code" ;
6060
6161 let requestStub = sandbox
@@ -82,7 +82,7 @@ describe("zipUpload", () => {
8282 } ) ;
8383 } ) ;
8484
85- it ( "reject with message if statusCode != 200 and error not in response" , ( ) => {
85+ it ( "reject with message if statusCode == 401 and error not in response" , ( ) => {
8686 let requestStub = sandbox
8787 . stub ( request , "post" )
8888 . yields (
@@ -98,6 +98,65 @@ describe("zipUpload", () => {
9898 request : { post : requestStub } ,
9999 } ) ;
100100
101+ return zipUploader
102+ . zipUpload ( bsConfig , "./random_file_path" )
103+ . then ( function ( data ) {
104+ chai . assert . fail ( "Promise error" ) ;
105+ } )
106+ . catch ( ( error ) => {
107+ sinon . assert . calledOnce ( requestStub ) ;
108+ sinon . assert . calledOnce ( getUserAgentStub ) ;
109+ sinon . assert . calledOnce ( createReadStreamStub ) ;
110+ chai . assert . equal (
111+ error ,
112+ Constants . validationMessages . INVALID_DEFAULT_AUTH_PARAMS
113+ ) ;
114+ } ) ;
115+ } ) ;
116+
117+ it ( "reject with error (if error present in response) if statusCode != 200 and statusCode != 401" , ( ) => {
118+ let error = "non 200 and non 401 code" ;
119+
120+ let requestStub = sandbox
121+ . stub ( request , "post" )
122+ . yields ( null , { statusCode : 404 } , JSON . stringify ( { error : error } ) ) ;
123+
124+ const zipUploader = proxyquire ( "../../../../bin/helpers/zipUpload" , {
125+ "./utils" : {
126+ getUserAgent : getUserAgentStub ,
127+ } ,
128+ request : { post : requestStub } ,
129+ } ) ;
130+
131+ return zipUploader
132+ . zipUpload ( bsConfig , "./random_file_path" )
133+ . then ( function ( data ) {
134+ chai . assert . fail ( "Promise error" ) ;
135+ } )
136+ . catch ( ( error ) => {
137+ sinon . assert . calledOnce ( requestStub ) ;
138+ sinon . assert . calledOnce ( getUserAgentStub ) ;
139+ sinon . assert . calledOnce ( createReadStreamStub ) ;
140+ chai . assert . equal ( error , "non 200 and non 401 code" ) ;
141+ } ) ;
142+ } ) ;
143+
144+ it ( "reject with message if statusCode != 200 and statusCode != 401 and error not in response" , ( ) => {
145+ let requestStub = sandbox
146+ . stub ( request , "post" )
147+ . yields (
148+ null ,
149+ { statusCode : 404 } ,
150+ JSON . stringify ( { message : "random message" } )
151+ ) ;
152+
153+ const zipUploader = proxyquire ( "../../../../bin/helpers/zipUpload" , {
154+ "./utils" : {
155+ getUserAgent : getUserAgentStub ,
156+ } ,
157+ request : { post : requestStub } ,
158+ } ) ;
159+
101160 return zipUploader
102161 . zipUpload ( bsConfig , "./random_file_path" )
103162 . then ( function ( data ) {
0 commit comments