@@ -462,56 +462,23 @@ describe('UPDATE Milestone', () => {
462
462
. expect ( 200 , done ) ;
463
463
} ) ;
464
464
465
- it ( 'should return 422 if startDate is after endDate' , ( done ) => {
466
- const invalidBody = {
467
- param : _ . assign ( { } , body . param , {
468
- startDate : '2018-05-29T00:00:00.000Z' ,
469
- endDate : '2018-05-28T00:00:00.000Z' ,
470
- } ) ,
471
- } ;
472
-
473
- request ( server )
474
- . patch ( '/v4/timelines/1/milestones/1' )
475
- . set ( {
476
- Authorization : `Bearer ${ testUtil . jwts . admin } ` ,
477
- } )
478
- . send ( invalidBody )
479
- . expect ( 'Content-Type' , / j s o n / )
480
- . expect ( 422 , done ) ;
481
- } ) ;
482
-
483
- it ( 'should return 422 if startDate is different than the original startDate' , ( done ) => {
484
- const invalidBody = {
485
- param : _ . assign ( { } , body . param , {
486
- startDate : '2018-07-01T00:00:00.000Z' ,
487
- } ) ,
488
- } ;
489
-
490
- request ( server )
491
- . patch ( '/v4/timelines/1/milestones/1' )
492
- . set ( {
493
- Authorization : `Bearer ${ testUtil . jwts . admin } ` ,
494
- } )
495
- . send ( invalidBody )
496
- . expect ( 'Content-Type' , / j s o n / )
497
- . expect ( 422 , done ) ;
498
- } ) ;
499
-
500
- it ( 'should return 422 if endDate is different than the original endDate' , ( done ) => {
501
- const invalidBody = {
502
- param : _ . assign ( { } , body . param , {
503
- endDate : '2018-07-01T00:00:00.000Z' ,
504
- } ) ,
505
- } ;
506
-
507
- request ( server )
508
- . patch ( '/v4/timelines/1/milestones/1' )
509
- . set ( {
510
- Authorization : `Bearer ${ testUtil . jwts . admin } ` ,
511
- } )
512
- . send ( invalidBody )
513
- . expect ( 'Content-Type' , / j s o n / )
514
- . expect ( 422 , done ) ;
465
+ [ 'startDate' , 'endDate' ] . forEach ( ( field ) => {
466
+ it ( `should return 422 if ${ field } is present in the payload` , ( done ) => {
467
+ const invalidBody = {
468
+ param : _ . assign ( { } , body . param , {
469
+ [ field ] : '2018-07-01T00:00:00.000Z' ,
470
+ } ) ,
471
+ } ;
472
+
473
+ request ( server )
474
+ . patch ( '/v4/timelines/1/milestones/1' )
475
+ . set ( {
476
+ Authorization : `Bearer ${ testUtil . jwts . admin } ` ,
477
+ } )
478
+ . send ( invalidBody )
479
+ . expect ( 'Content-Type' , / j s o n / )
480
+ . expect ( 422 , done ) ;
481
+ } ) ;
515
482
} ) ;
516
483
517
484
it ( 'should return 200 for admin' , ( done ) => {
@@ -717,14 +684,13 @@ describe('UPDATE Milestone', () => {
717
684
. expect ( 200 )
718
685
. end ( ( ) => {
719
686
// Milestone 6: order 0
720
- setTimeout ( ( ) => {
721
- models . Milestone . findById ( 6 )
722
- . then ( ( milestone ) => {
723
- milestone . order . should . be . eql ( 0 ) ;
724
-
725
- done ( ) ;
726
- } ) ;
727
- } , 3000 ) ;
687
+ models . Milestone . findById ( 6 )
688
+ . then ( ( milestone ) => {
689
+ milestone . order . should . be . eql ( 0 ) ;
690
+
691
+ done ( ) ;
692
+ } )
693
+ . catch ( done ) ;
728
694
} ) ;
729
695
} ) ;
730
696
@@ -782,22 +748,21 @@ describe('UPDATE Milestone', () => {
782
748
// Milestone 6: order 1 => 1
783
749
// Milestone 7: order 3 => 3
784
750
// Milestone 8: order 4 => 2
785
- setTimeout ( ( ) => {
786
- models . Milestone . findById ( 6 )
787
- . then ( ( milestone ) => {
788
- milestone . order . should . be . eql ( 1 ) ;
789
- } )
790
- . then ( ( ) => models . Milestone . findById ( 7 ) )
791
- . then ( ( milestone ) => {
792
- milestone . order . should . be . eql ( 3 ) ;
793
- } )
794
- . then ( ( ) => models . Milestone . findById ( 8 ) )
795
- . then ( ( milestone ) => {
796
- milestone . order . should . be . eql ( 2 ) ;
797
-
798
- done ( ) ;
799
- } ) ;
800
- } , 3000 ) ;
751
+ models . Milestone . findById ( 6 )
752
+ . then ( ( milestone ) => {
753
+ milestone . order . should . be . eql ( 1 ) ;
754
+ } )
755
+ . then ( ( ) => models . Milestone . findById ( 7 ) )
756
+ . then ( ( milestone ) => {
757
+ milestone . order . should . be . eql ( 3 ) ;
758
+ } )
759
+ . then ( ( ) => models . Milestone . findById ( 8 ) )
760
+ . then ( ( milestone ) => {
761
+ milestone . order . should . be . eql ( 2 ) ;
762
+
763
+ done ( ) ;
764
+ } )
765
+ . catch ( done ) ;
801
766
} ) ;
802
767
} ) ;
803
768
} ) ;
@@ -856,22 +821,21 @@ describe('UPDATE Milestone', () => {
856
821
// Milestone 6: order 1 => 1
857
822
// Milestone 7: order 2 => 3
858
823
// Milestone 8: order 4 => 2
859
- setTimeout ( ( ) => {
860
- models . Milestone . findById ( 6 )
861
- . then ( ( milestone ) => {
862
- milestone . order . should . be . eql ( 1 ) ;
863
- } )
864
- . then ( ( ) => models . Milestone . findById ( 7 ) )
865
- . then ( ( milestone ) => {
866
- milestone . order . should . be . eql ( 3 ) ;
867
- } )
868
- . then ( ( ) => models . Milestone . findById ( 8 ) )
869
- . then ( ( milestone ) => {
870
- milestone . order . should . be . eql ( 2 ) ;
871
-
872
- done ( ) ;
873
- } ) ;
874
- } , 3000 ) ;
824
+ models . Milestone . findById ( 6 )
825
+ . then ( ( milestone ) => {
826
+ milestone . order . should . be . eql ( 1 ) ;
827
+ } )
828
+ . then ( ( ) => models . Milestone . findById ( 7 ) )
829
+ . then ( ( milestone ) => {
830
+ milestone . order . should . be . eql ( 3 ) ;
831
+ } )
832
+ . then ( ( ) => models . Milestone . findById ( 8 ) )
833
+ . then ( ( milestone ) => {
834
+ milestone . order . should . be . eql ( 2 ) ;
835
+
836
+ done ( ) ;
837
+ } )
838
+ . catch ( done ) ;
875
839
} ) ;
876
840
} ) ;
877
841
} ) ;
@@ -895,20 +859,18 @@ describe('UPDATE Milestone', () => {
895
859
// endDate: null to '2018-05-21T00:00:00.000Z'
896
860
// Milestone 4: startDate: '2018-05-14T00:00:00.000Z' to '2018-05-22T00:00:00.000Z'
897
861
// endDate: null to '2018-05-24T00:00:00.000Z'
898
- setTimeout ( ( ) => {
899
- models . Milestone . findById ( 3 )
900
- . then ( ( milestone ) => {
901
- milestone . startDate . should . be . eql ( new Date ( '2018-05-19T00:00:00.000Z' ) ) ;
902
- milestone . endDate . should . be . eql ( new Date ( '2018-05-21T00:00:00.000Z' ) ) ;
903
- return models . Milestone . findById ( 4 ) ;
904
- } )
905
- . then ( ( milestone ) => {
906
- milestone . startDate . should . be . eql ( new Date ( '2018-05-22T00:00:00.000Z' ) ) ;
907
- milestone . endDate . should . be . eql ( new Date ( '2018-05-24T00:00:00.000Z' ) ) ;
908
- done ( ) ;
909
- } )
910
- . catch ( done ) ;
911
- } , 3000 ) ;
862
+ models . Milestone . findById ( 3 )
863
+ . then ( ( milestone ) => {
864
+ milestone . startDate . should . be . eql ( new Date ( '2018-05-19T00:00:00.000Z' ) ) ;
865
+ milestone . endDate . should . be . eql ( new Date ( '2018-05-21T00:00:00.000Z' ) ) ;
866
+ return models . Milestone . findById ( 4 ) ;
867
+ } )
868
+ . then ( ( milestone ) => {
869
+ milestone . startDate . should . be . eql ( new Date ( '2018-05-22T00:00:00.000Z' ) ) ;
870
+ milestone . endDate . should . be . eql ( new Date ( '2018-05-24T00:00:00.000Z' ) ) ;
871
+ done ( ) ;
872
+ } )
873
+ . catch ( done ) ;
912
874
} ) ;
913
875
} ) ;
914
876
@@ -929,20 +891,18 @@ describe('UPDATE Milestone', () => {
929
891
// endDate: null to '2018-05-21T00:00:00.000Z'
930
892
// Milestone 4: startDate: '2018-05-14T00:00:00.000Z' to '2018-05-22T00:00:00.000Z'
931
893
// endDate: null to '2018-05-24T00:00:00.000Z'
932
- setTimeout ( ( ) => {
933
- models . Milestone . findById ( 3 )
934
- . then ( ( milestone ) => {
935
- milestone . startDate . should . be . eql ( new Date ( '2018-05-19T00:00:00.000Z' ) ) ;
936
- milestone . endDate . should . be . eql ( new Date ( '2018-05-21T00:00:00.000Z' ) ) ;
937
- return models . Milestone . findById ( 4 ) ;
938
- } )
939
- . then ( ( milestone ) => {
940
- milestone . startDate . should . be . eql ( new Date ( '2018-05-22T00:00:00.000Z' ) ) ;
941
- milestone . endDate . should . be . eql ( new Date ( '2018-05-24T00:00:00.000Z' ) ) ;
942
- done ( ) ;
943
- } )
944
- . catch ( done ) ;
945
- } , 3000 ) ;
894
+ models . Milestone . findById ( 3 )
895
+ . then ( ( milestone ) => {
896
+ milestone . startDate . should . be . eql ( new Date ( '2018-05-19T00:00:00.000Z' ) ) ;
897
+ milestone . endDate . should . be . eql ( new Date ( '2018-05-21T00:00:00.000Z' ) ) ;
898
+ return models . Milestone . findById ( 4 ) ;
899
+ } )
900
+ . then ( ( milestone ) => {
901
+ milestone . startDate . should . be . eql ( new Date ( '2018-05-22T00:00:00.000Z' ) ) ;
902
+ milestone . endDate . should . be . eql ( new Date ( '2018-05-24T00:00:00.000Z' ) ) ;
903
+ done ( ) ;
904
+ } )
905
+ . catch ( done ) ;
946
906
} ) ;
947
907
} ) ;
948
908
0 commit comments