Skip to content

error shown if username or password not given #118

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Mar 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions bin/helpers/zipUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -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})`);
Expand Down
63 changes: 61 additions & 2 deletions test/unit/bin/helpers/zipUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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(
Expand All @@ -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) {
Expand Down