Skip to content

Commit 26f0926

Browse files
committed
test: livesync tool tests format
1 parent 56e432c commit 26f0926

File tree

1 file changed

+67
-2
lines changed

1 file changed

+67
-2
lines changed

test/services/livesync/android-livesync-tool.ts

Lines changed: 67 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ const getHandshakeBuffer = () => {
177177
return handshakeBuffer;
178178
};
179179

180-
describe.only("AndroidLivesyncTool", () => {
180+
describe("AndroidLivesyncTool", () => {
181181
let testInjector: IInjector = null;
182182
let livesyncTool: IAndroidLivesyncTool = null;
183183
let testSocket: INetSocket;
@@ -200,10 +200,13 @@ describe.only("AndroidLivesyncTool", () => {
200200
describe("methods", () => {
201201
describe("connect", () => {
202202
it("should retry if first connect fails", () => {
203+
//arrange
203204
const originalOn = testSocket.on;
204205
const originalOnce = testSocket.once;
206+
const connectStub: sinon.SinonStub = sandbox.stub(testSocket, "connect");
205207
let dataAttachCount = 0;
206208
let closeAttachCount = 0;
209+
207210
sandbox.stub(testSocket, "on").callsFake(function(event: string) {
208211
originalOn.apply(this, arguments);
209212
if (event === "close") {
@@ -223,9 +226,11 @@ describe.only("AndroidLivesyncTool", () => {
223226
}
224227
}
225228
});
226-
const connectStub: sinon.SinonStub = sandbox.stub(testSocket, "connect");
229+
230+
//act
227231
const connectPromise = livesyncTool.connect({ appIdentifier: "test", deviceIdentifier: "test", appPlatformsPath: "test" });
228232

233+
//assert
229234
return connectPromise.then(() => {
230235
assert(connectStub.calledTwice);
231236
assert.isFulfilled(connectPromise);
@@ -235,24 +240,31 @@ describe.only("AndroidLivesyncTool", () => {
235240
});
236241

237242
it("should reject if appIdentifier missing", () => {
243+
//act
238244
const connectPromise = livesyncTool.connect({ appIdentifier: "", deviceIdentifier: "test", appPlatformsPath: "test", connectTimeout: 400 });
239245

246+
//assert
240247
return assert.isRejected(connectPromise);
241248
});
242249

243250
it("should reject if appPlatformsPath missing", () => {
251+
//act
244252
const connectPromise = livesyncTool.connect({ appIdentifier: "test", deviceIdentifier: "test", appPlatformsPath: "", connectTimeout: 400 });
245253

254+
//assert
246255
return assert.isRejected(connectPromise);
247256
});
248257

249258
it("should fail eventually", () => {
259+
//act
250260
const connectPromise = livesyncTool.connect({ appIdentifier: "test", deviceIdentifier: "test", appPlatformsPath: "test", connectTimeout: 400 });
251261

262+
//assert
252263
return assert.isRejected(connectPromise);
253264
});
254265

255266
it("should fail if connection alreday exists", () => {
267+
//arrange
256268
const originalOnce = testSocket.once;
257269

258270
sandbox.stub(testSocket, "once").callsFake(function(event: string) {
@@ -262,10 +274,12 @@ describe.only("AndroidLivesyncTool", () => {
262274
}
263275
});
264276

277+
//act
265278
const connectPromise = livesyncTool.connect({ appIdentifier: "test", deviceIdentifier: "test", appPlatformsPath: "test", connectTimeout: 400 }).then(() => {
266279
return livesyncTool.connect({ appIdentifier: "test", deviceIdentifier: "test", appPlatformsPath: "test", connectTimeout: 400 });
267280
});
268281

282+
//assert
269283
return assert.isRejected(connectPromise);
270284
});
271285
});
@@ -288,12 +302,15 @@ describe.only("AndroidLivesyncTool", () => {
288302

289303
describe("sendFile", () => {
290304
it("sends correct information", async () => {
305+
//arrange
291306
const filePath = path.join(testAppPlatformPath, rootTestFileJs);
292307

308+
//act
293309
await livesyncTool.sendFile(filePath);
294310

295311
const sendFileData = getSendFileData((testSocket as TestSocket).accomulatedData);
296312

313+
//assert
297314
assert.equal(sendFileData.fileContent, fileContents[rootTestFileJs]);
298315
assert.equal(sendFileData.fileName, rootTestFileJs);
299316
assert(sendFileData.headerHashMatch);
@@ -302,47 +319,65 @@ describe.only("AndroidLivesyncTool", () => {
302319
});
303320

304321
it("rejects if file doesn't exist", () => {
322+
//act
305323
const sendFilePromise = livesyncTool.sendFile("nonexistent.js");
306324

325+
//assert
307326
return assert.isRejected(sendFilePromise);
308327
});
309328

310329
it("rejects if no connection", () => {
330+
//arrange
311331
livesyncTool.end();
312332
const filePath = path.join(testAppPlatformPath, rootTestFileJs);
333+
334+
//act
313335
const sendFilePromise = livesyncTool.sendFile(filePath);
314336

337+
//assert
315338
return assert.isRejected(sendFilePromise);
316339
});
317340

318341
it("rejects if socket sends error", () => {
342+
//arrange
319343
const errorMessage = "Some error";
320344
const filePath = path.join(testAppPlatformPath, rootTestFileJs);
321345
testSocket.emit('error', errorMessage);
346+
347+
//act
322348
const sendFilePromise = livesyncTool.sendFile(filePath);
349+
350+
//assert
323351
return assert.isRejected(sendFilePromise, errorMessage);
324352
});
325353

326354
it("rejects if error received", async () => {
355+
//arrange
327356
const filePath = path.join(testAppPlatformPath, rootTestFileJs);
328357
const errorMessage = "Some error";
329358
await livesyncTool.sendFile(filePath);
330359
sandbox.stub(testSocket, "write").callsFake((data) => {
331360
testSocket.emit('data', getSyncResponse(AndroidLivesyncTool.ERROR_REPORT, errorMessage));
332361
});
333362

363+
//act
334364
const sendFilePromise = livesyncTool.sendFile(filePath);
365+
366+
//assert
335367
assert.isRejected(sendFilePromise, errorMessage);
336368
});
337369
});
338370

339371
describe("remove file", () => {
340372
it("sends correct information", async () => {
373+
//arrange
341374
const filePath = path.join(testAppPlatformPath, rootTestFileJs);
342375
await livesyncTool.removeFile(filePath);
343376

377+
//act
344378
const removeData = getRemoveFileData((testSocket as TestSocket).accomulatedData);
345379

380+
//assert
346381
assert.equal(removeData.fileName, rootTestFileJs);
347382
assert.equal(removeData.operation, AndroidLivesyncTool.DELETE_FILE_OPERATION);
348383
assert(removeData.headerHashMatch);
@@ -351,18 +386,22 @@ describe.only("AndroidLivesyncTool", () => {
351386

352387
describe("sendDoSync", () => {
353388
it("resolves after received data", () => {
389+
//arrange
354390
let doSyncResolved = false;
355391
const originalWrite = testSocket.write.bind(testSocket);
356392
const writeStub = sandbox.stub(testSocket, "write").callThrough();
357393
writeStub.onSecondCall().callsFake((data) => {
358394
originalWrite(data);
359395
});
360396

397+
//act
361398
const doSyncPromise = livesyncTool.sendDoSyncOperation(true);
362399
const doSyncData = getSyncData((testSocket as TestSocket).accomulatedData);
363400
doSyncPromise.then(() => {
364401
doSyncResolved = true;
365402
});
403+
404+
//assert
366405
assert.isFalse(doSyncResolved);
367406
testSocket.emit('data', getSyncResponse(AndroidLivesyncTool.OPERATION_END_REPORT, doSyncData.operationUid));
368407

@@ -372,18 +411,22 @@ describe.only("AndroidLivesyncTool", () => {
372411
});
373412

374413
it("resolves after received data without refresh", () => {
414+
//arrange
375415
let doSyncResolved = false;
376416
const originalWrite = testSocket.write.bind(testSocket);
377417
const writeStub = sandbox.stub(testSocket, "write").callThrough();
378418
writeStub.onSecondCall().callsFake((data) => {
379419
originalWrite(data);
380420
});
381421

422+
//act
382423
const doSyncPromise = livesyncTool.sendDoSyncOperation(true);
383424
const doSyncData = getSyncData((testSocket as TestSocket).accomulatedData);
384425
doSyncPromise.then(() => {
385426
doSyncResolved = true;
386427
});
428+
429+
//assert
387430
assert.isFalse(doSyncResolved);
388431
testSocket.emit('data', getSyncResponse(AndroidLivesyncTool.OPERATION_END_NO_REFRESH_REPORT_CODE, doSyncData.operationUid));
389432

@@ -393,6 +436,7 @@ describe.only("AndroidLivesyncTool", () => {
393436
});
394437

395438
it("rejects after received error", () => {
439+
//arrange
396440
let doSyncRejected = false;
397441
const errorMessage = "Some error";
398442
const originalWrite = testSocket.write.bind(testSocket);
@@ -401,48 +445,61 @@ describe.only("AndroidLivesyncTool", () => {
401445
originalWrite(data);
402446
});
403447

448+
//act
404449
const doSyncPromise = livesyncTool.sendDoSyncOperation(true);
405450
doSyncPromise.then(null, () => {
406451
doSyncRejected = true;
407452
});
453+
454+
//assert
408455
assert.isFalse(doSyncRejected);
409456
testSocket.emit('data', getSyncResponse(AndroidLivesyncTool.ERROR_REPORT, errorMessage));
410457

411458
return assert.isRejected(doSyncPromise, errorMessage);
412459
});
413460

414461
it("rejects after socket closed", () => {
462+
//arrange
415463
let doSyncRejected = false;
416464
const originalWrite = testSocket.write.bind(testSocket);
417465
const writeStub = sandbox.stub(testSocket, "write").callThrough();
418466
writeStub.onSecondCall().callsFake((data) => {
419467
originalWrite(data);
420468
});
421469

470+
//act
422471
const doSyncPromise = livesyncTool.sendDoSyncOperation(true);
423472
doSyncPromise.then(null, () => {
424473
doSyncRejected = true;
425474
});
475+
476+
//assert
426477
assert.isFalse(doSyncRejected);
427478
testSocket.emit('close', true);
428479

429480
return assert.isRejected(doSyncPromise);
430481
});
431482

432483
it("rejects after timeout", () => {
484+
//act
433485
const doSyncPromise = livesyncTool.sendDoSyncOperation(true, 50);
434486

487+
//assert
435488
return assert.isRejected(doSyncPromise);
436489
});
437490
});
438491
});
439492

440493
describe("sendFiles", () => {
441494
it("calls sendFile for each file", async () => {
495+
//arrange
442496
const filePaths = _.keys(fileContents).map(filePath => path.join(testAppPlatformPath, filePath));
443497
const sendFileStub = sandbox.stub(livesyncTool, "sendFile").callsFake(() => Promise.resolve());
498+
499+
//act
444500
await livesyncTool.sendFiles(filePaths);
445501

502+
//assert
446503
_.forEach(filePaths, (filePath) => {
447504
assert(sendFileStub.calledWith(filePath));
448505
});
@@ -451,10 +508,14 @@ describe.only("AndroidLivesyncTool", () => {
451508

452509
describe("sendDirectory", () => {
453510
it("calls sendFile for each file in directory", async () => {
511+
//arrange
454512
const filePaths = _.keys(fileContents).map(filePath => path.join(testAppPlatformPath, filePath));
455513
const sendFileStub = sandbox.stub(livesyncTool, "sendFile").callsFake(() => Promise.resolve());
514+
515+
//act
456516
await livesyncTool.sendDirectory(testAppPlatformPath);
457517

518+
//assert
458519
_.forEach(filePaths, (filePath) => {
459520
assert(sendFileStub.calledWith(filePath));
460521
});
@@ -463,10 +524,14 @@ describe.only("AndroidLivesyncTool", () => {
463524

464525
describe("removeFiles", () => {
465526
it("calls sendFile for each file", async () => {
527+
//arrange
466528
const filePaths = _.keys(fileContents).map(filePath => path.join(testAppPlatformPath, filePath));
467529
const removeFileStub = sandbox.stub(livesyncTool, "removeFile").callsFake(() => Promise.resolve());
530+
531+
//act
468532
await livesyncTool.removeFiles(filePaths);
469533

534+
//assert
470535
_.forEach(filePaths, (filePath) => {
471536
assert(removeFileStub.calledWith(filePath));
472537
});

0 commit comments

Comments
 (0)