Skip to content

Commit 86daff6

Browse files
committed
🎨 removed duplicate code
1 parent 0d298fa commit 86daff6

File tree

2 files changed

+10
-34
lines changed

2 files changed

+10
-34
lines changed

bin/helpers/utils.js

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -390,10 +390,6 @@ exports.setSpecTimeout = (bsConfig, args) => {
390390
logger.debug(`Setting spec timeout = ${specTimeout}`);
391391
}
392392

393-
exports.isTimezoneArgPassed = () => {
394-
return this.searchForOption('--timezone');
395-
}
396-
397393
exports.isValidTimezone = (timezone) => {
398394
if(!this.isUndefined(timezone) && !this.isUndefined(TIMEZONE[timezone])) {
399395
return true;
@@ -402,28 +398,17 @@ exports.isValidTimezone = (timezone) => {
402398
}
403399

404400
exports.setTimezone = (bsConfig, args) => {
405-
let timezone = undefined;
406-
if(this.isTimezoneArgPassed()) {
407-
if(this.isNotUndefined(args.timezone)) {
408-
if(this.isValidTimezone(args.timezone)){
409-
timezone = args.timezone;
410-
} else {
411-
logger.error(`Invalid timezone = ${args.timezone}`);
412-
syncCliLogger.info(chalk.red(Constants.userMessages.INVALID_TIMEZONE));
413-
process.exit(1);
414-
}
415-
}
416-
} else if (this.isNotUndefined(bsConfig.run_settings.timezone)) {
417-
if(this.isValidTimezone(bsConfig.run_settings.timezone)){
418-
timezone = bsConfig.run_settings.timezone;
419-
} else {
420-
logger.error(`Invalid timezone = ${bsConfig.run_settings.timezone}`);
421-
syncCliLogger.info(chalk.red(Constants.userMessages.INVALID_TIMEZONE));
422-
process.exit(1);
423-
}
401+
let timezone = args.timezone || bsConfig.run_settings.timezone;
402+
let newTimezone;
403+
if(this.isNotUndefined(timezone) && this.isValidTimezone(timezone)){
404+
newTimezone = timezone;
405+
} else {
406+
logger.error(`Invalid timezone = ${timezone}`);
407+
syncCliLogger.info(chalk.red(Constants.userMessages.INVALID_TIMEZONE));
408+
process.exit(1);
424409
}
425-
bsConfig.run_settings.timezone = timezone;
426-
logger.debug(`Setting timezone = ${timezone}`);
410+
bsConfig.run_settings.timezone = newTimezone;
411+
logger.debug(`Setting timezone = ${newTimezone}`);
427412
}
428413

429414
exports.setRecordFlag = (bsConfig, args) => {

test/unit/bin/helpers/utils.js

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3725,19 +3725,16 @@ describe('utils', () => {
37253725
});
37263726

37273727
describe("setTimezone", () => {
3728-
let isTimezoneArgPassed;
37293728
let processStub;
37303729
let loggerStub;
37313730
let syncCliLoggerStub;
37323731
beforeEach(() => {
3733-
isTimezoneArgPassed = sinon.stub(utils, 'isTimezoneArgPassed');
37343732
processStub = sinon.stub(process, 'exit');
37353733
loggerStub = sinon.stub(winstonLogger, 'error');
37363734
syncCliLoggerStub = sinon.stub(syncCliLogger, 'info');
37373735
});
37383736

37393737
afterEach(() => {
3740-
isTimezoneArgPassed.restore();
37413738
processStub.restore();
37423739
loggerStub.restore();
37433740
syncCliLoggerStub.restore();
@@ -3751,7 +3748,6 @@ describe('utils', () => {
37513748
let args = {
37523749
timezone: "New_York"
37533750
};
3754-
isTimezoneArgPassed.returns(true);
37553751
utils.setTimezone(bsConfig, args);
37563752
expect(bsConfig.run_settings.timezone).to.eq("New_York");
37573753
});
@@ -3763,7 +3759,6 @@ describe('utils', () => {
37633759
}
37643760
}
37653761
let args = {};
3766-
isTimezoneArgPassed.returns(true);
37673762
utils.setTimezone(bsConfig, args);
37683763
expect(bsConfig.run_settings.timezone).to.eq(undefined);
37693764
});
@@ -3777,7 +3772,6 @@ describe('utils', () => {
37773772
let args = {
37783773
timezone: "xyz"
37793774
};
3780-
isTimezoneArgPassed.returns(true);
37813775
utils.setTimezone(bsConfig, args);
37823776
expect(bsConfig.run_settings.timezone).to.eq(undefined);
37833777
sinon.assert.calledOnceWithExactly(loggerStub, "Invalid timezone = xyz");
@@ -3792,7 +3786,6 @@ describe('utils', () => {
37923786
}
37933787
}
37943788
let args = {};
3795-
isTimezoneArgPassed.returns(false);
37963789
utils.setTimezone(bsConfig, args);
37973790
expect(bsConfig.run_settings.timezone).to.eq(undefined);
37983791
sinon.assert.calledOnceWithExactly(loggerStub, "Invalid timezone = abc");
@@ -3807,7 +3800,6 @@ describe('utils', () => {
38073800
}
38083801
}
38093802
let args = {};
3810-
isTimezoneArgPassed.returns(false);
38113803
utils.setTimezone(bsConfig, args);
38123804
expect(bsConfig.run_settings.timezone).to.eq("London");
38133805
});
@@ -3817,7 +3809,6 @@ describe('utils', () => {
38173809
run_settings: {}
38183810
}
38193811
let args = {};
3820-
isTimezoneArgPassed.returns(false);
38213812
utils.setTimezone(bsConfig, args);
38223813
expect(bsConfig.run_settings.timezone).to.eq(undefined);
38233814
});

0 commit comments

Comments
 (0)