@@ -225,6 +225,24 @@ describe('UPDATE Milestone', () => {
225
225
updatedAt : '2018-05-11T00:00:00.000Z' ,
226
226
deletedAt : '2018-05-11T00:00:00.000Z' ,
227
227
} ,
228
+ {
229
+ id : 6 ,
230
+ timelineId : 2 , // Timeline 2
231
+ name : 'Milestone 6' ,
232
+ duration : 3 ,
233
+ startDate : '2018-05-14T00:00:00.000Z' ,
234
+ status : 'open' ,
235
+ type : 'type5' ,
236
+ order : 1 ,
237
+ plannedText : 'plannedText 6' ,
238
+ activeText : 'activeText 6' ,
239
+ completedText : 'completedText 6' ,
240
+ blockedText : 'blockedText 6' ,
241
+ createdBy : 2 ,
242
+ updatedBy : 3 ,
243
+ createdAt : '2018-05-11T00:00:00.000Z' ,
244
+ updatedAt : '2018-05-11T00:00:00.000Z' ,
245
+ } ,
228
246
] ) ) )
229
247
. then ( ( ) => done ( ) ) ;
230
248
} ) ;
@@ -718,8 +736,8 @@ describe('UPDATE Milestone', () => {
718
736
. expect ( 200 )
719
737
. end ( ( ) => {
720
738
// Milestone 1: order 1
721
- // Milestone 2: order 3
722
- // Milestone 3: order 4
739
+ // Milestone 2: order 2
740
+ // Milestone 3: order 3
723
741
// Milestone 4: order 0
724
742
setTimeout ( ( ) => {
725
743
models . Milestone . findById ( 1 )
@@ -744,6 +762,178 @@ describe('UPDATE Milestone', () => {
744
762
} ) ;
745
763
} ) ;
746
764
765
+ // eslint-disable-next-line func-names
766
+ it ( 'should return 200 for admin - changing order with only 1 item in list' , function ( done ) {
767
+ this . timeout ( 10000 ) ;
768
+
769
+ request ( server )
770
+ . patch ( '/v4/timelines/2/milestones/6' )
771
+ . set ( {
772
+ Authorization : `Bearer ${ testUtil . jwts . admin } ` ,
773
+ } )
774
+ . send ( { param : _ . assign ( { } , body . param , { order : 0 } ) } ) // 1 to 0
775
+ . expect ( 200 )
776
+ . end ( ( ) => {
777
+ // Milestone 6: order 0
778
+ setTimeout ( ( ) => {
779
+ models . Milestone . findById ( 6 )
780
+ . then ( ( milestone ) => {
781
+ milestone . order . should . be . eql ( 0 ) ;
782
+
783
+ done ( ) ;
784
+ } ) ;
785
+ } , 3000 ) ;
786
+ } ) ;
787
+ } ) ;
788
+
789
+ // eslint-disable-next-line func-names
790
+ it ( 'should return 200 for admin - changing order without changing other milestones\' orders' , function ( done ) {
791
+ this . timeout ( 10000 ) ;
792
+
793
+ models . Milestone . bulkCreate ( [
794
+ {
795
+ id : 7 ,
796
+ timelineId : 2 , // Timeline 2
797
+ name : 'Milestone 7' ,
798
+ duration : 3 ,
799
+ startDate : '2018-05-14T00:00:00.000Z' ,
800
+ status : 'open' ,
801
+ type : 'type7' ,
802
+ order : 3 ,
803
+ plannedText : 'plannedText 7' ,
804
+ activeText : 'activeText 7' ,
805
+ completedText : 'completedText 7' ,
806
+ blockedText : 'blockedText 7' ,
807
+ createdBy : 2 ,
808
+ updatedBy : 3 ,
809
+ createdAt : '2018-05-11T00:00:00.000Z' ,
810
+ updatedAt : '2018-05-11T00:00:00.000Z' ,
811
+ } ,
812
+ {
813
+ id : 8 ,
814
+ timelineId : 2 , // Timeline 2
815
+ name : 'Milestone 8' ,
816
+ duration : 3 ,
817
+ startDate : '2018-05-14T00:00:00.000Z' ,
818
+ status : 'open' ,
819
+ type : 'type7' ,
820
+ order : 4 ,
821
+ plannedText : 'plannedText 8' ,
822
+ activeText : 'activeText 8' ,
823
+ completedText : 'completedText 8' ,
824
+ blockedText : 'blockedText 8' ,
825
+ createdBy : 2 ,
826
+ updatedBy : 3 ,
827
+ createdAt : '2018-05-11T00:00:00.000Z' ,
828
+ updatedAt : '2018-05-11T00:00:00.000Z' ,
829
+ } ,
830
+ ] )
831
+ . then ( ( ) => {
832
+ request ( server )
833
+ . patch ( '/v4/timelines/2/milestones/8' )
834
+ . set ( {
835
+ Authorization : `Bearer ${ testUtil . jwts . admin } ` ,
836
+ } )
837
+ . send ( { param : _ . assign ( { } , body . param , { order : 2 } ) } ) // 4 to 2
838
+ . expect ( 200 )
839
+ . end ( ( ) => {
840
+ // Milestone 6: order 1 => 1
841
+ // Milestone 7: order 3 => 3
842
+ // Milestone 8: order 4 => 2
843
+ setTimeout ( ( ) => {
844
+ models . Milestone . findById ( 6 )
845
+ . then ( ( milestone ) => {
846
+ milestone . order . should . be . eql ( 1 ) ;
847
+ } )
848
+ . then ( ( ) => models . Milestone . findById ( 7 ) )
849
+ . then ( ( milestone ) => {
850
+ milestone . order . should . be . eql ( 3 ) ;
851
+ } )
852
+ . then ( ( ) => models . Milestone . findById ( 8 ) )
853
+ . then ( ( milestone ) => {
854
+ milestone . order . should . be . eql ( 2 ) ;
855
+
856
+ done ( ) ;
857
+ } ) ;
858
+ } , 3000 ) ;
859
+ } ) ;
860
+ } ) ;
861
+ } ) ;
862
+
863
+ // eslint-disable-next-line func-names
864
+ it ( 'should return 200 for admin - changing order withchanging other milestones\' orders' , function ( done ) {
865
+ this . timeout ( 10000 ) ;
866
+
867
+ models . Milestone . bulkCreate ( [
868
+ {
869
+ id : 7 ,
870
+ timelineId : 2 , // Timeline 2
871
+ name : 'Milestone 7' ,
872
+ duration : 3 ,
873
+ startDate : '2018-05-14T00:00:00.000Z' ,
874
+ status : 'open' ,
875
+ type : 'type7' ,
876
+ order : 2 ,
877
+ plannedText : 'plannedText 7' ,
878
+ activeText : 'activeText 7' ,
879
+ completedText : 'completedText 7' ,
880
+ blockedText : 'blockedText 7' ,
881
+ createdBy : 2 ,
882
+ updatedBy : 3 ,
883
+ createdAt : '2018-05-11T00:00:00.000Z' ,
884
+ updatedAt : '2018-05-11T00:00:00.000Z' ,
885
+ } ,
886
+ {
887
+ id : 8 ,
888
+ timelineId : 2 , // Timeline 2
889
+ name : 'Milestone 8' ,
890
+ duration : 3 ,
891
+ startDate : '2018-05-14T00:00:00.000Z' ,
892
+ status : 'open' ,
893
+ type : 'type7' ,
894
+ order : 4 ,
895
+ plannedText : 'plannedText 8' ,
896
+ activeText : 'activeText 8' ,
897
+ completedText : 'completedText 8' ,
898
+ blockedText : 'blockedText 8' ,
899
+ createdBy : 2 ,
900
+ updatedBy : 3 ,
901
+ createdAt : '2018-05-11T00:00:00.000Z' ,
902
+ updatedAt : '2018-05-11T00:00:00.000Z' ,
903
+ } ,
904
+ ] )
905
+ . then ( ( ) => {
906
+ request ( server )
907
+ . patch ( '/v4/timelines/2/milestones/8' )
908
+ . set ( {
909
+ Authorization : `Bearer ${ testUtil . jwts . admin } ` ,
910
+ } )
911
+ . send ( { param : _ . assign ( { } , body . param , { order : 2 } ) } ) // 4 to 2
912
+ . expect ( 200 )
913
+ . end ( ( ) => {
914
+ // Milestone 6: order 1 => 1
915
+ // Milestone 7: order 2 => 3
916
+ // Milestone 8: order 4 => 2
917
+ setTimeout ( ( ) => {
918
+ models . Milestone . findById ( 6 )
919
+ . then ( ( milestone ) => {
920
+ milestone . order . should . be . eql ( 1 ) ;
921
+ } )
922
+ . then ( ( ) => models . Milestone . findById ( 7 ) )
923
+ . then ( ( milestone ) => {
924
+ milestone . order . should . be . eql ( 3 ) ;
925
+ } )
926
+ . then ( ( ) => models . Milestone . findById ( 8 ) )
927
+ . then ( ( milestone ) => {
928
+ milestone . order . should . be . eql ( 2 ) ;
929
+
930
+ done ( ) ;
931
+ } ) ;
932
+ } , 3000 ) ;
933
+ } ) ;
934
+ } ) ;
935
+ } ) ;
936
+
747
937
it ( 'should return 200 for connect admin' , ( done ) => {
748
938
request ( server )
749
939
. patch ( '/v4/timelines/1/milestones/1' )
0 commit comments