Skip to content

Commit 28470ed

Browse files
committed
add error spec to set and rename batch folder location
1 parent a3c7eaa commit 28470ed

7 files changed

Lines changed: 67 additions & 93 deletions

File tree

package-lock.json

Lines changed: 26 additions & 78 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/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"@internal/datastore": "*",
55
"esbuild": "^0.25.11",
66
"pino": "^9.7.0",
7-
"yargs": "^18.0.0"
7+
"yargs": "^17.7.2"
88
},
99
"devDependencies": {
1010
"@tsconfig/node22": "^22.0.2",

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ async function main() {
2323
awsAccountId: {
2424
type: "string",
2525
demandOption: true,
26+
choices: [
27+
"820178564574", // Supplier Dev
28+
"885964308133" //Supplier Nonprod
29+
],
2630
},
2731
"letter-id": {
2832
type: "string",
@@ -111,6 +115,10 @@ async function main() {
111115
awsAccountId: {
112116
type: "string",
113117
demandOption: true,
118+
choices: [
119+
"820178564574", // Supplier Dev
120+
"885964308133" //Supplier Nonprod
121+
],
114122
},
115123
"group-id": {
116124
type: "string",
@@ -177,14 +185,15 @@ async function main() {
177185
// Setup file attributes
178186
const bucketName = `nhs-${argv.awsAccountId}-eu-west-2-${argv.environment}-supapi-test-letters`;
179187
const targetFilename = `${batchId}-${status}.pdf`;
180-
const url = `s3://${bucketName}/${batchId}/${targetFilename}`;
188+
const folder = `${supplierId}/${batchId}`;
189+
const url = `s3://${bucketName}/${folder}/${targetFilename}`;
181190

182191
// Upload a test file for this batch if it is not an 'none' batch
183192
if(testLetter !== 'none') {
184193
await uploadFile(
185194
bucketName,
186-
supplierId,
187-
`../test-letters/${testLetter}.pdf`,
195+
folder,
196+
`${testLetter}.pdf`,
188197
targetFilename,
189198
);
190199
}
@@ -205,7 +214,7 @@ async function main() {
205214
// Upload Letters
206215
await letterRepository.putLetterBatch(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
@@ -3,15 +3,15 @@ import { readFileSync } from "fs";
33
import path from "path";
44

55

6-
export async function uploadFile(bucketName: string, supplierId: string, sourceFilename: string, targetFilename: string) {
6+
export async function uploadFile(bucketName: string, folder: string, sourceFilename: string, targetFilename: string) {
77
try {
88
const s3 = new S3Client();
9-
const filePath = path.join(__dirname, 'test-letters', sourceFilename);
9+
const filePath = path.join(__dirname, '..', 'test-letters', sourceFilename);
1010
const fileContent = readFileSync(filePath);
1111

1212
const uploadParams = {
1313
Bucket: bucketName,
14-
Key: `${supplierId}/${targetFilename}`,
14+
Key: `${folder}/${targetFilename}`,
1515
Body: fileContent,
1616
ContentType: "application/pdf",
1717
};

0 commit comments

Comments
 (0)