Skip to content

Commit 92b1caf

Browse files
masl2Namitha-Prabhustevebux
authored
CCM-13711: test data variations rebranched (#394)
* add test letter variation to script * update wrapper script * add error spec to set and rename batch folder location * tests fixes * fix tests and update script comments * allow prod for single test letter upload * Add missing dependencies * lockfile * lock * lint --------- Co-authored-by: namitha.prabhu <namitha.prabhu2@nhs.net> Co-authored-by: Steve Buxton <steve.buxton@nhs.net>
1 parent a1c77ae commit 92b1caf

File tree

13 files changed

+1934
-1091
lines changed

13 files changed

+1934
-1091
lines changed

package-lock.json

Lines changed: 1787 additions & 1062 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/utilities/letter-test-data/README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,12 @@ For creating multiple batches with different specification and group IDs, use th
4343
--status PENDING
4444
```
4545

46-
This script creates 3 batches with the following configurations:
46+
This script creates 4 batches with the following configurations:
4747

4848
- Batch 1: `--specification-id integration-specification-english --group-id group-english`
4949
- Batch 2: `--specification-id integration-specification-braille --group-id group-accessible`
5050
- Batch 3: `--specification-id integration-specification-arabic --group-id group-international`
51+
- Batch 4: `--specification-id integration-specification-missing-pdf --group-id group-error`
5152

5253
**Note:** The default configuration creates 2,505 letters total (835 letters × 3 batches) with an 18-month TTL.
5354

@@ -57,5 +58,6 @@ This script creates 3 batches with the following configurations:
5758
- `--environment` (required): Environment (e.g., pr147, main)
5859
- `--awsAccountId` (required): AWS Account ID for S3 bucket resolution
5960
- `--count` (optional): Number of letters per batch (default: 835)
61+
- `--missing-count` (optional): Number of letters with missing PDFs (default: 5)
6062
- `--status` (optional): Letter status (default: PENDING)
6163
- `--ttl-hours` (optional): TTL in hours (default: 13140, ~18 months)

scripts/utilities/letter-test-data/src/__test__/helpers/create-letter-helpers.test.ts

Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ describe("Create letter helpers", () => {
1313
jest.resetAllMocks();
1414
});
1515

16-
it("create letter", async () => {
16+
it("create letter should create and upload a test letter", async () => {
1717
jest.useFakeTimers();
1818
jest.setSystemTime(new Date(2020, 1, 1));
1919

@@ -30,6 +30,7 @@ describe("Create letter helpers", () => {
3030
const groupId = "groupId";
3131
const specificationId = "specificationId";
3232
const status = "PENDING" as LetterStatusType;
33+
const testLetter = "test-letter-standard";
3334

3435
await createLetter({
3536
letterId,
@@ -40,12 +41,13 @@ describe("Create letter helpers", () => {
4041
specificationId,
4142
status,
4243
letterRepository: mockedLetterRepository,
44+
testLetter,
4345
});
4446

4547
expect(mockedUploadFile).toHaveBeenCalledWith(
4648
"bucketName",
4749
"supplierId",
48-
"../../test_letter.pdf",
50+
"test-letter-standard.pdf",
4951
"targetFilename",
5052
);
5153
expect(mockPutLetter).toHaveBeenCalledWith({
@@ -63,6 +65,54 @@ describe("Create letter helpers", () => {
6365
});
6466
});
6567

68+
it("should not upload a letter for none", async () => {
69+
jest.useFakeTimers();
70+
jest.setSystemTime(new Date(2020, 1, 1));
71+
72+
const mockPutLetter = jest.fn();
73+
const mockedLetterRepository = {
74+
putLetter: mockPutLetter,
75+
} as any as LetterRepository;
76+
const mockedUploadFile = uploadFile as jest.Mock;
77+
78+
const supplierId = "supplierId";
79+
const letterId = "letterId";
80+
const bucketName = "bucketName";
81+
const targetFilename = "targetFilename";
82+
const groupId = "groupId";
83+
const specificationId = "specificationId";
84+
const status = "PENDING" as LetterStatusType;
85+
const testLetter = "none";
86+
87+
await createLetter({
88+
letterId,
89+
bucketName,
90+
supplierId,
91+
targetFilename,
92+
groupId,
93+
specificationId,
94+
status,
95+
letterRepository: mockedLetterRepository,
96+
testLetter,
97+
});
98+
99+
expect(mockedUploadFile).not.toHaveBeenCalled();
100+
101+
expect(mockPutLetter).toHaveBeenCalledWith({
102+
createdAt: "2020-02-01T00:00:00.000Z",
103+
groupId: "groupId",
104+
id: "letterId",
105+
specificationId: "specificationId",
106+
status: "PENDING",
107+
supplierId: "supplierId",
108+
updatedAt: "2020-02-01T00:00:00.000Z",
109+
url: "s3://bucketName/supplierId/targetFilename",
110+
billingRef: "specificationId",
111+
source: "/data-plane/letter-rendering/letter-test-data",
112+
subject: "supplier-api/letter-test-data/letterId",
113+
});
114+
});
115+
66116
it("should create a letter DTO with correct fields", () => {
67117
jest.useFakeTimers();
68118
jest.setSystemTime(new Date(2020, 1, 1));

scripts/utilities/letter-test-data/src/cli/index.ts

Lines changed: 44 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ async function main() {
2626
awsAccountId: {
2727
type: "string",
2828
demandOption: true,
29+
choices: [
30+
"820178564574", // Supplier Dev
31+
"885964308133", // Supplier Nonprod
32+
"815459455390", // Supplier Prod
33+
],
2934
},
3035
"letter-id": {
3136
type: "string",
@@ -61,6 +66,15 @@ async function main() {
6166
"DELIVERED",
6267
],
6368
},
69+
"test-letter": {
70+
type: "string",
71+
demandOption: true,
72+
choices: [
73+
"test-letter-large",
74+
"test-letter-standard",
75+
"none", // none exists to specify letter without pdf for error testing scenarios
76+
],
77+
},
6478
},
6579
async (argv) => {
6680
const { supplierId } = argv;
@@ -73,6 +87,7 @@ async function main() {
7387
const { environment } = argv;
7488
const { ttlHours } = argv;
7589
const letterRepository = createLetterRepository(environment, ttlHours);
90+
const { testLetter } = argv;
7691

7792
createLetter({
7893
letterId,
@@ -83,6 +98,7 @@ async function main() {
8398
specificationId,
8499
status: status as LetterStatusType,
85100
letterRepository,
101+
testLetter,
86102
});
87103
},
88104
)
@@ -101,6 +117,10 @@ async function main() {
101117
awsAccountId: {
102118
type: "string",
103119
demandOption: true,
120+
choices: [
121+
"820178564574", // Supplier Dev
122+
"885964308133", // Supplier Nonprod
123+
],
104124
},
105125
"group-id": {
106126
type: "string",
@@ -136,6 +156,15 @@ async function main() {
136156
"DELIVERED",
137157
],
138158
},
159+
"test-letter": {
160+
type: "string",
161+
demandOption: true,
162+
choices: [
163+
"test-letter-large",
164+
"test-letter-standard",
165+
"none", // none exists to specify letter without pdf for error testing scenarios
166+
],
167+
},
139168
},
140169
async (argv) => {
141170
// set batch ID
@@ -150,17 +179,23 @@ async function main() {
150179
const { ttlHours } = argv;
151180
const letterRepository = createLetterRepository(environment, ttlHours);
152181
const { count } = argv;
182+
const { testLetter } = argv;
153183

154-
// Upload a test file for this batch
184+
// Setup file attributes
155185
const bucketName = `nhs-${argv.awsAccountId}-eu-west-2-${argv.environment}-supapi-test-letters`;
156186
const targetFilename = `${batchId}-${status}.pdf`;
157-
const url = `s3://${bucketName}/${batchId}/${targetFilename}`;
158-
await uploadFile(
159-
bucketName,
160-
batchId,
161-
"../../test_letter.pdf",
162-
targetFilename,
163-
);
187+
const folder = `${supplierId}/${batchId}`;
188+
const url = `s3://${bucketName}/${folder}/${targetFilename}`;
189+
190+
// Upload a test file for this batch if it is not an 'none' batch
191+
if (testLetter !== "none") {
192+
await uploadFile(
193+
bucketName,
194+
folder,
195+
`${testLetter}.pdf`,
196+
targetFilename,
197+
);
198+
}
164199

165200
// Create letter DTOs
166201
const letterDtos = [];
@@ -180,7 +215,7 @@ async function main() {
180215
// Upload Letters
181216
await letterRepository.unsafePutLetterBatch(letterDtos);
182217

183-
console.log(`Created batch ${batchId} of ${letterDtos.length}`);
218+
console.log(`Created batch ${batchId} of ${letterDtos.length} letters`);
184219
},
185220
)
186221
.demandCommand(1)

