Skip to content

Commit ffe5723

Browse files
authored
Merge pull request #37 from browserstack/CYP_281_link
Add link to dashboard on build creation
2 parents 843c6f1 + 339936e commit ffe5723

File tree

6 files changed

+26
-14
lines changed

6 files changed

+26
-14
lines changed

bin/commands/runs.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,12 @@ module.exports = function run(args) {
3838
return zipUploader.zipUpload(bsConfig, config.fileName).then(function (zip) {
3939

4040
// Create build
41-
return build.createBuild(bsConfig, zip).then(function (message) {
41+
return build.createBuild(bsConfig, zip).then(function (data) {
42+
let message = `${data.message}! ${Constants.userMessages.BUILD_CREATED} with build id: ${data.build_id}`;
43+
let dashboardLink = `${Constants.userMessages.VISIT_DASHBOARD} ${config.dashboardUrl}${data.build_id}`;
4244
logger.info(message);
43-
utils.sendUsageReport(bsConfig, args, message, Constants.messageTypes.SUCCESS, null);
45+
logger.info(dashboardLink);
46+
utils.sendUsageReport(bsConfig, args, `${message}\n${dashboardLink}`, Constants.messageTypes.SUCCESS, null);
4447
return;
4548
}).catch(function (err) {
4649
// Build creation failed

bin/helpers/build.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const request = require('request');
44
const config = require('./config'),
55
capabilityHelper = require("../helpers/capabilityHelper"),
66
Constants = require('../helpers/constants'),
7-
utils =require('../helpers/utils');
7+
utils = require('../helpers/utils');
88

99
const createBuild = (bsConfig, zip) => {
1010
return new Promise(function (resolve, reject) {
@@ -46,7 +46,7 @@ const createBuild = (bsConfig, zip) => {
4646
reject(Constants.userMessages.BUILD_FAILED);
4747
}
4848
} else {
49-
resolve(`${build.message}! ${Constants.userMessages.BUILD_CREATED} with build id: ${build.build_id}`);
49+
resolve(build);
5050
}
5151
resolve(build);
5252
}

bin/helpers/config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ config.rails_host = hosts[config.env].rails_host;
1111
config.cypress_v1 = `${config.rails_host}/automate/cypress/v1`;
1212
config.buildUrl = `${config.cypress_v1}/builds/`;
1313
config.buildStopUrl = `${config.cypress_v1}/builds/stop/`;
14+
config.dashboardUrl = `https://automate.browserstack.com/dashboard/v2/builds/`;
1415
config.usageReportingUrl = `https://eds.browserstack.com:443/send_event_cy_internal`;
1516
config.fileName = "tests.zip";
1617

bin/helpers/constants.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ const userMessages = {
1010
ZIP_DELETE_FAILED: "Could not delete local file.",
1111
ZIP_DELETED: "Zip file deleted successfully.",
1212
API_DEPRECATED: "This version of API is deprecated, please use latest version of API.",
13-
FAILED_TO_ZIP: "Failed to zip files."
13+
FAILED_TO_ZIP: "Failed to zip files.",
14+
VISIT_DASHBOARD: "Visit the Automate dashboard for test reporting:"
1415
};
1516

1617
const validationMessages = {

test/unit/bin/commands/runs.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -409,6 +409,7 @@ describe("runs", () => {
409409
sendUsageReportStub = sandbox.stub().callsFake(function () {
410410
return "end";
411411
});
412+
dashboardUrl = "dashboard-url";
412413
capabilityValidatorStub = sandbox.stub();
413414
archiverStub = sandbox.stub();
414415
zipUploadStub = sandbox.stub();
@@ -422,9 +423,10 @@ describe("runs", () => {
422423
});
423424

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

429431
const runs = proxyquire("../../../../bin/commands/runs", {
430432
"../helpers/utils": {
@@ -451,6 +453,9 @@ describe("runs", () => {
451453
"../helpers/build": {
452454
createBuild: createBuildStub,
453455
},
456+
"../helpers/config": {
457+
dashboardUrl: dashboardUrl,
458+
},
454459
});
455460

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

464469
return runs(args)
465470
.then(function (_bsConfig) {
@@ -478,7 +483,7 @@ describe("runs", () => {
478483
sendUsageReportStub,
479484
bsConfig,
480485
args,
481-
message,
486+
`${message}\n${dashboardLink}`,
482487
messageType,
483488
errorCode
484489
);

test/unit/bin/helpers/build.js

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,13 +176,12 @@ describe("build", () => {
176176
it("build created successfuly", () => {
177177
let build_id = "random build id";
178178
let build_message = "success"
179+
let requestData = { message: build_message, build_id: build_id };
179180
let requestStub = sandbox
180181
.stub(request, "post")
181-
.yields(
182-
null,
183-
{ statusCode: 201 },
184-
JSON.stringify({ message: build_message, build_id: build_id })
185-
);
182+
.yields(null, { statusCode: 201 }, JSON.stringify(requestData));
183+
184+
let dashboardUrl = "dashboard-url";
186185

187186
const build = proxyquire("../../../../bin/helpers/build", {
188187
"../helpers/utils": {
@@ -191,6 +190,9 @@ describe("build", () => {
191190
"../helpers/capabilityHelper": {
192191
caps: capsStub,
193192
},
193+
"./config": {
194+
dashboardUrl: dashboardUrl,
195+
},
194196
request: { post: requestStub },
195197
});
196198

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

0 commit comments

Comments
 (0)