Skip to content

Commit dbdaee2

Browse files
roshan04Karan Nagpal
authored andcommitted
added specs for changes
1 parent 36608b2 commit dbdaee2

File tree

5 files changed

+55
-56
lines changed

5 files changed

+55
-56
lines changed

bin/helpers/reporterHTML.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,9 @@ function generateCypressCombinationSpecReportDataWithConfigJson(combination){
294294
let configJson, resultsJson;
295295

296296
await Promise.all([getConfigJsonResponse(combination), getResultsJsonResponse(combination)]).then(function (successResult) {
297-
[configJson, configJsonError, resultsJson, resultsJsonError] = successResult;
297+
[[configJson, configJsonError], [resultsJson, resultsJsonError]] = successResult;
298298
}).catch(function (failureResult) {
299-
[configJson, configJsonError, resultsJson, resultsJsonError] = failureResult;
299+
[[configJson, configJsonError], [resultsJson, resultsJsonError]] = failureResult;
300300
});
301301

302302
if(resultsJsonError || configJsonError){

bin/helpers/utils.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ const usageReporting = require("./usageReporting"),
1818
pkg = require('../../package.json');
1919

2020
const request = require('request');
21-
const axios = require("axios");
2221

2322
exports.validateBstackJson = (bsConfigPath) => {
2423
return new Promise(function (resolve, reject) {
@@ -1021,6 +1020,7 @@ exports.stopBrowserStackBuild = async (bsConfig, args, buildId, rawArgs) => {
10211020
}
10221021
}
10231022
});
1023+
resolve();
10241024
});
10251025
}
10261026

