Skip to content

Commit 22d3dcc

Browse files
committed
added rspecs for the get initial details call
1 parent a3bb89f commit 22d3dcc

File tree

2 files changed

+63
-2
lines changed

2 files changed

+63
-2
lines changed

bin/commands/runs.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ module.exports = function run(args, rawArgs) {
4545
// accept the access key from command line or env variable if provided
4646
utils.setAccessKey(bsConfig, args);
4747

48-
console.log(`roshan1: the constant before runs is ${Constants.STATE_CHANGING_HASH.initial_details} ::`)
4948
let buildReportData = await getInitialDetails(bsConfig, args, rawArgs);
50-
console.log(`roshan1: the constant after runs is ${Constants.STATE_CHANGING_HASH.initial_details} ::`)
5149

5250
// accept the build name from command line if provided
5351
utils.setBuildName(bsConfig, args);
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
const { expect } = require("chai");
2+
const chai = require("chai"),
3+
chaiAsPromised = require("chai-as-promised"),
4+
sinon = require('sinon'),
5+
request = require('request');
6+
7+
const Constants = require("../../../../bin/helpers/constants"),
8+
logger = require("../../../../bin/helpers/logger").winstonLogger,
9+
testObjects = require("../../support/fixtures/testObjects"),
10+
utils = require('../../../../bin/helpers/utils'),
11+
getInitialDetails = require('../../../../bin/helpers/getInitialDetails').getInitialDetails;
12+
13+
chai.use(chaiAsPromised);
14+
logger.transports["console.info"].silent = true;
15+
16+
describe('#getInitialDetails', () => {
17+
let args = testObjects.buildInfoSampleArgs;
18+
let rawArgs = testObjects.buildInfoSampleRawArgs;
19+
let bsConfig = testObjects.sampleBsConfig;
20+
let sendUsageReportStub = null, requestStub = null, formatRequestStub = null;
21+
let messageType = Constants.messageTypes.ERROR;
22+
let errorCode = 'get_initial_details_failed'
23+
24+
beforeEach(() => {
25+
sendUsageReportStub = sinon.stub(utils, 'sendUsageReport');
26+
requestStub = sinon.stub(request, "get");
27+
formatRequestStub = sinon.stub(utils, "formatRequest");
28+
});
29+
30+
afterEach(() => {
31+
sinon.restore();
32+
});
33+
34+
it('sends usage report if error occurred in getInitialDetails call', () => {
35+
let error_message = "error occurred";
36+
requestStub.yields(error_message, null, null);
37+
formatRequestStub.returns({err: error_message, statusCode: null, body: null})
38+
sendUsageReportStub.calledOnceWithExactly(bsConfig, args, error_message, messageType, errorCode, null, rawArgs);
39+
getInitialDetails(bsConfig, args, rawArgs).then((result) => {
40+
expect(result).to.eq({});
41+
})
42+
});
43+
44+
it('resolves with data if getInitialDetails call is successful', () => {
45+
let body = {"user_id": 1234};
46+
requestStub.yields(null, { statusCode: 200 }, body);
47+
formatRequestStub.notCalled;
48+
sendUsageReportStub.notCalled;
49+
getInitialDetails(bsConfig, args, rawArgs).then((result) => {
50+
expect(result).to.eq(body);
51+
})
52+
});
53+
54+
it('send usage report if error response from getInitialDetails call', () => {
55+
let body = {"error": 'user not found'};
56+
requestStub.yields(null, { statusCode: 422 }, body);
57+
formatRequestStub.notCalled;
58+
sendUsageReportStub.calledOnceWithExactly(bsConfig, args, body["error"], messageType, errorCode, null, rawArgs);
59+
getInitialDetails(bsConfig, args, rawArgs).then((result) => {
60+
expect(result).to.eq(body);
61+
})
62+
});
63+
});

0 commit comments

Comments
 (0)