@@ -177,7 +177,7 @@ const getHandshakeBuffer = () => {
177
177
return handshakeBuffer ;
178
178
} ;
179
179
180
- describe . only ( "AndroidLivesyncTool" , ( ) => {
180
+ describe ( "AndroidLivesyncTool" , ( ) => {
181
181
let testInjector : IInjector = null ;
182
182
let livesyncTool : IAndroidLivesyncTool = null ;
183
183
let testSocket : INetSocket ;
@@ -200,10 +200,13 @@ describe.only("AndroidLivesyncTool", () => {
200
200
describe ( "methods" , ( ) => {
201
201
describe ( "connect" , ( ) => {
202
202
it ( "should retry if first connect fails" , ( ) => {
203
+ //arrange
203
204
const originalOn = testSocket . on ;
204
205
const originalOnce = testSocket . once ;
206
+ const connectStub : sinon . SinonStub = sandbox . stub ( testSocket , "connect" ) ;
205
207
let dataAttachCount = 0 ;
206
208
let closeAttachCount = 0 ;
209
+
207
210
sandbox . stub ( testSocket , "on" ) . callsFake ( function ( event : string ) {
208
211
originalOn . apply ( this , arguments ) ;
209
212
if ( event === "close" ) {
@@ -223,9 +226,11 @@ describe.only("AndroidLivesyncTool", () => {
223
226
}
224
227
}
225
228
} ) ;
226
- const connectStub : sinon . SinonStub = sandbox . stub ( testSocket , "connect" ) ;
229
+
230
+ //act
227
231
const connectPromise = livesyncTool . connect ( { appIdentifier : "test" , deviceIdentifier : "test" , appPlatformsPath : "test" } ) ;
228
232
233
+ //assert
229
234
return connectPromise . then ( ( ) => {
230
235
assert ( connectStub . calledTwice ) ;
231
236
assert . isFulfilled ( connectPromise ) ;
@@ -235,24 +240,31 @@ describe.only("AndroidLivesyncTool", () => {
235
240
} ) ;
236
241
237
242
it ( "should reject if appIdentifier missing" , ( ) => {
243
+ //act
238
244
const connectPromise = livesyncTool . connect ( { appIdentifier : "" , deviceIdentifier : "test" , appPlatformsPath : "test" , connectTimeout : 400 } ) ;
239
245
246
+ //assert
240
247
return assert . isRejected ( connectPromise ) ;
241
248
} ) ;
242
249
243
250
it ( "should reject if appPlatformsPath missing" , ( ) => {
251
+ //act
244
252
const connectPromise = livesyncTool . connect ( { appIdentifier : "test" , deviceIdentifier : "test" , appPlatformsPath : "" , connectTimeout : 400 } ) ;
245
253
254
+ //assert
246
255
return assert . isRejected ( connectPromise ) ;
247
256
} ) ;
248
257
249
258
it ( "should fail eventually" , ( ) => {
259
+ //act
250
260
const connectPromise = livesyncTool . connect ( { appIdentifier : "test" , deviceIdentifier : "test" , appPlatformsPath : "test" , connectTimeout : 400 } ) ;
251
261
262
+ //assert
252
263
return assert . isRejected ( connectPromise ) ;
253
264
} ) ;
254
265
255
266
it ( "should fail if connection alreday exists" , ( ) => {
267
+ //arrange
256
268
const originalOnce = testSocket . once ;
257
269
258
270
sandbox . stub ( testSocket , "once" ) . callsFake ( function ( event : string ) {
@@ -262,10 +274,12 @@ describe.only("AndroidLivesyncTool", () => {
262
274
}
263
275
} ) ;
264
276
277
+ //act
265
278
const connectPromise = livesyncTool . connect ( { appIdentifier : "test" , deviceIdentifier : "test" , appPlatformsPath : "test" , connectTimeout : 400 } ) . then ( ( ) => {
266
279
return livesyncTool . connect ( { appIdentifier : "test" , deviceIdentifier : "test" , appPlatformsPath : "test" , connectTimeout : 400 } ) ;
267
280
} ) ;
268
281
282
+ //assert
269
283
return assert . isRejected ( connectPromise ) ;
270
284
} ) ;
271
285
} ) ;
@@ -288,12 +302,15 @@ describe.only("AndroidLivesyncTool", () => {
288
302
289
303
describe ( "sendFile" , ( ) => {
290
304
it ( "sends correct information" , async ( ) => {
305
+ //arrange
291
306
const filePath = path . join ( testAppPlatformPath , rootTestFileJs ) ;
292
307
308
+ //act
293
309
await livesyncTool . sendFile ( filePath ) ;
294
310
295
311
const sendFileData = getSendFileData ( ( testSocket as TestSocket ) . accomulatedData ) ;
296
312
313
+ //assert
297
314
assert . equal ( sendFileData . fileContent , fileContents [ rootTestFileJs ] ) ;
298
315
assert . equal ( sendFileData . fileName , rootTestFileJs ) ;
299
316
assert ( sendFileData . headerHashMatch ) ;
@@ -302,47 +319,65 @@ describe.only("AndroidLivesyncTool", () => {
302
319
} ) ;
303
320
304
321
it ( "rejects if file doesn't exist" , ( ) => {
322
+ //act
305
323
const sendFilePromise = livesyncTool . sendFile ( "nonexistent.js" ) ;
306
324
325
+ //assert
307
326
return assert . isRejected ( sendFilePromise ) ;
308
327
} ) ;
309
328
310
329
it ( "rejects if no connection" , ( ) => {
330
+ //arrange
311
331
livesyncTool . end ( ) ;
312
332
const filePath = path . join ( testAppPlatformPath , rootTestFileJs ) ;
333
+
334
+ //act
313
335
const sendFilePromise = livesyncTool . sendFile ( filePath ) ;
314
336
337
+ //assert
315
338
return assert . isRejected ( sendFilePromise ) ;
316
339
} ) ;
317
340
318
341
it ( "rejects if socket sends error" , ( ) => {
342
+ //arrange
319
343
const errorMessage = "Some error" ;
320
344
const filePath = path . join ( testAppPlatformPath , rootTestFileJs ) ;
321
345
testSocket . emit ( 'error' , errorMessage ) ;
346
+
347
+ //act
322
348
const sendFilePromise = livesyncTool . sendFile ( filePath ) ;
349
+
350
+ //assert
323
351
return assert . isRejected ( sendFilePromise , errorMessage ) ;
324
352
} ) ;
325
353
326
354
it ( "rejects if error received" , async ( ) => {
355
+ //arrange
327
356
const filePath = path . join ( testAppPlatformPath , rootTestFileJs ) ;
328
357
const errorMessage = "Some error" ;
329
358
await livesyncTool . sendFile ( filePath ) ;
330
359
sandbox . stub ( testSocket , "write" ) . callsFake ( ( data ) => {
331
360
testSocket . emit ( 'data' , getSyncResponse ( AndroidLivesyncTool . ERROR_REPORT , errorMessage ) ) ;
332
361
} ) ;
333
362
363
+ //act
334
364
const sendFilePromise = livesyncTool . sendFile ( filePath ) ;
365
+
366
+ //assert
335
367
assert . isRejected ( sendFilePromise , errorMessage ) ;
336
368
} ) ;
337
369
} ) ;
338
370
339
371
describe ( "remove file" , ( ) => {
340
372
it ( "sends correct information" , async ( ) => {
373
+ //arrange
341
374
const filePath = path . join ( testAppPlatformPath , rootTestFileJs ) ;
342
375
await livesyncTool . removeFile ( filePath ) ;
343
376
377
+ //act
344
378
const removeData = getRemoveFileData ( ( testSocket as TestSocket ) . accomulatedData ) ;
345
379
380
+ //assert
346
381
assert . equal ( removeData . fileName , rootTestFileJs ) ;
347
382
assert . equal ( removeData . operation , AndroidLivesyncTool . DELETE_FILE_OPERATION ) ;
348
383
assert ( removeData . headerHashMatch ) ;
@@ -351,18 +386,22 @@ describe.only("AndroidLivesyncTool", () => {
351
386
352
387
describe ( "sendDoSync" , ( ) => {
353
388
it ( "resolves after received data" , ( ) => {
389
+ //arrange
354
390
let doSyncResolved = false ;
355
391
const originalWrite = testSocket . write . bind ( testSocket ) ;
356
392
const writeStub = sandbox . stub ( testSocket , "write" ) . callThrough ( ) ;
357
393
writeStub . onSecondCall ( ) . callsFake ( ( data ) => {
358
394
originalWrite ( data ) ;
359
395
} ) ;
360
396
397
+ //act
361
398
const doSyncPromise = livesyncTool . sendDoSyncOperation ( true ) ;
362
399
const doSyncData = getSyncData ( ( testSocket as TestSocket ) . accomulatedData ) ;
363
400
doSyncPromise . then ( ( ) => {
364
401
doSyncResolved = true ;
365
402
} ) ;
403
+
404
+ //assert
366
405
assert . isFalse ( doSyncResolved ) ;
367
406
testSocket . emit ( 'data' , getSyncResponse ( AndroidLivesyncTool . OPERATION_END_REPORT , doSyncData . operationUid ) ) ;
368
407
@@ -372,18 +411,22 @@ describe.only("AndroidLivesyncTool", () => {
372
411
} ) ;
373
412
374
413
it ( "resolves after received data without refresh" , ( ) => {
414
+ //arrange
375
415
let doSyncResolved = false ;
376
416
const originalWrite = testSocket . write . bind ( testSocket ) ;
377
417
const writeStub = sandbox . stub ( testSocket , "write" ) . callThrough ( ) ;
378
418
writeStub . onSecondCall ( ) . callsFake ( ( data ) => {
379
419
originalWrite ( data ) ;
380
420
} ) ;
381
421
422
+ //act
382
423
const doSyncPromise = livesyncTool . sendDoSyncOperation ( true ) ;
383
424
const doSyncData = getSyncData ( ( testSocket as TestSocket ) . accomulatedData ) ;
384
425
doSyncPromise . then ( ( ) => {
385
426
doSyncResolved = true ;
386
427
} ) ;
428
+
429
+ //assert
387
430
assert . isFalse ( doSyncResolved ) ;
388
431
testSocket . emit ( 'data' , getSyncResponse ( AndroidLivesyncTool . OPERATION_END_NO_REFRESH_REPORT_CODE , doSyncData . operationUid ) ) ;
389
432
@@ -393,6 +436,7 @@ describe.only("AndroidLivesyncTool", () => {
393
436
} ) ;
394
437
395
438
it ( "rejects after received error" , ( ) => {
439
+ //arrange
396
440
let doSyncRejected = false ;
397
441
const errorMessage = "Some error" ;
398
442
const originalWrite = testSocket . write . bind ( testSocket ) ;
@@ -401,48 +445,61 @@ describe.only("AndroidLivesyncTool", () => {
401
445
originalWrite ( data ) ;
402
446
} ) ;
403
447
448
+ //act
404
449
const doSyncPromise = livesyncTool . sendDoSyncOperation ( true ) ;
405
450
doSyncPromise . then ( null , ( ) => {
406
451
doSyncRejected = true ;
407
452
} ) ;
453
+
454
+ //assert
408
455
assert . isFalse ( doSyncRejected ) ;
409
456
testSocket . emit ( 'data' , getSyncResponse ( AndroidLivesyncTool . ERROR_REPORT , errorMessage ) ) ;
410
457
411
458
return assert . isRejected ( doSyncPromise , errorMessage ) ;
412
459
} ) ;
413
460
414
461
it ( "rejects after socket closed" , ( ) => {
462
+ //arrange
415
463
let doSyncRejected = false ;
416
464
const originalWrite = testSocket . write . bind ( testSocket ) ;
417
465
const writeStub = sandbox . stub ( testSocket , "write" ) . callThrough ( ) ;
418
466
writeStub . onSecondCall ( ) . callsFake ( ( data ) => {
419
467
originalWrite ( data ) ;
420
468
} ) ;
421
469
470
+ //act
422
471
const doSyncPromise = livesyncTool . sendDoSyncOperation ( true ) ;
423
472
doSyncPromise . then ( null , ( ) => {
424
473
doSyncRejected = true ;
425
474
} ) ;
475
+
476
+ //assert
426
477
assert . isFalse ( doSyncRejected ) ;
427
478
testSocket . emit ( 'close' , true ) ;
428
479
429
480
return assert . isRejected ( doSyncPromise ) ;
430
481
} ) ;
431
482
432
483
it ( "rejects after timeout" , ( ) => {
484
+ //act
433
485
const doSyncPromise = livesyncTool . sendDoSyncOperation ( true , 50 ) ;
434
486
487
+ //assert
435
488
return assert . isRejected ( doSyncPromise ) ;
436
489
} ) ;
437
490
} ) ;
438
491
} ) ;
439
492
440
493
describe ( "sendFiles" , ( ) => {
441
494
it ( "calls sendFile for each file" , async ( ) => {
495
+ //arrange
442
496
const filePaths = _ . keys ( fileContents ) . map ( filePath => path . join ( testAppPlatformPath , filePath ) ) ;
443
497
const sendFileStub = sandbox . stub ( livesyncTool , "sendFile" ) . callsFake ( ( ) => Promise . resolve ( ) ) ;
498
+
499
+ //act
444
500
await livesyncTool . sendFiles ( filePaths ) ;
445
501
502
+ //assert
446
503
_ . forEach ( filePaths , ( filePath ) => {
447
504
assert ( sendFileStub . calledWith ( filePath ) ) ;
448
505
} ) ;
@@ -451,10 +508,14 @@ describe.only("AndroidLivesyncTool", () => {
451
508
452
509
describe ( "sendDirectory" , ( ) => {
453
510
it ( "calls sendFile for each file in directory" , async ( ) => {
511
+ //arrange
454
512
const filePaths = _ . keys ( fileContents ) . map ( filePath => path . join ( testAppPlatformPath , filePath ) ) ;
455
513
const sendFileStub = sandbox . stub ( livesyncTool , "sendFile" ) . callsFake ( ( ) => Promise . resolve ( ) ) ;
514
+
515
+ //act
456
516
await livesyncTool . sendDirectory ( testAppPlatformPath ) ;
457
517
518
+ //assert
458
519
_ . forEach ( filePaths , ( filePath ) => {
459
520
assert ( sendFileStub . calledWith ( filePath ) ) ;
460
521
} ) ;
@@ -463,10 +524,14 @@ describe.only("AndroidLivesyncTool", () => {
463
524
464
525
describe ( "removeFiles" , ( ) => {
465
526
it ( "calls sendFile for each file" , async ( ) => {
527
+ //arrange
466
528
const filePaths = _ . keys ( fileContents ) . map ( filePath => path . join ( testAppPlatformPath , filePath ) ) ;
467
529
const removeFileStub = sandbox . stub ( livesyncTool , "removeFile" ) . callsFake ( ( ) => Promise . resolve ( ) ) ;
530
+
531
+ //act
468
532
await livesyncTool . removeFiles ( filePaths ) ;
469
533
534
+ //assert
470
535
_ . forEach ( filePaths , ( filePath ) => {
471
536
assert ( removeFileStub . calledWith ( filePath ) ) ;
472
537
} ) ;
0 commit comments