Skip to content

Commit

Permalink
Merge pull request #37 from browserstack/CYP_281_link
Browse files Browse the repository at this point in the history
Add link to dashboard on build creation
  • Loading branch information
suryart committed Jul 15, 2020
2 parents 843c6f1 + 339936e commit ffe5723
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 14 deletions.
7 changes: 5 additions & 2 deletions bin/commands/runs.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@ module.exports = function run(args) {
return zipUploader.zipUpload(bsConfig, config.fileName).then(function (zip) {

// Create build
return build.createBuild(bsConfig, zip).then(function (message) {
return build.createBuild(bsConfig, zip).then(function (data) {
let message = `${data.message}! ${Constants.userMessages.BUILD_CREATED} with build id: ${data.build_id}`;
let dashboardLink = `${Constants.userMessages.VISIT_DASHBOARD} ${config.dashboardUrl}${data.build_id}`;
logger.info(message);
utils.sendUsageReport(bsConfig, args, message, Constants.messageTypes.SUCCESS, null);
logger.info(dashboardLink);
utils.sendUsageReport(bsConfig, args, `${message}\n${dashboardLink}`, Constants.messageTypes.SUCCESS, null);
return;
}).catch(function (err) {
// Build creation failed
Expand Down
4 changes: 2 additions & 2 deletions bin/helpers/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const request = require('request');
const config = require('./config'),
capabilityHelper = require("../helpers/capabilityHelper"),
Constants = require('../helpers/constants'),
utils =require('../helpers/utils');
utils = require('../helpers/utils');

const createBuild = (bsConfig, zip) => {
return new Promise(function (resolve, reject) {
Expand Down Expand Up @@ -46,7 +46,7 @@ const createBuild = (bsConfig, zip) => {
reject(Constants.userMessages.BUILD_FAILED);
}
} else {
resolve(`${build.message}! ${Constants.userMessages.BUILD_CREATED} with build id: ${build.build_id}`);
resolve(build);
}
resolve(build);
}
Expand Down
1 change: 1 addition & 0 deletions bin/helpers/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ config.rails_host = hosts[config.env].rails_host;
config.cypress_v1 = `${config.rails_host}/automate/cypress/v1`;
config.buildUrl = `${config.cypress_v1}/builds/`;
config.buildStopUrl = `${config.cypress_v1}/builds/stop/`;
config.dashboardUrl = `https://automate.browserstack.com/dashboard/v2/builds/`;
config.usageReportingUrl = `https://eds.browserstack.com:443/send_event_cy_internal`;
config.fileName = "tests.zip";

Expand Down
3 changes: 2 additions & 1 deletion bin/helpers/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@ const userMessages = {
ZIP_DELETE_FAILED: "Could not delete local file.",
ZIP_DELETED: "Zip file deleted successfully.",
API_DEPRECATED: "This version of API is deprecated, please use latest version of API.",
FAILED_TO_ZIP: "Failed to zip files."
FAILED_TO_ZIP: "Failed to zip files.",
VISIT_DASHBOARD: "Visit the Automate dashboard for test reporting:"
};

const validationMessages = {
Expand Down
11 changes: 8 additions & 3 deletions test/unit/bin/commands/runs.js
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ describe("runs", () => {
sendUsageReportStub = sandbox.stub().callsFake(function () {
return "end";
});
dashboardUrl = "dashboard-url";
capabilityValidatorStub = sandbox.stub();
archiverStub = sandbox.stub();
zipUploadStub = sandbox.stub();
Expand All @@ -422,9 +423,10 @@ describe("runs", () => {
});

it("send error report", () => {
let message = "build created";
let messageType = Constants.messageTypes.SUCCESS;
let errorCode = null;
let message = `Success! ${Constants.userMessages.BUILD_CREATED} with build id: random_build_id`;
let dashboardLink = `${Constants.userMessages.VISIT_DASHBOARD} ${dashboardUrl}random_build_id`;

const runs = proxyquire("../../../../bin/commands/runs", {
"../helpers/utils": {
Expand All @@ -451,6 +453,9 @@ describe("runs", () => {
"../helpers/build": {
createBuild: createBuildStub,
},
"../helpers/config": {
dashboardUrl: dashboardUrl,
},
});

validateBstackJsonStub.returns(Promise.resolve(bsConfig));
Expand All @@ -459,7 +464,7 @@ describe("runs", () => {
);
archiverStub.returns(Promise.resolve("Zipping completed"));
zipUploadStub.returns(Promise.resolve("zip uploaded"));
createBuildStub.returns(Promise.resolve("build created"));
createBuildStub.returns(Promise.resolve({ message: 'Success', build_id: 'random_build_id' }));

return runs(args)
.then(function (_bsConfig) {
Expand All @@ -478,7 +483,7 @@ describe("runs", () => {
sendUsageReportStub,
bsConfig,
args,
message,
`${message}\n${dashboardLink}`,
messageType,
errorCode
);
Expand Down
14 changes: 8 additions & 6 deletions test/unit/bin/helpers/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,13 +176,12 @@ describe("build", () => {
it("build created successfuly", () => {
let build_id = "random build id";
let build_message = "success"
let requestData = { message: build_message, build_id: build_id };
let requestStub = sandbox
.stub(request, "post")
.yields(
null,
{ statusCode: 201 },
JSON.stringify({ message: build_message, build_id: build_id })
);
.yields(null, { statusCode: 201 }, JSON.stringify(requestData));

let dashboardUrl = "dashboard-url";

const build = proxyquire("../../../../bin/helpers/build", {
"../helpers/utils": {
Expand All @@ -191,6 +190,9 @@ describe("build", () => {
"../helpers/capabilityHelper": {
caps: capsStub,
},
"./config": {
dashboardUrl: dashboardUrl,
},
request: { post: requestStub },
});

Expand All @@ -199,7 +201,7 @@ describe("build", () => {
.then(function (data) {
sinon.assert.calledOnce(requestStub);
sinon.assert.calledOnce(getUserAgentStub);
chai.assert.equal(data, `${build_message}! ${Constants.userMessages.BUILD_CREATED} with build id: ${build_id}`);
chai.assert.equal(data, `${requestData}`);
})
.catch((error) => {
chai.assert.isNotOk(error, "Promise error");
Expand Down

0 comments on commit ffe5723

Please sign in to comment.