@@ -841,10 +841,66 @@ describe('UPDATE Milestone', () => {
841841 } ) ;
842842 } ) ;
843843
844+ it ( 'should return 200 for admin - marking milestone active later will cascade changes to coming ' +
845+ // eslint-disable-next-line func-names
846+ 'milestones' , function ( done ) {
847+ this . timeout ( 10000 ) ;
848+ const today = moment . utc ( ) . hours ( 0 ) . minutes ( 0 ) . seconds ( 0 )
849+ . milliseconds ( 0 ) ;
850+
851+ request ( server )
852+ . patch ( '/v4/timelines/1/milestones/2' )
853+ . set ( {
854+ Authorization : `Bearer ${ testUtil . jwts . admin } ` ,
855+ } )
856+ . send ( { param : { status : MILESTONE_STATUS . ACTIVE } } )
857+ . expect ( 200 )
858+ . end ( ( ) => {
859+ // Milestone 2: startDate: '2018-05-14T00:00:00.000Z' to '2018-05-14T00:00:00.000Z'
860+ // actualStartDate: null to today
861+ // endDate: null to today + 2 (2 = duration - 1)
862+ // Milestone 3: startDate: '2018-05-14T00:00:00.000Z' to today + 3
863+ // endDate: null to today + 5 (5 = 3 + duration - 1)
864+ // Milestone 4: startDate: '2018-05-14T00:00:00.000Z' to today + 6
865+ // endDate: null to today + 8 (2 = 6 + duration - 1)
866+ models . Milestone . findById ( 2 )
867+ . then ( ( milestone ) => {
868+ should . exist ( milestone . actualStartDate ) ;
869+ moment . utc ( milestone . actualStartDate ) . diff ( today , 'days' ) . should . be . eql ( 0 ) ;
870+ // start date of the updated milestone should not change
871+ milestone . startDate . should . be . eql ( new Date ( '2018-05-14T00:00:00.000Z' ) ) ;
872+ today . add ( 'days' , milestone . duration - 1 ) ;
873+ // end date of the updated milestone should change, as delayed start caused scheduled to be delayed
874+ moment . utc ( milestone . endDate ) . diff ( today , 'days' ) . should . be . eql ( 0 ) ;
875+ milestone . status . should . be . eql ( MILESTONE_STATUS . ACTIVE ) ;
876+ return models . Milestone . findById ( 3 ) ;
877+ } )
878+ . then ( ( milestone ) => {
879+ today . add ( 'days' , 1 ) ; // should have start date next to previous one's end date
880+ moment . utc ( milestone . startDate ) . diff ( today , 'days' ) . should . be . eql ( 0 ) ;
881+ should . not . exist ( milestone . actualStartDate ) ;
882+ today . add ( 'days' , milestone . duration - 1 ) ;
883+ moment . utc ( milestone . endDate ) . diff ( today , 'days' ) . should . be . eql ( 0 ) ;
884+ return models . Milestone . findById ( 4 ) ;
885+ } )
886+ . then ( ( milestone ) => {
887+ today . add ( 'days' , 1 ) ; // should have start date next to previous one's end date
888+ moment . utc ( milestone . startDate ) . diff ( today , 'days' ) . should . be . eql ( 0 ) ;
889+ should . not . exist ( milestone . actualStartDate ) ;
890+ today . add ( 'days' , milestone . duration - 1 ) ;
891+ moment . utc ( milestone . endDate ) . diff ( today , 'days' ) . should . be . eql ( 0 ) ;
892+ done ( ) ;
893+ } )
894+ . catch ( done ) ;
895+ } ) ;
896+ } ) ;
897+
844898 it ( 'should return 200 for admin - changing completionDate will cascade changes to coming ' +
845899 // eslint-disable-next-line func-names
846900 'milestones' , function ( done ) {
847901 this . timeout ( 10000 ) ;
902+ const today = moment . utc ( ) . hours ( 0 ) . minutes ( 0 ) . seconds ( 0 )
903+ . milliseconds ( 0 ) ;
848904
849905 request ( server )
850906 . patch ( '/v4/timelines/1/milestones/2' )
@@ -863,7 +919,6 @@ describe('UPDATE Milestone', () => {
863919 models . Milestone . findById ( 3 )
864920 . then ( ( milestone ) => {
865921 milestone . startDate . should . be . eql ( new Date ( '2018-05-19T00:00:00.000Z' ) ) ;
866- const today = moment . utc ( ) ;
867922 should . exist ( milestone . actualStartDate ) ;
868923 moment ( ) . utc ( milestone . actualStartDate ) . diff ( today , 'days' ) . should . be . eql ( 0 ) ;
869924 // milestone.actualStartDate.should.be.eql(today);
0 commit comments