scripts/utilities/letter-test-data/src/create-batch-letters.sh

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,20 @@ usage() {
1616
echo ""
1717
echo "Optional parameters:"
1818
echo " --count Number of letters per batch (default: 835)"
19+
echo " --missing-count Number of letters with missing PDFs (default: 5)"
1920
echo " --status Letter status (default: PENDING)"
2021
echo " --ttl-hours TTL in hours (default: 13140)"
2122
echo ""
2223
echo "Example:"
2324
echo " $0 --supplier-id supplier-123 --environment pr147 --awsAccountId 820178564574"
2425
echo " $0 --supplier-id supplier-123 --environment main --awsAccountId 820178564574 --count 25 --status ACCEPTED"
26+
echo " $0 --supplier-id supplier-123 --environment main --awsAccountId 820178564574 --count 25 --status ACCEPTED --missing-count 3"
2527
exit 1
2628
}
2729

2830
# Default values
2931
COUNT=835 #3 batches = 2505 letters
32+
MISSING_COUNT=5 # Number of letters with missing PDFs
3033
STATUS="PENDING"
3134
TTL_HOURS=13140 # Approximately 18 months
3235

@@ -49,6 +52,10 @@ while [[ $# -gt 0 ]]; do
4952
COUNT="$2"
5053
shift 2
5154
;;
55+
--missing-count)
56+
MISSING_COUNT="$2"
57+
shift 2
58+
;;
5259
--status)
5360
STATUS="$2"
5461
shift 2
@@ -87,11 +94,18 @@ if ! [[ "$COUNT" =~ ^[1-9][0-9]*$ ]]; then
8794
exit 1
8895
fi
8996

