Skip to content

Commit a06c43f

Browse files
committed
add test cacses
1 parent a1db395 commit a06c43f

File tree

3 files changed

+36
-4
lines changed

3 files changed

+36
-4
lines changed

bin/helpers/utils.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -385,11 +385,11 @@ exports.isJSONInvalid = (err, args) => {
385385
let invalid = true
386386

387387
if (err === Constants.validationMessages.INVALID_PARALLELS_CONFIGURATION && !this.isUndefined(args.parallels)) {
388-
invalid = false
388+
return false
389389
}
390390

391391
if (this.deleteBaseUrlFromError(err) === this.deleteBaseUrlFromError(Constants.validationMessages.LOCAL_NOT_SET)) {
392-
invalid = false
392+
return false
393393
}
394394

395395
return invalid

test/unit/bin/commands/runs.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ describe("runs", () => {
8282
beforeEach(() => {
8383
sandbox = sinon.createSandbox();
8484
validateBstackJsonStub = sandbox.stub();
85+
isJSONInvalidStub = sandbox.stub();
8586
setUsernameStub = sandbox.stub();
8687
setAccessKeyStub = sandbox.stub();
8788
setBuildNameStub = sandbox.stub();
@@ -127,7 +128,8 @@ describe("runs", () => {
127128
setLocal: setLocalStub,
128129
setLocalIdentifier: setLocalIdentifierStub,
129130
deleteResults: deleteResultsStub,
130-
setDefaults: setDefaultsStub
131+
setDefaults: setDefaultsStub,
132+
isJSONInvalid: isJSONInvalidStub
131133
},
132134
'../helpers/capabilityHelper': {
133135
validate: capabilityValidatorStub,

test/unit/bin/helpers/utils.js

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ describe('utils', () => {
145145
sandbox = sinon.createSandbox();
146146
sandbox.stub(utils,'getBrowserCombinations').returns(['a','b']);
147147
});
148-
148+
149149
afterEach(() => {
150150
sandbox.restore();
151151
sinon.restore();
@@ -1146,4 +1146,34 @@ describe('utils', () => {
11461146
expect(utils.versionChangedMessage(preferredVersion, actualVersion)).to.eq(message)
11471147
});
11481148
})
1149+
1150+
describe('#isJSONInvalid', () => {
1151+
it('JSON is valid when error is parallel misconfiguration', () => {
1152+
let error = constant.validationMessages.INVALID_PARALLELS_CONFIGURATION;
1153+
let args = {"parallels": 4}
1154+
expect(utils.isJSONInvalid(error, args)).to.eq(false)
1155+
});
1156+
1157+
it('JSON is valid when local is not set for localhost url', () => {
1158+
let error = constant.validationMessages.LOCAL_NOT_SET.replace("<baseUrlValue>", "localhost:4000");
1159+
expect(utils.isJSONInvalid(error, {})).to.eq(false)
1160+
});
1161+
1162+
it('JSON is invalid for errors apart from Local or Prallell misconfiguration', () => {
1163+
let error = constant.validationMessages.INCORRECT_AUTH_PARAMS;
1164+
expect(utils.isJSONInvalid(error, {})).to.eq(true)
1165+
});
1166+
})
1167+
1168+
describe('#deleteBaseUrlFromError', () => {
1169+
it('Replace baseUrl in Local error string', () => {
1170+
let error = constant.validationMessages.LOCAL_NOT_SET;
1171+
expect(utils.deleteBaseUrlFromError(error)).to.match(/To test on BrowserStack/)
1172+
});
1173+
1174+
it('should not replace baseUrl in other error string', () => {
1175+
let error = constant.validationMessages.NOT_VALID_JSON;
1176+
expect(utils.deleteBaseUrlFromError(error)).not.to.match(/To test on BrowserStack/)
1177+
});
1178+
});
11491179
});

0 commit comments

Comments
 (0)