@@ -630,6 +630,8 @@ describe(CachedDataSource, () => {
630630} ) ;
631631
632632describe ( Notices , ( ) => {
633+ const cliVersion = '2.1005.0' ;
634+
633635 beforeEach ( ( ) => {
634636 // disable caching
635637 jest . spyOn ( CachedDataSource . prototype as any , 'save' ) . mockImplementation ( ( _ : any ) => Promise . resolve ( ) ) ;
@@ -642,7 +644,7 @@ describe(Notices, () => {
642644
643645 describe ( 'addBootstrapVersion' , ( ) => {
644646 test ( 'can add multiple values' , async ( ) => {
645- const notices = Notices . create ( { context : new Context ( ) , ioHost } ) ;
647+ const notices = Notices . create ( { context : new Context ( ) , ioHost, cliVersion } ) ;
646648 notices . addBootstrappedEnvironment ( { bootstrapStackVersion : 10 , environment : { account : 'account' , region : 'region' , name : 'env' } } ) ;
647649 notices . addBootstrappedEnvironment ( { bootstrapStackVersion : 11 , environment : { account : 'account' , region : 'region' , name : 'env' } } ) ;
648650
@@ -656,13 +658,10 @@ describe(Notices, () => {
656658 } ) ;
657659
658660 test ( 'deduplicates' , async ( ) => {
659- const notices = Notices . create ( { ioHost, context : new Context ( ) } ) ;
661+ const notices = Notices . create ( { ioHost, context : new Context ( ) , cliVersion : '1.0.0' } ) ;
660662 notices . addBootstrappedEnvironment ( { bootstrapStackVersion : 10 , environment : { account : 'account' , region : 'region' , name : 'env' } } ) ;
661663 notices . addBootstrappedEnvironment ( { bootstrapStackVersion : 10 , environment : { account : 'account' , region : 'region' , name : 'env' } } ) ;
662664
663- // mock cli version number
664- jest . spyOn ( version , 'versionNumber' ) . mockImplementation ( ( ) => '1.0.0' ) ;
665-
666665 notices . display ( ) ;
667666
668667 const filter = jest . spyOn ( NoticesFilter . prototype , 'filter' ) ;
@@ -687,10 +686,7 @@ describe(Notices, () => {
687686
688687 describe ( 'refresh' , ( ) => {
689688 test ( 'deduplicates notices' , async ( ) => {
690- // within the affected version range of the notice
691- jest . spyOn ( version , 'versionNumber' ) . mockImplementation ( ( ) => '1.0.0' ) ;
692-
693- const notices = Notices . create ( { ioHost, context : new Context ( ) } ) ;
689+ const notices = Notices . create ( { ioHost, context : new Context ( ) , cliVersion : '1.0.0' } ) ;
694690 await notices . refresh ( {
695691 dataSource : { fetch : async ( ) => [ BASIC_NOTICE , BASIC_NOTICE ] } ,
696692 } ) ;
@@ -700,10 +696,7 @@ describe(Notices, () => {
700696 } ) ;
701697
702698 test ( 'clears notices if empty' , async ( ) => {
703- // within the affected version range of the notice
704- jest . spyOn ( version , 'versionNumber' ) . mockImplementation ( ( ) => '1.0.0' ) ;
705-
706- const notices = Notices . create ( { ioHost, context : new Context ( ) } ) ;
699+ const notices = Notices . create ( { ioHost, context : new Context ( ) , cliVersion : '1.0.0' } ) ;
707700 await notices . refresh ( {
708701 dataSource : { fetch : async ( ) => [ ] } ,
709702 } ) ;
@@ -713,7 +706,7 @@ describe(Notices, () => {
713706 } ) ;
714707
715708 test ( 'doesnt throw' , async ( ) => {
716- const notices = Notices . create ( { ioHost, context : new Context ( ) } ) ;
709+ const notices = Notices . create ( { ioHost, context : new Context ( ) , cliVersion } ) ;
717710 await notices . refresh ( {
718711 dataSource : {
719712 fetch : async ( ) => {
@@ -724,12 +717,9 @@ describe(Notices, () => {
724717 } ) ;
725718
726719 test ( 'filters out acknowledged notices by default' , async ( ) => {
727- // within the affected version range of both notices
728- jest . spyOn ( version , 'versionNumber' ) . mockImplementation ( ( ) => '1.126.0' ) ;
729-
730720 const context = new Context ( { bag : new Settings ( { 'acknowledged-issue-numbers' : [ MULTIPLE_AFFECTED_VERSIONS_NOTICE . issueNumber ] } ) } ) ;
731721
732- const notices = Notices . create ( { ioHost, context } ) ;
722+ const notices = Notices . create ( { ioHost, context, cliVersion : '1.126.0' } ) ;
733723 await notices . refresh ( {
734724 dataSource : { fetch : async ( ) => [ BASIC_NOTICE , MULTIPLE_AFFECTED_VERSIONS_NOTICE ] } ,
735725 } ) ;
@@ -740,12 +730,9 @@ describe(Notices, () => {
740730 } ) ;
741731
742732 test ( 'preserves acknowledged notices if requested' , async ( ) => {
743- // within the affected version range of both notices
744- jest . spyOn ( version , 'versionNumber' ) . mockImplementation ( ( ) => '1.126.0' ) ;
745-
746733 const context = new Context ( { bag : new Settings ( { 'acknowledged-issue-numbers' : [ MULTIPLE_AFFECTED_VERSIONS_NOTICE . issueNumber ] } ) } ) ;
747734
748- const notices = Notices . create ( { ioHost, context, includeAcknowledged : true } ) ;
735+ const notices = Notices . create ( { ioHost, context, includeAcknowledged : true , cliVersion : '1.126.0' } ) ;
749736 await notices . refresh ( {
750737 dataSource : { fetch : async ( ) => [ BASIC_NOTICE , MULTIPLE_AFFECTED_VERSIONS_NOTICE ] } ,
751738 } ) ;
@@ -758,10 +745,7 @@ describe(Notices, () => {
758745
759746 describe ( 'display' , ( ) => {
760747 test ( 'notices envelop' , async ( ) => {
761- // within the affected version range of the notice
762- jest . spyOn ( version , 'versionNumber' ) . mockImplementation ( ( ) => '1.0.0' ) ;
763-
764- const notices = Notices . create ( { ioHost, context : new Context ( ) } ) ;
748+ const notices = Notices . create ( { ioHost, context : new Context ( ) , cliVersion : '1.0.0' } ) ;
765749 await notices . refresh ( {
766750 dataSource : { fetch : async ( ) => [ BASIC_NOTICE , BASIC_NOTICE ] } ,
767751 } ) ;
@@ -772,10 +756,7 @@ describe(Notices, () => {
772756 } ) ;
773757
774758 test ( 'deduplicates notices' , async ( ) => {
775- // within the affected version range of the notice
776- jest . spyOn ( version , 'versionNumber' ) . mockImplementation ( ( ) => '1.0.0' ) ;
777-
778- const notices = Notices . create ( { ioHost, context : new Context ( ) } ) ;
759+ const notices = Notices . create ( { ioHost, context : new Context ( ) , cliVersion : '1.0.0' } ) ;
779760 await notices . refresh ( {
780761 dataSource : { fetch : async ( ) => [ BASIC_NOTICE , BASIC_NOTICE ] } ,
781762 } ) ;
@@ -786,22 +767,19 @@ describe(Notices, () => {
786767 } ) ;
787768
788769 test ( 'nothing when there are no notices' , async ( ) => {
789- Notices . create ( { ioHost, context : new Context ( ) } ) . display ( ) ;
770+ Notices . create ( { ioHost, context : new Context ( ) , cliVersion } ) . display ( ) ;
790771 // expect a single trace that the tree.json was not found, but nothing else
791772 expect ( ioHost . messages . length ) . toBe ( 1 ) ;
792773 ioHost . expectMessage ( { level : 'trace' , containing : 'Failed to get tree.json file' } ) ;
793774 } ) ;
794775
795776 test ( 'total count when show total is true' , async ( ) => {
796- Notices . create ( { ioHost, context : new Context ( ) } ) . display ( { showTotal : true } ) ;
777+ Notices . create ( { ioHost, context : new Context ( ) , cliVersion } ) . display ( { showTotal : true } ) ;
797778 ioHost . expectMessage ( { containing : 'There are 0 unacknowledged notice(s).' } ) ;
798779 } ) ;
799780
800781 test ( 'warning' , async ( ) => {
801- // within the affected version range of the notice
802- jest . spyOn ( version , 'versionNumber' ) . mockImplementation ( ( ) => '1.0.0' ) ;
803-
804- const notices = Notices . create ( { ioHost, context : new Context ( ) } ) ;
782+ const notices = Notices . create ( { ioHost, context : new Context ( ) , cliVersion : '1.0.0' } ) ;
805783 await notices . refresh ( {
806784 dataSource : { fetch : async ( ) => [ BASIC_WARNING_NOTICE ] } ,
807785 } ) ;
@@ -811,10 +789,7 @@ describe(Notices, () => {
811789 } ) ;
812790
813791 test ( 'error' , async ( ) => {
814- // within the affected version range of the notice
815- jest . spyOn ( version , 'versionNumber' ) . mockImplementation ( ( ) => '1.0.0' ) ;
816-
817- const notices = Notices . create ( { ioHost, context : new Context ( ) } ) ;
792+ const notices = Notices . create ( { ioHost, context : new Context ( ) , cliVersion : '1.0.0' } ) ;
818793 await notices . refresh ( {
819794 dataSource : { fetch : async ( ) => [ BASIC_ERROR_NOTICE ] } ,
820795 } ) ;
@@ -824,10 +799,7 @@ describe(Notices, () => {
824799 } ) ;
825800
826801 test ( 'only relevant notices' , async ( ) => {
827- // within the affected version range of the notice
828- jest . spyOn ( version , 'versionNumber' ) . mockImplementation ( ( ) => '1.0.0' ) ;
829-
830- const notices = Notices . create ( { ioHost, context : new Context ( ) } ) ;
802+ const notices = Notices . create ( { ioHost, context : new Context ( ) , cliVersion : '1.0.0' } ) ;
831803 await notices . refresh ( {
832804 dataSource : { fetch : async ( ) => [ BASIC_NOTICE ] } ,
833805 } ) ;
@@ -837,12 +809,9 @@ describe(Notices, () => {
837809 } ) ;
838810
839811 test ( 'only unacknowledged notices' , async ( ) => {
840- // within the affected version range of both notices
841- jest . spyOn ( version , 'versionNumber' ) . mockImplementation ( ( ) => '1.126.0' ) ;
842-
843812 const context = new Context ( { bag : new Settings ( { 'acknowledged-issue-numbers' : [ MULTIPLE_AFFECTED_VERSIONS_NOTICE . issueNumber ] } ) } ) ;
844813
845- const notices = Notices . create ( { ioHost, context } ) ;
814+ const notices = Notices . create ( { ioHost, context, cliVersion : '1.126.0' } ) ;
846815 await notices . refresh ( {
847816 dataSource : { fetch : async ( ) => [ BASIC_NOTICE , MULTIPLE_AFFECTED_VERSIONS_NOTICE ] } ,
848817 } ) ;
@@ -852,11 +821,8 @@ describe(Notices, () => {
852821 } ) ;
853822
854823 test ( 'can include acknowledged notices if requested' , async ( ) => {
855- // within the affected version range of both notices
856- jest . spyOn ( version , 'versionNumber' ) . mockImplementation ( ( ) => '1.126.0' ) ;
857-
858824 const context = new Context ( { bag : new Settings ( { 'acknowledged-issue-numbers' : [ MULTIPLE_AFFECTED_VERSIONS_NOTICE . issueNumber ] } ) } ) ;
859- const notices = Notices . create ( { ioHost, context, includeAcknowledged : true } ) ;
825+ const notices = Notices . create ( { ioHost, context, includeAcknowledged : true , cliVersion : '1.126.0' } ) ;
860826 await notices . refresh ( {
861827 dataSource : { fetch : async ( ) => [ BASIC_NOTICE , MULTIPLE_AFFECTED_VERSIONS_NOTICE ] } ,
862828 } ) ;
0 commit comments