Skip to content

Commit 1f2bc58

Browse files
config fix
1 parent b9f6803 commit 1f2bc58

3 files changed

Lines changed: 92 additions & 29 deletions

File tree

config/suppliers/letter-variant/client1-campaign7.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
"description": "Economy, colour printing",
2929
"id": "client1-campaign7",
3030
"name": "Client1 - Campaign 7",
31-
"packSpecificationIds": [],
31+
"packSpecificationIds": [
32+
"notify-c5-colour"
33+
],
3234
"priority": 50,
3335
"status": "INT",
3436
"type": "STANDARD",

tests/component-tests/allocation-tests/letter-allocation-rejected.spec.ts

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ import {
66
getAllocationLog,
77
getAllocationLogForDomainId,
88
getVariantsForAllocation,
9+
getVolumeGroupData,
10+
updateLetterVariantConfig,
911
updateVolumeGroupData,
1012
} from "tests/helpers/allocation-helper";
1113
import { 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
});

tests/helpers/allocation-helper.ts

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ export type VolumeGroupInactiveTestCase = {
123123
testName: string;
124124
volumeGroupId: string;
125125
fieldToUpdate: VolumeGroupDateField;
126-
daysInFuture: number;
127126
};
128127

129128
const getSupplierConfigTableName = (): string =>
@@ -388,17 +387,9 @@ export async function updateSupplierOverallAllocation(
388387

389388
export async function updateVolumeGroupData(
390389
volumeGroupId: string,
391-
daysInFuture: number,
392-
fieldName: "startDate" | "endDate" = "startDate",
390+
targetDate: string,
391+
fieldName: string,
393392
) {
394-
const days = Math.abs(daysInFuture);
395-
const dayOffset = fieldName === "endDate" ? -days : days;
396-
const targetDate = new Date(Date.now() + dayOffset * 24 * 60 * 60 * 1000)
397-
.toISOString()
398-
.split("T")[0];
399-
400-
logger.info(`targetDate for volume group update is ${targetDate}`);
401-
402393
const key = {
403394
pk: "ENTITY#volume-group",
404395
sk: `ID#${volumeGroupId}`,
@@ -421,6 +412,32 @@ export async function updateVolumeGroupData(
421412
);
422413
}
423414

415+
export async function getVolumeGroupData(volumeGroupId: string): Promise<{
416+
originalStartDate: string;
417+
originalEndDate: string;
418+
}> {
419+
const { Item } = await docClient.send(
420+
new GetCommand({
421+
TableName: getSupplierConfigTableName(),
422+
Key: {
423+
pk: "ENTITY#volume-group",
424+
sk: `ID#${volumeGroupId}`,
425+
},
426+
}),
427+
);
428+
429+
if (!Item) {
430+
throw new Error(
431+
`Volume group data was not found in supplier config table for id ${volumeGroupId}`,
432+
);
433+
}
434+
435+
return {
436+
originalEndDate: Item.endDate,
437+
originalStartDate: Item.startDate,
438+
};
439+
}
440+
424441
export async function updateSupplierAllocation(
425442
supplierId: string,
426443
volumeGroupId: string,
@@ -449,3 +466,30 @@ export async function updateSupplierAllocation(
449466
}),
450467
);
451468
}
469+
470+
export async function updateLetterVariantConfig(
471+
letterVariantId: string,
472+
packSpecificationIds: string[],
473+
) {
474+
const now = new Date().toISOString();
475+
const key = {
476+
pk: "ENTITY#letter-variant",
477+
sk: `ID#${letterVariantId}`,
478+
};
479+
await docClient.send(
480+
new UpdateCommand({
481+
TableName: getSupplierConfigTableName(),
482+
Key: key,
483+
UpdateExpression: `
484+
SET
485+
packSpecificationIds = :packSpecificationIds,
486+
updatedAt = :now
487+
`,
488+
ExpressionAttributeValues: {
489+
":packSpecificationIds": packSpecificationIds,
490+
":now": now,
491+
},
492+
ConditionExpression: "attribute_exists(pk) AND attribute_exists(sk)",
493+
}),
494+
);
495+
}

0 commit comments

Comments
 (0)