test/unit/bin/helpers/reporterHTML.js

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -276,6 +276,7 @@ describe("reportHTML", () => {
276276
describe("Modify Cypress Report Data", ()=> {
277277
const reporterHTML = rewire('../../../../bin/helpers/reporterHTML');
278278
const cypressReportData = reporterHTML.__get__('cypressReportData');
279+
let getMock = sinon.mock(request);
279280
const cypress_report_data_with_config = {
280281
cypress_version: "6.8.0",
281282
rows: {
@@ -307,32 +308,32 @@ describe("reportHTML", () => {
307308
}
308309
}
309310
it("Generate Report Data for cypress version > 6", async ()=>{
310-
let configResponse = { data: {
311-
tests: [
311+
let configResponse = {
312+
"tests": [
312313
{
313-
clientId: "r3",
314-
title:[
314+
"clientId": "r3",
315+
"title":[
315316
"file_name",
316317
"test_case"
317318
]
318319
}
319320
]
320-
} }
321-
let resultsResponse = { data: {
322-
tests: [
321+
}
322+
let resultsResponse = {
323+
"tests": [
323324
{
324-
clientId: "r3",
325-
state: "passed",
326-
attempts:[
325+
"clientId": "r3",
326+
"state": "passed",
327+
"attempts":[
327328
{
328329
"state": "passed",
329-
"wallClockDuration": 62
330+
"wallClockDuration": "62"
330331
}
331332
]
332333
}
333334
]
334-
} }
335-
let expectedResponse = {
335+
}
336+
let expectedResponse = {
336337
cypress_version: "6.8.0",
337338
rows:{
338339
"todo.spec.js": {
@@ -344,18 +345,17 @@ describe("reportHTML", () => {
344345
}]
345346
}
346347
}
347-
}
348-
let axiosGetStub = sandbox.stub(axios, "get")
349-
let axiosConfigStub = axiosGetStub.withArgs("config_json").resolves(configResponse);
350-
let axiosResultStub = axiosGetStub.withArgs("result_json").resolves(resultsResponse);
348+
}
349+
let getConfigJsonResponse = getMock.expects('get').withArgs("config_json").yields(undefined, { statusCode: 200 }, JSON.stringify(configResponse));
350+
let getResultsJsonResponse = getMock.expects('get').withArgs("result_json").yields(undefined, { statusCode: 200 }, JSON.stringify(resultsResponse));
351351
let result = await cypressReportData(cypress_report_data_with_config);
352-
sinon.assert.calledOnce(axiosConfigStub);
353-
sinon.assert.calledOnce(axiosResultStub);
352+
sinon.assert.calledOnce(getConfigJsonResponse);
353+
sinon.assert.calledOnce(getResultsJsonResponse);
354354
expect(JSON.stringify(result)).to.be.equal(JSON.stringify(expectedResponse));
355355
});
356356

357357
it("Generate Report Data for cypress version < 6", async ()=>{
358-
let resultsResponse = { data: {
358+
let resultsResponse = {
359359
tests: [
360360
{
361361
clientId: "r3",
@@ -372,7 +372,7 @@ describe("reportHTML", () => {
372372
]
373373
}
374374
]
375-
} }
375+
}
376376
let expectedResponse = {
377377
cypress_version: "5.6.0",
378378
rows:{
@@ -386,10 +386,9 @@ describe("reportHTML", () => {
386386
}
387387
}
388388
}
389-
let axiosGetStub = sandbox.stub(axios, "get")
390-
let axiosResultStub = axiosGetStub.withArgs("result_json").resolves(resultsResponse);
389+
let getResultsJsonResponse = getMock.expects('get').withArgs("result_json").yields(undefined, { statusCode: 200 }, JSON.stringify(resultsResponse));
391390
let result = await cypressReportData(cypress_report_data_without_config);
392-
sinon.assert.calledOnce(axiosResultStub);
391+
sinon.assert.calledOnce(getResultsJsonResponse);
393392
expect(JSON.stringify(result)).to.be.equal(JSON.stringify(expectedResponse));
394393
});
395394
});

test/unit/bin/helpers/utils.js

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ const chai = require('chai'),
1111
chalk = require('chalk'),
1212
os = require("os"),
1313
crypto = require('crypto'),
14-
fs = require('fs'),
15-
axios = require('axios');
14+
fs = require('fs');
1615
const getmac = require('getmac').default;
1716
const usageReporting = require('../../../../bin/helpers/usageReporting');
1817
const utils = require('../../../../bin/helpers/utils'),
@@ -2555,75 +2554,75 @@ describe('utils', () => {
25552554
});
25562555

25572556
describe('stopBrowserStackBuild', () => {
2558-
let axiosPostStub, getUserAgentStub, sendUsageReportStub, message, messageType, errorCode;
2557+
let getUserAgentStub, sendUsageReportStub, message, messageType, errorCode;
25592558
let bsConfig = testObjects.sampleBsConfig;
25602559
let args = {};
25612560
let rawArgs = {};
25622561
let buildId = 'build_id';
25632562
let body = testObjects.buildStopSampleBody;
25642563

25652564
beforeEach(() => {
2566-
axiosPostStub = sandbox.stub(axios, "post");
25672565
getUserAgentStub = sinon.stub(utils, 'getUserAgent').returns('user-agent');
25682566
sendUsageReportStub = sinon.stub(utils, 'sendUsageReport');
25692567
});
25702568
afterEach(()=>{
2571-
axiosPostStub.restore();
25722569
getUserAgentStub.restore();
25732570
sendUsageReportStub.restore();
25742571
sandbox.restore();
25752572
})
25762573

25772574
it('message thrown if API deprecated', async () => {
25782575
let api_deprecated_response = {
2579-
status: 299
2576+
statusCode: 299
25802577
}
25812578
message = constant.userMessages.API_DEPRECATED;
25822579
messageType = constant.messageTypes.INFO;
25832580
errorCode = 'api_deprecated';
2584-
axiosPostStub.resolves(api_deprecated_response);
2581+
let requestStub = sinon.stub(request, 'post').yields(undefined, api_deprecated_response, null);
25852582
await utils.stopBrowserStackBuild(bsConfig, args, buildId, rawArgs);
2586-
sinon.assert.calledOnce(axiosPostStub);
2583+
sinon.assert.calledOnce(requestStub);
25872584
sinon.assert.calledOnce(getUserAgentStub);
25882585
sinon.assert.calledOnceWithExactly(sendUsageReportStub, bsConfig, args, message, messageType, errorCode, null, rawArgs);
2586+
requestStub.restore();
25892587
});
25902588

25912589
it('message thrown if build returned', async () => {
25922590
let api_deprecated_response = {
2593-
status: 299,
2594-
data: body
2591+
statusCode: 299,
25952592
}
25962593
message = body.message;
25972594
messageType = constant.messageTypes.INFO;
25982595
errorCode = 'api_deprecated';
2599-
axiosPostStub.resolves(api_deprecated_response);
2596+
let requestStub = sinon.stub(request, 'post').yields(undefined, api_deprecated_response, JSON.stringify(body));
26002597
await utils.stopBrowserStackBuild(bsConfig, args, buildId, rawArgs);
2601-
sinon.assert.calledOnce(axiosPostStub);
2598+
sinon.assert.calledOnce(requestStub);
26022599
sinon.assert.calledOnce(getUserAgentStub);
26032600
sinon.assert.calledOnceWithExactly(sendUsageReportStub, bsConfig, args, message, messageType, errorCode, null, rawArgs);
2601+
requestStub.restore();
26042602
});
26052603

26062604
it('message thrown if statusCode != 200', async () => {
26072605
let non_200_status_response = {
2608-
status: 400
2606+
statusCode: 400
26092607
}
26102608
message = constant.userMessages.BUILD_STOP_FAILED;
26112609
messageType = constant.messageTypes.ERROR;
26122610
errorCode = 'api_failed_build_stop';
2613-
axiosPostStub.resolves(non_200_status_response);
2611+
let requestStub = sinon.stub(request, 'post').yields(undefined, non_200_status_response, null);
26142612
await utils.stopBrowserStackBuild(bsConfig, args, buildId, rawArgs);
2615-
sinon.assert.calledOnce(axiosPostStub);
2613+
sinon.assert.calledOnce(requestStub);
26162614
sinon.assert.calledOnce(getUserAgentStub);
26172615
sinon.assert.calledOnceWithExactly(sendUsageReportStub, bsConfig, args, message, messageType, errorCode, null, rawArgs);
2616+
requestStub.restore();
26182617
});
26192618

26202619
it('message thrown if statusCode != 200 and user unauthorized', async () => {
26212620
let body_with_message = {
26222621
...body,
2623-
message: "Unauthorized",
2622+
"message": "Unauthorized",
26242623
};
26252624
let non_200_status_response = {
2626-
status: 401,
2625+
statusCode: 401,
26272626
data: body_with_message
26282627
}
26292628

@@ -2632,45 +2631,46 @@ describe('utils', () => {
26322631
} with error: \n${JSON.stringify(body_with_message, null, 2)}`;
26332632
messageType = constant.messageTypes.ERROR;
26342633
errorCode = 'api_auth_failed';
2635-
axiosPostStub.resolves(non_200_status_response);
2634+
let requestStub = sinon.stub(request, 'post').yields(undefined, non_200_status_response, JSON.stringify(body_with_message));
26362635
await utils.stopBrowserStackBuild(bsConfig, args, buildId, rawArgs);
2637-
sinon.assert.calledOnce(axiosPostStub);
2636+
sinon.assert.calledOnce(requestStub);
26382637
sinon.assert.calledOnce(getUserAgentStub);
26392638
sinon.assert.calledOnceWithExactly(sendUsageReportStub, bsConfig, args, message, messageType, errorCode, null, rawArgs);
2639+
requestStub.restore();
26402640
});
26412641

26422642
it('message thrown if statusCode != 200 and build is present', async () => {
26432643
let non_200_status_response = {
2644-
status: 402,
2645-
data: body
2644+
statusCode: 402,
26462645
}
26472646

26482647
message = `${
26492648
constant.userMessages.BUILD_STOP_FAILED
26502649
} with error: \n${JSON.stringify(body, null, 2)}`;
26512650
messageType = constant.messageTypes.ERROR;
26522651
errorCode = 'api_failed_build_stop';
2653-
axiosPostStub.resolves(non_200_status_response);
2652+
let requestStub = sinon.stub(request, 'post').yields(undefined, non_200_status_response, JSON.stringify(body));
26542653
await utils.stopBrowserStackBuild(bsConfig, args, buildId, rawArgs);
2655-
sinon.assert.calledOnce(axiosPostStub);
2654+
sinon.assert.calledOnce(requestStub);
26562655
sinon.assert.calledOnce(getUserAgentStub);
26572656
sinon.assert.calledOnceWithExactly(sendUsageReportStub, bsConfig, args, message, messageType, errorCode, null, rawArgs);
2657+
requestStub.restore();
26582658
});
26592659

26602660
it('message thrown if API success', async () => {
26612661
let success_response = {
2662-
status: 200,
2663-
data: body
2662+
statusCode: 200,
26642663
}
26652664

26662665
message = `${JSON.stringify(body, null, 2)}`;
26672666
messageType = constant.messageTypes.SUCCESS;
26682667
errorCode = null;
2669-
axiosPostStub.resolves(success_response);
2668+
let requestStub = sinon.stub(request, 'post').yields(undefined, success_response, JSON.stringify(body));
26702669
await utils.stopBrowserStackBuild(bsConfig, args, buildId, rawArgs);
2671-
sinon.assert.calledOnce(axiosPostStub);
2670+
sinon.assert.calledOnce(requestStub);
26722671
sinon.assert.calledOnce(getUserAgentStub);
26732672
sinon.assert.calledOnceWithExactly(sendUsageReportStub, bsConfig, args, message, messageType, errorCode, null, rawArgs);
2673+
requestStub.restore();
26742674
});
26752675
});
26762676

test/unit/support/fixtures/testObjects.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ const buildStopSampleRawArgs = {
151151
};
152152

153153
const buildStopSampleBody = {
154-
message: "stopped 1 sessions",
155-
stopped_session_count: 1,
154+
"message": "stopped 1 sessions",
155+
"stopped_session_count": "1"
156156
};
157157

158158
const sampleCapsData = {

0 commit comments

Comments
 (0)