diff --git a/bin/helpers/zipUpload.js b/bin/helpers/zipUpload.js index 654dd481..320caa16 100644 --- a/bin/helpers/zipUpload.js +++ b/bin/helpers/zipUpload.js @@ -37,10 +37,14 @@ const uploadCypressZip = (bsConfig, filePath) => { responseData = null } if (resp.statusCode != 200) { - if (responseData && responseData["error"]) { + if(responseData && responseData["error"]){ reject(responseData["error"]); } else { - reject(Constants.userMessages.ZIP_UPLOADER_NOT_REACHABLE); + if(resp.statusCode == 401){ + reject(Constants.validationMessages.INVALID_DEFAULT_AUTH_PARAMS); + } else { + reject(Constants.userMessages.ZIP_UPLOADER_NOT_REACHABLE); + } } } else { logger.info(`Uploaded tests successfully (${responseData.zip_url})`); diff --git a/test/unit/bin/helpers/zipUpload.js b/test/unit/bin/helpers/zipUpload.js index a2b3e5b5..6d547686 100644 --- a/test/unit/bin/helpers/zipUpload.js +++ b/test/unit/bin/helpers/zipUpload.js @@ -55,7 +55,7 @@ describe("zipUpload", () => { }); }); - it("reject with error (if error present in response) if statusCode != 200", () => { + it("reject with error (if error present in response) if statusCode == 401", () => { let error = "non 200 code"; let requestStub = sandbox @@ -82,7 +82,7 @@ describe("zipUpload", () => { }); }); - it("reject with message if statusCode != 200 and error not in response", () => { + it("reject with message if statusCode == 401 and error not in response", () => { let requestStub = sandbox .stub(request, "post") .yields( @@ -98,6 +98,65 @@ describe("zipUpload", () => { request: { post: requestStub }, }); + return zipUploader + .zipUpload(bsConfig, "./random_file_path") + .then(function (data) { + chai.assert.fail("Promise error"); + }) + .catch((error) => { + sinon.assert.calledOnce(requestStub); + sinon.assert.calledOnce(getUserAgentStub); + sinon.assert.calledOnce(createReadStreamStub); + chai.assert.equal( + error, + Constants.validationMessages.INVALID_DEFAULT_AUTH_PARAMS + ); + }); + }); + + it("reject with error (if error present in response) if statusCode != 200 and statusCode != 401", () => { + let error = "non 200 and non 401 code"; + + let requestStub = sandbox + .stub(request, "post") + .yields(null, { statusCode: 404 }, JSON.stringify({ error: error })); + + const zipUploader = proxyquire("../../../../bin/helpers/zipUpload", { + "./utils": { + getUserAgent: getUserAgentStub, + }, + request: { post: requestStub }, + }); + + return zipUploader + .zipUpload(bsConfig, "./random_file_path") + .then(function (data) { + chai.assert.fail("Promise error"); + }) + .catch((error) => { + sinon.assert.calledOnce(requestStub); + sinon.assert.calledOnce(getUserAgentStub); + sinon.assert.calledOnce(createReadStreamStub); + chai.assert.equal(error, "non 200 and non 401 code"); + }); + }); + + it("reject with message if statusCode != 200 and statusCode != 401 and error not in response", () => { + let requestStub = sandbox + .stub(request, "post") + .yields( + null, + { statusCode: 404 }, + JSON.stringify({ message: "random message" }) + ); + + const zipUploader = proxyquire("../../../../bin/helpers/zipUpload", { + "./utils": { + getUserAgent: getUserAgentStub, + }, + request: { post: requestStub }, + }); + return zipUploader .zipUpload(bsConfig, "./random_file_path") .then(function (data) {