Skip to content

Commit 6569dff

Browse files
committed
added specs for the changes
1 parent 4e177b4 commit 6569dff

File tree

2 files changed

+92
-22
lines changed

2 files changed

+92
-22
lines changed

bin/helpers/zipUpload.js

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ const config = require("./config"),
1010
Constants = require("./constants"),
1111
utils = require("./utils");
1212

13+
14+
const purgeUploadBar = (obj) => {
15+
obj.bar1.update(100, {
16+
speed: ((obj.size / (Date.now() - obj.startTime)) / 125).toFixed(2) //kbits per sec
17+
});
18+
obj.bar1.stop();
19+
clearInterval(obj.zipInterval);
20+
}
21+
1322
const uploadSuits = (bsConfig, filePath, opts, obj) => {
1423
return new Promise(function (resolve, reject) {
1524
obj.startTime = Date.now();
@@ -93,15 +102,6 @@ const uploadSuits = (bsConfig, filePath, opts, obj) => {
93102
});
94103
}
95104

96-
97-
const purgeUploadBar = (obj) => {
98-
obj.bar1.update(100, {
99-
speed: ((obj.size / (Date.now() - obj.startTime)) / 125).toFixed(2) //kbits per sec
100-
});
101-
obj.bar1.stop();
102-
clearInterval(obj.zipInterval);
103-
}
104-
105105
const uploadCypressZip = (bsConfig, md5data, packageData) => {
106106
return new Promise(function (resolve, reject) {
107107
let obj = {}

test/unit/bin/helpers/zipUpload.js

Lines changed: 83 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,13 @@ describe("zipUpload", () => {
7171
archivePresent: true,
7272
messages: {}
7373
}
74-
return uploadSuitsrewire(bsConfig, filePath, opts)
74+
let obj = {
75+
bar1: null,
76+
zipInterval: null,
77+
size: 0,
78+
startTime: null
79+
}
80+
return uploadSuitsrewire(bsConfig, filePath, opts, obj)
7581
.then((_data) => {
7682
chai.assert.fail("Promise error");
7783
})
@@ -87,7 +93,13 @@ describe("zipUpload", () => {
8793
md5ReturnKey: 'returnKey',
8894
url: 'bs://random_hash'
8995
}
90-
return uploadSuitsrewire(bsConfig, filePath, opts)
96+
let obj = {
97+
bar1: null,
98+
zipInterval: null,
99+
size: 0,
100+
startTime: null
101+
}
102+
return uploadSuitsrewire(bsConfig, filePath, opts, obj)
91103
.then((data) => {
92104
chai.assert.deepEqual(data, {returnKey: 'bs://random_hash'});
93105
})
@@ -101,7 +113,13 @@ describe("zipUpload", () => {
101113
let opts = {
102114
archivePresent: false,
103115
}
104-
return uploadSuitsrewire(bsConfig, filePath, opts)
116+
let obj = {
117+
bar1: null,
118+
zipInterval: null,
119+
size: 0,
120+
startTime: null
121+
}
122+
return uploadSuitsrewire(bsConfig, filePath, opts, obj)
105123
.then((data) => {
106124
chai.assert.deepEqual(data, {});
107125
})
@@ -126,7 +144,13 @@ describe("zipUpload", () => {
126144
archivePresent: true,
127145
messages: {}
128146
}
129-
return uploadSuitsrewire(bsConfig, filePath, opts)
147+
let obj = {
148+
bar1: null,
149+
zipInterval: null,
150+
size: 0,
151+
startTime: null
152+
}
153+
return uploadSuitsrewire(bsConfig, filePath, opts, obj)
130154
.then((data) => {
131155
chai.assert.hasAllKeys(data, ["time"]);
132156
})
@@ -151,7 +175,13 @@ describe("zipUpload", () => {
151175
archivePresent: true,
152176
messages: {}
153177
}
154-
return uploadSuitsrewire(bsConfig, filePath, opts)
178+
let obj = {
179+
bar1: null,
180+
zipInterval: null,
181+
size: 0,
182+
startTime: null
183+
}
184+
return uploadSuitsrewire(bsConfig, filePath, opts, obj)
155185
.then((data) => {
156186
chai.assert.hasAllKeys(data, ["zip_url", "time"]);
157187
})
@@ -175,7 +205,13 @@ describe("zipUpload", () => {
175205
archivePresent: true,
176206
messages: {}
177207
}
178-
return uploadSuitsrewire(bsConfig, filePath, opts)
208+
let obj = {
209+
bar1: null,
210+
zipInterval: null,
211+
size: 0,
212+
startTime: null
213+
}
214+
return uploadSuitsrewire(bsConfig, filePath, opts, obj)
179215
.then((_data) => {
180216
chai.assert.fail("Promise error");
181217
})
@@ -199,7 +235,13 @@ describe("zipUpload", () => {
199235
archivePresent: true,
200236
messages: {}
201237
}
202-
return uploadSuitsrewire(bsConfig, filePath, opts)
238+
let obj = {
239+
bar1: null,
240+
zipInterval: null,
241+
size: 0,
242+
startTime: null
243+
}
244+
return uploadSuitsrewire(bsConfig, filePath, opts, obj)
203245
.then((_data) => {
204246
chai.assert.fail("Promise error");
205247
})
@@ -224,7 +266,13 @@ describe("zipUpload", () => {
224266
messages: {},
225267
propogateError: false
226268
}
227-
return uploadSuitsrewire(bsConfig, filePath, opts)
269+
let obj = {
270+
bar1: null,
271+
zipInterval: null,
272+
size: 0,
273+
startTime: null
274+
}
275+
return uploadSuitsrewire(bsConfig, filePath, opts, obj)
228276
.then((data) => {
229277
chai.assert.deepEqual(data, {});
230278
})
@@ -249,7 +297,13 @@ describe("zipUpload", () => {
249297
messages: {},
250298
propogateError: true
251299
}
252-
return uploadSuitsrewire(bsConfig, filePath, opts)
300+
let obj = {
301+
bar1: null,
302+
zipInterval: null,
303+
size: 0,
304+
startTime: null
305+
}
306+
return uploadSuitsrewire(bsConfig, filePath, opts, obj)
253307
.then((_data) => {
254308
chai.assert.fail("Promise error");
255309
})
@@ -274,7 +328,13 @@ describe("zipUpload", () => {
274328
messages: {},
275329
propogateError: true
276330
}
277-
return uploadSuitsrewire(bsConfig, filePath, opts)
331+
let obj = {
332+
bar1: null,
333+
zipInterval: null,
334+
size: 0,
335+
startTime: null
336+
}
337+
return uploadSuitsrewire(bsConfig, filePath, opts, obj)
278338
.then((_data) => {
279339
chai.assert.fail("Promise error");
280340
})
@@ -299,7 +359,13 @@ describe("zipUpload", () => {
299359
messages: {},
300360
propogateError: true
301361
}
302-
return uploadSuitsrewire(bsConfig, filePath, opts)
362+
let obj = {
363+
bar1: null,
364+
zipInterval: null,
365+
size: 0,
366+
startTime: null
367+
}
368+
return uploadSuitsrewire(bsConfig, filePath, opts, obj)
303369
.then((_data) => {
304370
chai.assert.fail("Promise error");
305371
})
@@ -320,9 +386,11 @@ describe("zipUpload", () => {
320386
});
321387

322388
it("resolve with test suit", () => {
389+
let purgeUploadBarStub = sandbox.stub().returns(true);
323390
zipUploader.__set__({
324391
utils: utilsStub,
325-
uploadSuits: uploadSuitsStub
392+
uploadSuits: uploadSuitsStub,
393+
purgeUploadBar: purgeUploadBarStub
326394
});
327395
let uploadCypressZiprewire = zipUploader.__get__('uploadCypressZip');
328396
let bsConfig = {}
@@ -340,9 +408,11 @@ describe("zipUpload", () => {
340408

341409
it("reject with error while uploading suit", () => {
342410
let uploadSuitsErrorStub = sandbox.stub().returns(Promise.reject("test error"));
411+
let purgeUploadBarStub = sandbox.stub().returns(true);
343412
zipUploader.__set__({
344413
utils: utilsStub,
345-
uploadSuits: uploadSuitsErrorStub
414+
uploadSuits: uploadSuitsErrorStub,
415+
purgeUploadBar: purgeUploadBarStub
346416
});
347417
let uploadCypressZiprewire = zipUploader.__get__('uploadCypressZip');
348418
let bsConfig = {}

0 commit comments

Comments
 (0)