Skip to content

Commit a68b09d

Browse files
Moving the defaultAuthHash outside setUsername
1 parent 7180bc0 commit a68b09d

File tree

4 files changed

+511
-349
lines changed

4 files changed

+511
-349
lines changed

bin/commands/runs.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ module.exports = function run(args) {
1717
return utils.validateBstackJson(bsConfigPath).then(function (bsConfig) {
1818
utils.setUsageReportingFlag(bsConfig, args.disableUsageReporting);
1919

20+
// setting defaultAuthHash to {} if not present and set via env variables or via args.
21+
utils.defaultAuthHash(bsConfig,args);
22+
2023
// accept the username from command line or env variable if provided
2124
utils.setUsername(bsConfig, args);
2225

bin/helpers/utils.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,10 +115,17 @@ exports.setParallels = (bsConfig, args) => {
115115
}
116116
};
117117

118-
exports.setUsername = (bsConfig, args) => {
119-
if (this.isUndefined(bsConfig['auth']) && (!this.isUndefined(args.username) || !this.isUndefined(process.env.BROWSERSTACK_USERNAME))) {
118+
exports.defaultAuthHash = (bsConfig, args) => {
119+
if (
120+
this.isUndefined(bsConfig['auth']) &&
121+
(!this.isUndefined(args.username) ||
122+
!this.isUndefined(process.env.BROWSERSTACK_USERNAME))
123+
) {
120124
bsConfig['auth'] = {};
121125
}
126+
}
127+
128+
exports.setUsername = (bsConfig, args) => {
122129
if (!this.isUndefined(args.username)) {
123130
bsConfig["auth"]["username"] = args.username;
124131
} else if (!this.isUndefined(process.env.BROWSERSTACK_USERNAME)) {

test/unit/bin/commands/runs.js

Lines changed: 44 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ describe("runs", () => {
4040
let messageType = Constants.messageTypes.ERROR;
4141
let errorCode = "random-error-code";
4242

43-
const runs = proxyquire("../../../../bin/commands/runs", {
44-
"../helpers/utils": {
43+
const runs = proxyquire('../../../../bin/commands/runs', {
44+
'../helpers/utils': {
4545
validateBstackJson: validateBstackJsonStub,
4646
getErrorCodeFromErr: getErrorCodeFromErrStub,
4747
sendUsageReport: sendUsageReportStub,
@@ -98,6 +98,7 @@ describe("runs", () => {
9898
setLocalStub = sandbox.stub();
9999
setLocalIdentifierStub = sandbox.stub();
100100
deleteResultsStub = sandbox.stub();
101+
defaultAuthHashStub = sandbox.stub();
101102
});
102103

103104
afterEach(() => {
@@ -110,8 +111,8 @@ describe("runs", () => {
110111
let messageType = Constants.messageTypes.ERROR;
111112
let errorCode = "random-error-code";
112113

113-
const runs = proxyquire("../../../../bin/commands/runs", {
114-
"../helpers/utils": {
114+
const runs = proxyquire('../../../../bin/commands/runs', {
115+
'../helpers/utils': {
115116
validateBstackJson: validateBstackJsonStub,
116117
getErrorCodeFromMsg: getErrorCodeFromMsgStub,
117118
sendUsageReport: sendUsageReportStub,
@@ -125,9 +126,10 @@ describe("runs", () => {
125126
getConfigPath: getConfigPathStub,
126127
setLocal: setLocalStub,
127128
setLocalIdentifier: setLocalIdentifierStub,
128-
deleteResults: deleteResultsStub
129+
deleteResults: deleteResultsStub,
130+
defaultAuthHash: defaultAuthHashStub
129131
},
130-
"../helpers/capabilityHelper": {
132+
'../helpers/capabilityHelper': {
131133
validate: capabilityValidatorStub,
132134
},
133135
});
@@ -149,6 +151,7 @@ describe("runs", () => {
149151
sinon.assert.calledOnce(setLocalStub);
150152
sinon.assert.calledOnce(setLocalIdentifierStub);
151153
sinon.assert.calledOnce(deleteResultsStub);
154+
sinon.assert.calledOnce(defaultAuthHashStub);
152155
sinon.assert.calledOnceWithExactly(
153156
sendUsageReportStub,
154157
bsConfig,
@@ -185,6 +188,7 @@ describe("runs", () => {
185188
setLocalStub = sandbox.stub();
186189
setLocalIdentifierStub = sandbox.stub();
187190
deleteResultsStub = sandbox.stub();
191+
defaultAuthHashStub = sandbox.stub();
188192
});
189193

190194
afterEach(() => {
@@ -197,8 +201,8 @@ describe("runs", () => {
197201
let messageType = Constants.messageTypes.ERROR;
198202
let errorCode = "zip_creation_failed";
199203

200-
const runs = proxyquire("../../../../bin/commands/runs", {
201-
"../helpers/utils": {
204+
const runs = proxyquire('../../../../bin/commands/runs', {
205+
'../helpers/utils': {
202206
validateBstackJson: validateBstackJsonStub,
203207
sendUsageReport: sendUsageReportStub,
204208
setParallels: setParallelsStub,
@@ -212,17 +216,18 @@ describe("runs", () => {
212216
getConfigPath: getConfigPathStub,
213217
setLocal: setLocalStub,
214218
setLocalIdentifier: setLocalIdentifierStub,
215-
deleteResults: deleteResultsStub
219+
deleteResults: deleteResultsStub,
220+
defaultAuthHash: defaultAuthHashStub
216221
},
217-
"../helpers/capabilityHelper": {
222+
'../helpers/capabilityHelper': {
218223
validate: capabilityValidatorStub,
219224
},
220-
"../helpers/archiver": {
225+
'../helpers/archiver': {
221226
archive: archiverStub,
222227
},
223-
"../helpers/fileHelpers": {
224-
deleteZip: deleteZipStub
225-
}
228+
'../helpers/fileHelpers': {
229+
deleteZip: deleteZipStub,
230+
},
226231
});
227232

228233
validateBstackJsonStub.returns(Promise.resolve(bsConfig));
@@ -245,6 +250,7 @@ describe("runs", () => {
245250
sinon.assert.calledOnce(setUsageReportingFlagStub);
246251
sinon.assert.calledOnce(deleteZipStub);
247252
sinon.assert.calledOnce(deleteResultsStub);
253+
sinon.assert.calledOnce(defaultAuthHashStub);
248254
sinon.assert.calledOnceWithExactly(
249255
sendUsageReportStub,
250256
bsConfig,
@@ -282,6 +288,7 @@ describe("runs", () => {
282288
setLocalStub = sandbox.stub();
283289
setLocalIdentifierStub = sandbox.stub();
284290
deleteResultsStub = sandbox.stub();
291+
defaultAuthHashStub = sandbox.stub();
285292
});
286293

287294
afterEach(() => {
@@ -294,8 +301,8 @@ describe("runs", () => {
294301
let messageType = Constants.messageTypes.ERROR;
295302
let errorCode = "zip_upload_failed";
296303

297-
const runs = proxyquire("../../../../bin/commands/runs", {
298-
"../helpers/utils": {
304+
const runs = proxyquire('../../../../bin/commands/runs', {
305+
'../helpers/utils': {
299306
validateBstackJson: validateBstackJsonStub,
300307
sendUsageReport: sendUsageReportStub,
301308
setParallels: setParallelsStub,
@@ -309,18 +316,19 @@ describe("runs", () => {
309316
getConfigPath: getConfigPathStub,
310317
setLocal: setLocalStub,
311318
setLocalIdentifier: setLocalIdentifierStub,
312-
deleteResults: deleteResultsStub
319+
deleteResults: deleteResultsStub,
320+
defaultAuthHash: defaultAuthHashStub
313321
},
314-
"../helpers/capabilityHelper": {
322+
'../helpers/capabilityHelper': {
315323
validate: capabilityValidatorStub,
316324
},
317-
"../helpers/archiver": {
325+
'../helpers/archiver': {
318326
archive: archiverStub,
319327
},
320-
"../helpers/fileHelpers": {
328+
'../helpers/fileHelpers': {
321329
deleteZip: deleteZipStub,
322330
},
323-
"../helpers/zipUpload": {
331+
'../helpers/zipUpload': {
324332
zipUpload: zipUploadStub,
325333
},
326334
});
@@ -346,6 +354,7 @@ describe("runs", () => {
346354
sinon.assert.calledOnce(setUsageReportingFlagStub);
347355
sinon.assert.calledOnce(zipUploadStub);
348356
sinon.assert.calledOnce(deleteResultsStub);
357+
sinon.assert.calledOnce(defaultAuthHashStub);
349358
sinon.assert.calledOnceWithExactly(
350359
sendUsageReportStub,
351360
bsConfig,
@@ -387,6 +396,7 @@ describe("runs", () => {
387396
setLocalStub = sandbox.stub();
388397
setLocalIdentifierStub = sandbox.stub();
389398
deleteResultsStub = sandbox.stub();
399+
defaultAuthHashStub = sandbox.stub();
390400
});
391401

392402
afterEach(() => {
@@ -399,8 +409,8 @@ describe("runs", () => {
399409
let messageType = Constants.messageTypes.ERROR;
400410
let errorCode = "build_failed";
401411

402-
const runs = proxyquire("../../../../bin/commands/runs", {
403-
"../helpers/utils": {
412+
const runs = proxyquire('../../../../bin/commands/runs', {
413+
'../helpers/utils': {
404414
validateBstackJson: validateBstackJsonStub,
405415
sendUsageReport: sendUsageReportStub,
406416
setParallels: setParallelsStub,
@@ -414,21 +424,22 @@ describe("runs", () => {
414424
getConfigPath: getConfigPathStub,
415425
setLocal: setLocalStub,
416426
setLocalIdentifier: setLocalIdentifierStub,
417-
deleteResults: deleteResultsStub
427+
deleteResults: deleteResultsStub,
428+
defaultAuthHash: defaultAuthHashStub
418429
},
419-
"../helpers/capabilityHelper": {
430+
'../helpers/capabilityHelper': {
420431
validate: capabilityValidatorStub,
421432
},
422-
"../helpers/archiver": {
433+
'../helpers/archiver': {
423434
archive: archiverStub,
424435
},
425-
"../helpers/fileHelpers": {
436+
'../helpers/fileHelpers': {
426437
deleteZip: deleteZipStub,
427438
},
428-
"../helpers/zipUpload": {
439+
'../helpers/zipUpload': {
429440
zipUpload: zipUploadStub,
430441
},
431-
"../helpers/build": {
442+
'../helpers/build': {
432443
createBuild: createBuildStub,
433444
},
434445
});
@@ -460,6 +471,7 @@ describe("runs", () => {
460471

461472
sinon.assert.calledOnce(sendUsageReportStub);
462473
sinon.assert.calledOnce(deleteResultsStub);
474+
sinon.assert.calledOnce(defaultAuthHashStub);
463475

464476
sinon.assert.calledOnceWithExactly(
465477
sendUsageReportStub,
@@ -503,6 +515,7 @@ describe("runs", () => {
503515
deleteZipStub = sandbox.stub();
504516
exportResultsStub = sandbox.stub();
505517
deleteResultsStub = sandbox.stub();
518+
defaultAuthHashStub = sandbox.stub();
506519
isUndefinedStub = sandbox.stub();
507520
setLocalStub = sandbox.stub();
508521
setLocalIdentifierStub = sandbox.stub();
@@ -536,6 +549,7 @@ describe("runs", () => {
536549
setLocalIdentifier: setLocalIdentifierStub,
537550
exportResults: exportResultsStub,
538551
deleteResults: deleteResultsStub,
552+
defaultAuthHash: defaultAuthHashStub,
539553
isUndefined: isUndefinedStub
540554
},
541555
"../helpers/capabilityHelper": {
@@ -584,6 +598,7 @@ describe("runs", () => {
584598
sinon.assert.calledOnce(createBuildStub);
585599
sinon.assert.calledOnce(exportResultsStub);
586600
sinon.assert.calledOnce(deleteResultsStub);
601+
sinon.assert.calledOnce(defaultAuthHashStub);
587602
sinon.assert.calledOnceWithExactly(
588603
sendUsageReportStub,
589604
bsConfig,

0 commit comments

Comments
 (0)