Skip to content
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
11 changes: 11 additions & 0 deletions bin/helpers/reporterHTML.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,17 @@ let reportGenerator = (bsConfig, buildId, args, cb) => {
message = Constants.userMessages.API_DEPRECATED;
logger.info(message);
}
} else if (resp.statusCode === 422) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add test cases for this

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

messageType = Constants.messageTypes.ERROR;
errorCode = 'api_failed_build_generate_report';
try {
response = JSON.parse(body);
message = response.message;
} catch (error) {
logger.error(`Error generating the report: ${error}`);
response = {message: message};
}
logger.error(response.message);
} else if (resp.statusCode != 200) {
messageType = Constants.messageTypes.ERROR;
errorCode = 'api_failed_build_generate_report';
Expand Down
31 changes: 31 additions & 0 deletions test/unit/bin/helpers/reporterHTML.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,37 @@ describe("reportHTML", () => {
});

context("non 200 response", () => {
it("422 status, build available but running, cannot generate report", () => {
let build = { message: 'The report cannot be generated as the build is running' };
let body = JSON.stringify(build);
let requestStub = sandbox.stub(request, "get").yields(null, { statusCode: 422 }, body);
let message = build.message;
let messageType = Constants.messageTypes.ERROR;
let errorCode = 'api_failed_build_generate_report';

const reporterHTML = proxyquire('../../../../bin/helpers/reporterHTML', {
'./utils': {
validateBstackJson: validateBstackJsonStub,
setDefaultAuthHash: setDefaultAuthHashStub,
setUsername: setUsernameStub,
setAccessKey: setAccessKeyStub,
getUserAgent: getUserAgentStub,
setUsageReportingFlag: setUsageReportingFlagStub,
setCypressConfigFilename: setCypressConfigFilenameStub,
sendUsageReport: sendUsageReportStub,
setDefaults: setDefaultsStub,
getErrorCodeFromErr: getErrorCodeFromErrStub
},
request: {get: requestStub}
});

reporterHTML.reportGenerator(bsConfig, buildId, args);

sinon.assert.calledOnce(requestStub);
sinon.assert.calledOnce(getUserAgentStub);
sinon.assert.calledOnceWithExactly(sendUsageReportStub, bsConfig, args, message, messageType, errorCode);
});

it("400 status, build available, cannot generate report", () => {
let build = { buildId: buildId, message: 'success', rows: [] };
let body = JSON.stringify(build);
Expand Down