97+
# Validate missing count is a positive number
98+
if ! [[ "$MISSING_COUNT" =~ ^[1-9][0-9]*$ ]]; then
99+
echo "Error: Missing count must be a positive integer"
100+
exit 1
101+
fi
102+
90103
echo "Creating letter batches with the following configuration:"
91104
echo " Supplier ID: $SUPPLIER_ID"
92105
echo " Environment: $ENVIRONMENT"
93106
echo " AWS Account ID: $AWS_ACCOUNT_ID"
94107
echo " Count per batch: $COUNT"
108+
echo " Letters missing PDFs count: $MISSING_COUNT"
95109
echo " Status: $STATUS"
96110
echo " TTL Hours: $TTL_HOURS"
97111
echo ""
@@ -103,11 +117,12 @@ PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
103117
# Change to the project directory
104118
cd "$PROJECT_DIR"
105119

106-
# Define the three batches with different specification and group IDs
120+
# Define the batches with different specification and group IDs
107121
BATCHES=(
108-
"integration-specification-english:group-english"
109-
"integration-specification-braille:group-accessible"
110-
"integration-specification-arabic:group-international"
122+
"integration-specification-english:group-english:test-letter-standard:${COUNT}"
123+
"integration-specification-braille:group-accessible:test-letter-standard:${COUNT}"
124+
"integration-specification-arabic:group-international:test-letter-large:${COUNT}"
125+
"integration-specification-missing-pdf:group-error:none:${MISSING_COUNT}"
111126
)
112127

113128
# Counter for tracking batch creation
@@ -120,8 +135,8 @@ echo ""
120135

121136
# Create each batch
122137
for batch in "${BATCHES[@]}"; do
123-
# Parse specification-id and group-id from the batch definition
124-
IFS=':' read -r SPEC_ID GROUP_ID <<< "$batch"
138+
# Parse specification-id, group-id and batch volume from the batch definition
139+
IFS=':' read -r SPEC_ID GROUP_ID TEST_LETTER BATCH_COUNT <<< "$batch"
125140

126141
echo "[$BATCH_COUNTER/$TOTAL_BATCHES] Creating batch with specification-id: $SPEC_ID, group-id: $GROUP_ID-$SUPPLIER_ID"
127142

@@ -133,8 +148,9 @@ for batch in "${BATCHES[@]}"; do
133148
--specification-id "$SPEC_ID" \
134149
--group-id "$GROUP_ID-$SUPPLIER_ID" \
135150
--status "$STATUS" \
136-
--count "$COUNT" \
137-
--ttl-hours "$TTL_HOURS"
151+
--count "$BATCH_COUNT" \
152+
--ttl-hours "$TTL_HOURS" \
153+
--test-letter "$TEST_LETTER"
138154

139155
if [[ $? -eq 0 ]]; then
140156
echo "✓ Batch $BATCH_COUNTER completed successfully"

scripts/utilities/letter-test-data/src/helpers/create-letter-helpers.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export async function createLetter(params: {
1414
groupId: string;
1515
status: LetterStatusType;
1616
letterRepository: LetterRepository;
17+
testLetter: string;
1718
}) {
1819
const {
1920
bucketName,
@@ -24,14 +25,17 @@ export async function createLetter(params: {
2425
status,
2526
supplierId,
2627
targetFilename,
28+
testLetter,
2729
} = params;
2830

29-
await uploadFile(
30-
bucketName,
31-
supplierId,
32-
"../../test_letter.pdf",
33-
targetFilename,
34-
);
31+
if (testLetter !== "none") {
32+
await uploadFile(
33+
bucketName,
34+
supplierId,
35+
`${testLetter}.pdf`,
36+
targetFilename,
37+
);
38+
}
3539

3640
const letter: Omit<Letter, "ttl" | "supplierStatus" | "supplierStatusSk"> = {
3741
id: letterId,

scripts/utilities/letter-test-data/src/helpers/s3-helpers.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@ import path from "node:path";
44

55
export default async function uploadFile(
66
bucketName: string,
7-
supplierId: string,
7+
folder: string,
88
sourceFilename: string,
99
targetFilename: string,
1010
) {
1111
try {
1212
const s3 = new S3Client();
13-
const filePath = path.join(__dirname, sourceFilename);
13+
const filePath = path.join(__dirname, "..", "test-letters", sourceFilename);
1414
const fileContent = readFileSync(filePath);
1515

1616
const uploadParams = {
1717
Bucket: bucketName,
18-
Key: `${supplierId}/${targetFilename}`,
18+
Key: `${folder}/${targetFilename}`,
1919
Body: fileContent,
2020
ContentType: "application/pdf",
2121
};
Binary file not shown.
Binary file not shown.
-585 KB
Binary file not shown.

0 commit comments

Comments
 (0)