@@ -697,8 +697,21 @@ module.exports = () => {
697697 const fourthFlagFrom = new Date ( '2024-07-01 13:00:00' ) . getTime ( ) ;
698698 const fourthFlagTo = new Date ( '2024-07-01 15:00:00' ) . getTime ( ) ;
699699
700+ /*
701+ * --- 12 - 13 - 14 - 15 - 16 - 17 --> hours
702+ * ( ) First flag
703+ * ( ]----------------------------- Second flag
704+ * ------------------------[ ) Third flag
705+ * ---------[ ]-------------- Fourth flag
706+ */
707+
700708 // 1
701709 {
710+ /*
711+ * --- 12 - 13 - 14 - 15 - 16 - 17 --> hours
712+ * ( ) First flag effective period
713+ */
714+
702715 const from = null ;
703716 const to = null ;
704717 const [ qcFlag ] = await qcFlagService . create (
@@ -720,6 +733,11 @@ module.exports = () => {
720733
721734 // 2
722735 {
736+ /*
737+ * --- 12 - 13 - 14 - 15 - 16 - 17 --> hours
738+ * -----[ ) First flag effective period
739+ * ( ]----------------------------- Second flag effective period
740+ */
723741 const from = null ;
724742 const to = secondFlagTo ;
725743 const [ qcFlag ] = await qcFlagService . create (
@@ -741,12 +759,19 @@ module.exports = () => {
741759 // Previous: first flag
742760 const firstFlagEffectivePeriods = await getEffectivePeriodsOfQcFlag ( createdFlagIds [ 0 ] ) ;
743761 expect ( firstFlagEffectivePeriods ) . to . lengthOf ( 1 ) ;
744- expect ( firstFlagEffectivePeriods [ 0 ] . from ) . to . equal ( secondFlagTo ) ;
762+ expect ( firstFlagEffectivePeriods [ 0 ] . from ) . to . equal ( to ) ;
745763 expect ( firstFlagEffectivePeriods [ 0 ] . to ) . to . equal ( null ) ;
746764 }
747765
748766 // 3
749767 {
768+ /*
769+ * --- 12 - 13 - 14 - 15 - 16 - 17 --> hours
770+ * -----[ ]---------- First flag effective period
771+ * ( ]----------------------------- Second flag effective period
772+ * ------------------------[ ) Third flag effective period
773+ */
774+
750775 const from = thirdFlagFrom ;
751776 const to = null ;
752777 const [ qcFlag ] = await qcFlagService . create (
@@ -780,6 +805,14 @@ module.exports = () => {
780805
781806 // 4
782807 {
808+ /*
809+ * --- 12 - 13 - 14 - 15 - 16 - 17 --> hours
810+ * -----[ ]----------[ ]---------- First flag effective periods
811+ * ( ]----------------------------- Second flag effective period
812+ * ------------------------[ ) Third flag effective period
813+ * ---------[ ]-------------- Fourth flag effective period
814+ */
815+
783816 const from = fourthFlagFrom ;
784817 const to = fourthFlagTo ;
785818 const [ qcFlag ] = await qcFlagService . create (
@@ -791,6 +824,31 @@ module.exports = () => {
791824 } ,
792825 relations ,
793826 ) ;
827+
828+ const newFlagEffectivePeriods = await getEffectivePeriodsOfQcFlag ( qcFlag . id ) ;
829+ expect ( newFlagEffectivePeriods ) . to . lengthOf ( 1 ) ;
830+ expect ( newFlagEffectivePeriods [ 0 ] . from ) . to . equal ( from ) ;
831+ expect ( newFlagEffectivePeriods [ 0 ] . to ) . to . equal ( to ) ;
832+
833+ // Previous: first flag
834+ const firstFlagEffectivePeriods = await getEffectivePeriodsOfQcFlag ( createdFlagIds [ 0 ] ) ;
835+ expect ( firstFlagEffectivePeriods ) . to . lengthOf ( 2 ) ;
836+ expect ( firstFlagEffectivePeriods [ 0 ] . from ) . to . equal ( secondFlagTo ) ;
837+ expect ( firstFlagEffectivePeriods [ 0 ] . to ) . to . equal ( from ) ;
838+ expect ( firstFlagEffectivePeriods [ 1 ] . from ) . to . equal ( to ) ;
839+ expect ( firstFlagEffectivePeriods [ 1 ] . to ) . to . equal ( thirdFlagFrom ) ;
840+
841+ // Previous: second flag
842+ const secondFlagEffectivePeriods = await getEffectivePeriodsOfQcFlag ( createdFlagIds [ 1 ] ) ;
843+ expect ( secondFlagEffectivePeriods ) . to . lengthOf ( 1 ) ;
844+ expect ( secondFlagEffectivePeriods [ 0 ] . from ) . to . equal ( null ) ;
845+ expect ( secondFlagEffectivePeriods [ 0 ] . to ) . to . equal ( secondFlagTo ) ;
846+
847+ // Previous: third flag
848+ const thirdFlagEffectivePeriods = await getEffectivePeriodsOfQcFlag ( createdFlagIds [ 2 ] ) ;
849+ expect ( thirdFlagEffectivePeriods ) . to . lengthOf ( 1 ) ;
850+ expect ( thirdFlagEffectivePeriods [ 0 ] . from ) . to . equal ( thirdFlagFrom ) ;
851+ expect ( thirdFlagEffectivePeriods [ 0 ] . to ) . to . equal ( null ) ;
794852 }
795853 } ) ;
796854 } ) ;
0 commit comments