@@ -11,7 +11,10 @@ import busApi from '../../services/busApi';
11
11
import messageService from '../../services/messageService' ;
12
12
import RabbitMQService from '../../services/rabbitmq' ;
13
13
import mockRabbitMQ from '../../tests/mockRabbitMQ' ;
14
- import { BUS_API_EVENT } from '../../constants' ;
14
+ import {
15
+ BUS_API_EVENT ,
16
+ RESOURCES ,
17
+ } from '../../constants' ;
15
18
16
19
const ES_PROJECT_INDEX = config . get ( 'elasticsearchConfig.indexName' ) ;
17
20
const ES_PROJECT_TYPE = config . get ( 'elasticsearchConfig.docType' ) ;
@@ -63,7 +66,6 @@ describe('Project Phases', () => {
63
66
let projectId ;
64
67
let phaseId ;
65
68
let phaseId2 ;
66
- let phaseId3 ;
67
69
const memberUser = {
68
70
handle : testUtil . getDecodedToken ( testUtil . jwts . member ) . handle ,
69
71
userId : testUtil . getDecodedToken ( testUtil . jwts . member ) . userId ,
@@ -133,7 +135,6 @@ describe('Project Phases', () => {
133
135
. then ( ( createdPhases ) => {
134
136
phaseId = createdPhases [ 0 ] . id ;
135
137
phaseId2 = createdPhases [ 1 ] . id ;
136
- phaseId3 = createdPhases [ 2 ] . id ;
137
138
138
139
done ( ) ;
139
140
} ) ;
@@ -184,7 +185,7 @@ describe('Project Phases', () => {
184
185
request ( server )
185
186
. patch ( `/v5/projects/${ projectId } /phases/999` )
186
187
. set ( {
187
- Authorization : `Bearer ${ testUtil . jwts . copilot } ` ,
188
+ Authorization : `Bearer ${ testUtil . jwts . admin } ` ,
188
189
} )
189
190
. send ( updateBody )
190
191
. expect ( 'Content-Type' , / j s o n / )
@@ -195,7 +196,7 @@ describe('Project Phases', () => {
195
196
request ( server )
196
197
. patch ( `/v5/projects/${ projectId } /phases/${ phaseId } ` )
197
198
. set ( {
198
- Authorization : `Bearer ${ testUtil . jwts . manager } ` ,
199
+ Authorization : `Bearer ${ testUtil . jwts . admin } ` ,
199
200
} )
200
201
. send ( {
201
202
progress : - 15 ,
@@ -208,7 +209,7 @@ describe('Project Phases', () => {
208
209
request ( server )
209
210
. patch ( `/v5/projects/${ projectId } /phases/${ phaseId } ` )
210
211
. set ( {
211
- Authorization : `Bearer ${ testUtil . jwts . copilot } ` ,
212
+ Authorization : `Bearer ${ testUtil . jwts . admin } ` ,
212
213
} )
213
214
. send ( {
214
215
endDate : '2018-05-13T00:00:00Z' ,
@@ -355,168 +356,24 @@ describe('Project Phases', () => {
355
356
let createEventSpy ;
356
357
const sandbox = sinon . sandbox . create ( ) ;
357
358
359
+
358
360
before ( ( done ) => {
359
361
// Wait for 500ms in order to wait for createEvent calls from previous tests to complete
360
362
testUtil . wait ( done ) ;
361
363
} ) ;
362
364
365
+
363
366
beforeEach ( ( ) => {
364
367
createEventSpy = sandbox . spy ( busApi , 'createEvent' ) ;
365
368
} ) ;
366
369
370
+
367
371
afterEach ( ( ) => {
368
372
sandbox . restore ( ) ;
369
373
} ) ;
370
374
371
- it ( 'should NOT send message BUS_API_EVENT.PROJECT_PLAN_UPDATED when spentBudget updated' , ( done ) => {
372
- request ( server )
373
- . patch ( `/v5/projects/${ projectId } /phases/${ phaseId } ` )
374
- . set ( {
375
- Authorization : `Bearer ${ testUtil . jwts . copilot } ` ,
376
- } )
377
- . send ( {
378
- spentBudget : 123 ,
379
- } )
380
- . expect ( 'Content-Type' , / j s o n / )
381
- . expect ( 200 )
382
- . end ( ( err ) => {
383
- if ( err ) {
384
- done ( err ) ;
385
- } else {
386
- testUtil . wait ( ( ) => {
387
- createEventSpy . calledOnce . should . be . true ;
388
-
389
- createEventSpy . firstCall . calledWith ( BUS_API_EVENT . PROJECT_PHASE_UPDATE_PAYMENT ) ;
390
- done ( ) ;
391
- } ) ;
392
- }
393
- } ) ;
394
- } ) ;
395
-
396
375
397
- it ( 'should NOT send message BUS_API_EVENT.PROJECT_PLAN_UPDATED when progress updated' , ( done ) => {
398
- request ( server )
399
- . patch ( `/v5/projects/${ projectId } /phases/${ phaseId } ` )
400
- . set ( {
401
- Authorization : `Bearer ${ testUtil . jwts . copilot } ` ,
402
- } )
403
- . send ( {
404
- progress : 50 ,
405
- } )
406
- . expect ( 'Content-Type' , / j s o n / )
407
- . expect ( 200 )
408
- . end ( ( err ) => {
409
- if ( err ) {
410
- done ( err ) ;
411
- } else {
412
- testUtil . wait ( ( ) => {
413
- createEventSpy . callCount . should . be . eql ( 1 ) ;
414
- createEventSpy . firstCall . calledWith ( BUS_API_EVENT . PROJECT_PHASE_UPDATED ) ;
415
- done ( ) ;
416
- } ) ;
417
- }
418
- } ) ;
419
- } ) ;
420
-
421
- it ( 'should NOT send message BUS_API_EVENT.PROJECT_PLAN_UPDATED when details updated' , ( done ) => {
422
- request ( server )
423
- . patch ( `/v5/projects/${ projectId } /phases/${ phaseId } ` )
424
- . set ( {
425
- Authorization : `Bearer ${ testUtil . jwts . copilot } ` ,
426
- } )
427
- . send ( {
428
- details : {
429
- text : 'something' ,
430
- } ,
431
- } )
432
- . expect ( 'Content-Type' , / j s o n / )
433
- . expect ( 200 )
434
- . end ( ( err ) => {
435
- if ( err ) {
436
- done ( err ) ;
437
- } else {
438
- testUtil . wait ( ( ) => {
439
- createEventSpy . calledOnce . should . be . true ;
440
- createEventSpy . firstCall . calledWith ( BUS_API_EVENT . PROJECT_PHASE_UPDATE_SCOPE ) ;
441
- done ( ) ;
442
- } ) ;
443
- }
444
- } ) ;
445
- } ) ;
446
-
447
- it ( 'should NOT send message BUS_API_EVENT.PROJECT_PLAN_UPDATED when status updated (completed)' , ( done ) => {
448
- request ( server )
449
- . patch ( `/v5/projects/${ projectId } /phases/${ phaseId } ` )
450
- . set ( {
451
- Authorization : `Bearer ${ testUtil . jwts . copilot } ` ,
452
- } )
453
- . send ( {
454
- status : 'completed' ,
455
- } )
456
- . expect ( 'Content-Type' , / j s o n / )
457
- . expect ( 200 )
458
- . end ( ( err ) => {
459
- if ( err ) {
460
- done ( err ) ;
461
- } else {
462
- testUtil . wait ( ( ) => {
463
- createEventSpy . calledOnce . should . be . true ;
464
- createEventSpy . firstCall . calledWith ( BUS_API_EVENT . PROJECT_PHASE_TRANSITION_COMPLETED ) ;
465
- done ( ) ;
466
- } ) ;
467
- }
468
- } ) ;
469
- } ) ;
470
-
471
- it ( 'should NOT send message BUS_API_EVENT.PROJECT_PLAN_UPDATED when status updated (active)' , ( done ) => {
472
- request ( server )
473
- . patch ( `/v5/projects/${ projectId } /phases/${ phaseId3 } ` )
474
- . set ( {
475
- Authorization : `Bearer ${ testUtil . jwts . copilot } ` ,
476
- } )
477
- . send ( {
478
- status : 'active' ,
479
- } )
480
- . expect ( 'Content-Type' , / j s o n / )
481
- . expect ( 200 )
482
- . end ( ( err ) => {
483
- if ( err ) {
484
- done ( err ) ;
485
- } else {
486
- testUtil . wait ( ( ) => {
487
- createEventSpy . calledOnce . should . be . true ;
488
- createEventSpy . firstCall . calledWith ( BUS_API_EVENT . PROJECT_PHASE_TRANSITION_ACTIVE ) ;
489
- done ( ) ;
490
- } ) ;
491
- }
492
- } ) ;
493
- } ) ;
494
-
495
- it ( 'should NOT send message BUS_API_EVENT.PROJECT_PLAN_UPDATED when budget updated' , ( done ) => {
496
- request ( server )
497
- . patch ( `/v5/projects/${ projectId } /phases/${ phaseId } ` )
498
- . set ( {
499
- Authorization : `Bearer ${ testUtil . jwts . copilot } ` ,
500
- } )
501
- . send ( {
502
- budget : 123 ,
503
- } )
504
- . expect ( 'Content-Type' , / j s o n / )
505
- . expect ( 200 )
506
- . end ( ( err ) => {
507
- if ( err ) {
508
- done ( err ) ;
509
- } else {
510
- testUtil . wait ( ( ) => {
511
- createEventSpy . calledOnce . should . be . true ;
512
- createEventSpy . firstCall . calledWith ( BUS_API_EVENT . PROJECT_PHASE_UPDATED ) ;
513
- done ( ) ;
514
- } ) ;
515
- }
516
- } ) ;
517
- } ) ;
518
-
519
- it ( 'should send message BUS_API_EVENT.PROJECT_PLAN_UPDATED when startDate updated' , ( done ) => {
376
+ it ( 'should send message BUS_API_EVENT.PROJECT_PHASE_UPDATED when startDate updated' , ( done ) => {
520
377
request ( server )
521
378
. patch ( `/v5/projects/${ projectId } /phases/${ phaseId } ` )
522
379
. set ( {
@@ -532,16 +389,21 @@ describe('Project Phases', () => {
532
389
done ( err ) ;
533
390
} else {
534
391
testUtil . wait ( ( ) => {
535
- createEventSpy . calledOnce . should . be . true ;
392
+ // createEventSpy.calledOnce.should.be.true;
536
393
createEventSpy . calledWith ( BUS_API_EVENT . PROJECT_PHASE_UPDATED ,
537
- sinon . match . has ( 'startDate' ) ) . should . be . true ;
394
+ sinon . match ( { resource : RESOURCES . PHASE } ) ) . should . be . true ;
395
+ createEventSpy . calledWith ( BUS_API_EVENT . PROJECT_PHASE_UPDATED ,
396
+ sinon . match ( { id : phaseId } ) ) . should . be . true ;
397
+ createEventSpy . calledWith ( BUS_API_EVENT . PROJECT_PHASE_UPDATED ,
398
+ sinon . match ( { updatedBy : testUtil . userIds . copilot } ) ) . should . be . true ;
538
399
done ( ) ;
539
400
} ) ;
540
401
}
541
402
} ) ;
542
403
} ) ;
543
404
544
- it ( 'should send message BUS_API_EVENT.PROJECT_PLAN_UPDATED when duration updated' , ( done ) => {
405
+
406
+ it ( 'should send message BUS_API_EVENT.PROJECT_PHASE_UPDATED when duration updated' , ( done ) => {
545
407
request ( server )
546
408
. patch ( `/v5/projects/${ projectId } /phases/${ phaseId } ` )
547
409
. set ( {
@@ -565,54 +427,6 @@ describe('Project Phases', () => {
565
427
}
566
428
} ) ;
567
429
} ) ;
568
-
569
- it ( 'should not send message BUS_API_EVENT.PROJECT_PLAN_UPDATED when order updated' , ( done ) => {
570
- request ( server )
571
- . patch ( `/v5/projects/${ projectId } /phases/${ phaseId } ` )
572
- . set ( {
573
- Authorization : `Bearer ${ testUtil . jwts . copilot } ` ,
574
- } )
575
- . send ( {
576
- order : 100 ,
577
- } )
578
- . expect ( 'Content-Type' , / j s o n / )
579
- . expect ( 200 )
580
- . end ( ( err ) => {
581
- if ( err ) {
582
- done ( err ) ;
583
- } else {
584
- testUtil . wait ( ( ) => {
585
- createEventSpy . calledOnce . should . be . true ;
586
- createEventSpy . firstCall . calledWith ( BUS_API_EVENT . PROJECT_PHASE_UPDATED ) ;
587
- done ( ) ;
588
- } ) ;
589
- }
590
- } ) ;
591
- } ) ;
592
-
593
- it ( 'should not send message BUS_API_EVENT.PROJECT_PLAN_UPDATED when endDate updated' , ( done ) => {
594
- request ( server )
595
- . patch ( `/v5/projects/${ projectId } /phases/${ phaseId } ` )
596
- . set ( {
597
- Authorization : `Bearer ${ testUtil . jwts . copilot } ` ,
598
- } )
599
- . send ( {
600
- endDate : new Date ( ) ,
601
- } )
602
- . expect ( 'Content-Type' , / j s o n / )
603
- . expect ( 200 )
604
- . end ( ( err ) => {
605
- if ( err ) {
606
- done ( err ) ;
607
- } else {
608
- testUtil . wait ( ( ) => {
609
- createEventSpy . calledOnce . should . be . true ;
610
- createEventSpy . firstCall . calledWith ( BUS_API_EVENT . PROJECT_PHASE_UPDATED ) ;
611
- done ( ) ;
612
- } ) ;
613
- }
614
- } ) ;
615
- } ) ;
616
430
} ) ;
617
431
618
432
describe ( 'RabbitMQ Message topic' , ( ) => {
0 commit comments