66 getAllocationLog ,
77 getAllocationLogForDomainId ,
88 getVariantsForAllocation ,
9+ getVolumeGroupData ,
10+ updateLetterVariantConfig ,
911 updateVolumeGroupData ,
1012} from "tests/helpers/allocation-helper" ;
1113import { createPreparedV1Event } from "tests/helpers/event-fixtures" ;
@@ -99,6 +101,10 @@ test.describe("Allocator Rejected Allocation Tests", () => {
99101 pageCount,
100102 } ) ;
101103
104+ if ( letterVariantMapping === 7 ) {
105+ await updateLetterVariantConfig ( letterVariant , [ "" ] ) ;
106+ }
107+
102108 const response = await sendSnsEvent ( preparedEvent ) ;
103109 expect ( response . MessageId ) . toBeTruthy ( ) ;
104110
@@ -134,9 +140,10 @@ test.describe("Allocator Rejected Allocation Tests", () => {
134140 break ;
135141 }
136142 case 3 : {
137- expect ( lettersInDb . reasonText ) . toBe (
138- `No pack specification found for id ` ,
143+ expect ( lettersInDb . reasonText ) . toContain (
144+ `No pack specification found for id` ,
139145 ) ;
146+ await updateLetterVariantConfig ( letterVariant , [ "notify-c5-colour" ] ) ; // update back to valid config for other tests
140147 break ;
141148 }
142149 default : {
@@ -146,36 +153,43 @@ test.describe("Allocator Rejected Allocation Tests", () => {
146153 } ) ;
147154 }
148155
149- const volumeGroupInactiveTestCases : VolumeGroupInactiveTestCase [ ] = [
156+ for ( const { fieldToUpdate , testName , volumeGroupId } of [
150157 {
151158 testName :
152159 "Verify that letters are rejected when volumeGroup is not active" ,
153160 volumeGroupId : "volumeGroup-test2" ,
154161 fieldToUpdate : "startDate" ,
155- daysInFuture : 1 ,
156162 } ,
157163 {
158164 testName :
159165 "Verify that letters are rejected when volumeGroup is no longer active" ,
160166 volumeGroupId : "volumeGroup-test2" ,
161167 fieldToUpdate : "endDate" ,
162- daysInFuture : - 1 ,
163168 } ,
164- ] ;
165-
166- for ( const {
167- daysInFuture,
168- fieldToUpdate,
169- testName,
170- volumeGroupId,
171- } of volumeGroupInactiveTestCases ) {
169+ ] ) {
172170 test ( testName , async ( ) => {
173171 const domainId = `${ fieldToUpdate } -${ randomUUID ( ) } ` ;
174172 const letterVariant = getVariantsForAllocation ( 8 ) ;
175173 logger . info ( `Testing volumeGroup with futureDate: ${ domainId } ` ) ;
176174
177- // set volume group date to future date
178- await updateVolumeGroupData ( volumeGroupId , daysInFuture , fieldToUpdate ) ;
175+ const { originalEndDate, originalStartDate } =
176+ await getVolumeGroupData ( volumeGroupId ) ;
177+
178+ const [ futureStartDate ] = new Date ( Date . now ( ) + 24 * 60 * 60 * 1000 )
179+ . toISOString ( )
180+ . split ( "T" ) ; // move start date to future
181+ const [ pastEndDate ] = new Date ( Date . now ( ) - 24 * 60 * 60 * 1000 )
182+ . toISOString ( )
183+ . split ( "T" ) ; // move end date to past
184+
185+ const targetUpdateDate =
186+ fieldToUpdate === "startDate" ? futureStartDate : pastEndDate ;
187+
188+ await updateVolumeGroupData (
189+ volumeGroupId ,
190+ targetUpdateDate ,
191+ fieldToUpdate ,
192+ ) ;
179193
180194 const preparedEvent = createPreparedV1Event ( {
181195 domainId,
@@ -199,8 +213,11 @@ test.describe("Allocator Rejected Allocation Tests", () => {
199213 expect ( lettersInDb . reasonText ) . toContain (
200214 `Volume group with id ${ volumeGroupId } is not active` ,
201215 ) ;
202- // update back to current date
203- await updateVolumeGroupData ( volumeGroupId , 0 , fieldToUpdate ) ;
216+ await updateVolumeGroupData (
217+ volumeGroupId ,
218+ fieldToUpdate === "startDate" ? originalStartDate : originalEndDate ,
219+ fieldToUpdate ,
220+ ) ;
204221 } ) ;
205222 }
206223} ) ;
0 commit comments