Skip to content

Commit 4549a69

Browse files
committed
add error spec to set and rename batch folder location
1 parent 8f476a0 commit 4549a69

5 files changed

Lines changed: 40 additions & 14 deletions

File tree

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/cli/index.ts

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@ async function main() {
2626
awsAccountId: {
2727
type: "string",
2828
demandOption: true,
29+
choices: [
30+
"820178564574", // Supplier Dev
31+
"885964308133" //Supplier Nonprod
32+
],
2933
},
3034
"letter-id": {
3135
type: "string",
@@ -112,6 +116,10 @@ async function main() {
112116
awsAccountId: {
113117
type: "string",
114118
demandOption: true,
119+
choices: [
120+
"820178564574", // Supplier Dev
121+
"885964308133" //Supplier Nonprod
122+
],
115123
},
116124
"group-id": {
117125
type: "string",
@@ -175,14 +183,15 @@ async function main() {
175183
// Setup file attributes
176184
const bucketName = `nhs-${argv.awsAccountId}-eu-west-2-${argv.environment}-supapi-test-letters`;
177185
const targetFilename = `${batchId}-${status}.pdf`;
178-
const url = `s3://${bucketName}/${batchId}/${targetFilename}`;
186+
const folder = `${supplierId}/${batchId}`;
187+
const url = `s3://${bucketName}/${folder}/${targetFilename}`;
179188

180189
// Upload a test file for this batch if it is not an 'none' batch
181190
if(testLetter !== 'none') {
182191
await uploadFile(
183192
bucketName,
184-
supplierId,
185-
`../test-letters/${testLetter}.pdf`,
193+
folder,
194+
`${testLetter}.pdf`,
186195
targetFilename,
187196
);
188197
}
@@ -205,7 +214,7 @@ async function main() {
205214
// Upload Letters
206215
await letterRepository.unsafePutLetterBatch(letterDtos);
207216

208-
console.log(`Created batch ${batchId} of ${letterDtos.length}`);
217+
console.log(`Created batch ${batchId} of ${letterDtos.length} letters`);
209218
},
210219
)
211220
.demandCommand(1)

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

Lines changed: 20 additions & 5 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 ""
@@ -105,9 +119,10 @@ cd "$PROJECT_DIR"
105119

106120
# Define the three batches with different specification and group IDs
107121
BATCHES=(
108-
"integration-specification-english:group-english:test-letter-standard"
109-
"integration-specification-braille:group-accessible:test-letter-standard"
110-
"integration-specification-arabic:group-international:test-letter-large"
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
@@ -121,7 +136,7 @@ echo ""
121136
# Create each batch
122137
for batch in "${BATCHES[@]}"; do
123138
# Parse specification-id and group-id from the batch definition
124-
IFS=':' read -r SPEC_ID GROUP_ID TEST_LETTER <<< "$batch"
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,7 +148,7 @@ for batch in "${BATCHES[@]}"; do
133148
--specification-id "$SPEC_ID" \
134149
--group-id "$GROUP_ID-$SUPPLIER_ID" \
135150
--status "$STATUS" \
136-
--count "$COUNT" \
151+
--count "$BATCH_COUNT" \
137152
--ttl-hours "$TTL_HOURS" \
138153
--test-letter "$TEST_LETTER"
139154

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export async function createLetter(params: {
3232
await uploadFile(
3333
bucketName,
3434
supplierId,
35-
`../test-letters/${testLetter}.pdf`,
35+
`${testLetter}.pdf`,
3636
targetFilename,
3737
);
3838
}

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, 'test-letters', 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
};

0 commit comments

Comments
 (0)