Skip to content

Commit a4b0ff8

Browse files
committed
added specs for response checks
1 parent e6f196b commit a4b0ff8

File tree

2 files changed

+61
-66
lines changed

2 files changed

+61
-66
lines changed

test/unit/bin/helpers/capabilityHelper.js

Lines changed: 0 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -779,70 +779,6 @@ describe("capabilityHelper.js", () => {
779779
});
780780
});
781781

782-
describe("validates username and password" , () =>{
783-
beforeEach(() => {
784-
//Stub for cypress json validation
785-
sinon.stub(fs, 'existsSync').returns(true);
786-
sinon.stub(fs, 'readFileSync').returns("{}");
787-
788-
bsConfig = {
789-
auth: {},
790-
browsers: [
791-
{
792-
browser: "chrome",
793-
os: "Windows 10",
794-
versions: ["78", "77"],
795-
},
796-
],
797-
run_settings: {
798-
cypress_proj_dir: "random path",
799-
cypressConfigFilePath: "random path"
800-
},
801-
};
802-
});
803-
804-
afterEach(() => {
805-
fs.existsSync.restore();
806-
fs.readFileSync.restore();
807-
});
808-
809-
it('throws an error if the user has given username as null', () =>{
810-
return capabilityHelper
811-
.validate(bsConfig, { username: "" })
812-
.then(function (data) {
813-
chai.assert.fail("Promise error");
814-
})
815-
.catch((error) => {
816-
chai.assert.equal(error, Constants.validationMessages.EMPTY_ARGS.replace("<argsNotGiven>","Username"));
817-
});
818-
});
819-
820-
it('throws an error if the user has given password as null', () =>{
821-
return capabilityHelper
822-
.validate(bsConfig, { key: "" })
823-
.then(function (data) {
824-
chai.assert.fail("Promise error");
825-
})
826-
.catch((error) => {
827-
chai.assert.equal(error, Constants.validationMessages.EMPTY_ARGS.replace("<argsNotGiven>","Password"));
828-
});
829-
});
830-
831-
it('throws an error if the user has given username and password both as null', () =>{
832-
return capabilityHelper
833-
.validate(bsConfig, {
834-
username: "",
835-
key: ""
836-
})
837-
.then(function (data) {
838-
chai.assert.fail("Promise error");
839-
})
840-
.catch((error) => {
841-
chai.assert.equal(error, Constants.validationMessages.EMPTY_ARGS.replace("<argsNotGiven>","Username and Password"));
842-
});
843-
});
844-
});
845-
846782
it("validate bsConfig", () => {
847783
let bsConfig = undefined;
848784
return capabilityHelper

test/unit/bin/helpers/zipUpload.js

Lines changed: 61 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ describe("zipUpload", () => {
5555
});
5656
});
5757

58-
it("reject with error (if error present in response) if statusCode != 200", () => {
58+
it("reject with error (if error present in response) if statusCode == 401", () => {
5959
let error = "non 200 code";
6060

6161
let requestStub = sandbox
@@ -82,7 +82,7 @@ describe("zipUpload", () => {
8282
});
8383
});
8484

85-
it("reject with message if statusCode != 200 and error not in response", () => {
85+
it("reject with message if statusCode == 401 and error not in response", () => {
8686
let requestStub = sandbox
8787
.stub(request, "post")
8888
.yields(
@@ -98,6 +98,65 @@ describe("zipUpload", () => {
9898
request: { post: requestStub },
9999
});
100100

101+
return zipUploader
102+
.zipUpload(bsConfig, "./random_file_path")
103+
.then(function (data) {
104+
chai.assert.fail("Promise error");
105+
})
106+
.catch((error) => {
107+
sinon.assert.calledOnce(requestStub);
108+
sinon.assert.calledOnce(getUserAgentStub);
109+
sinon.assert.calledOnce(createReadStreamStub);
110+
chai.assert.equal(
111+
error,
112+
Constants.validationMessages.INVALID_DEFAULT_AUTH_PARAMS
113+
);
114+
});
115+
});
116+
117+
it("reject with error (if error present in response) if statusCode != 200 and statusCode != 401", () => {
118+
let error = "non 200 and non 401 code";
119+
120+
let requestStub = sandbox
121+
.stub(request, "post")
122+
.yields(null, { statusCode: 404 }, JSON.stringify({ error: error }));
123+
124+
const zipUploader = proxyquire("../../../../bin/helpers/zipUpload", {
125+
"./utils": {
126+
getUserAgent: getUserAgentStub,
127+
},
128+
request: { post: requestStub },
129+
});
130+
131+
return zipUploader
132+
.zipUpload(bsConfig, "./random_file_path")
133+
.then(function (data) {
134+
chai.assert.fail("Promise error");
135+
})
136+
.catch((error) => {
137+
sinon.assert.calledOnce(requestStub);
138+
sinon.assert.calledOnce(getUserAgentStub);
139+
sinon.assert.calledOnce(createReadStreamStub);
140+
chai.assert.equal(error, "non 200 and non 401 code");
141+
});
142+
});
143+
144+
it("reject with message if statusCode != 200 and statusCode != 401 and error not in response", () => {
145+
let requestStub = sandbox
146+
.stub(request, "post")
147+
.yields(
148+
null,
149+
{ statusCode: 404 },
150+
JSON.stringify({ message: "random message" })
151+
);
152+
153+
const zipUploader = proxyquire("../../../../bin/helpers/zipUpload", {
154+
"./utils": {
155+
getUserAgent: getUserAgentStub,
156+
},
157+
request: { post: requestStub },
158+
});
159+
101160
return zipUploader
102161
.zipUpload(bsConfig, "./random_file_path")
103162
.then(function (data) {

0 commit comments

Comments
 (0)