Skip to content

Commit 4c3ea4a

Browse files
authored
wrapper to produce a 2505 set of test letters (#269)
1 parent ec49b72 commit 4c3ea4a

File tree

2 files changed

+183
-0
lines changed

2 files changed

+183
-0
lines changed

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

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,33 @@ npm run cli -- create-letter-batch \
2929
--status PENDING \
3030
--count 10
3131
```
32+
33+
## Batch Creation Script
34+
35+
For creating multiple batches with different specification and group IDs, use the bash wrapper script:
36+
37+
```bash
38+
./src/create-batch-letters.sh \
39+
--supplier-id supplier-id \
40+
--environment main \
41+
--awsAccountId 820178564574 \
42+
--count 25 \
43+
--status PENDING
44+
```
45+
46+
This script creates 3 batches with the following configurations:
47+
48+
- Batch 1: `--specification-id integration-specification-english --group-id group-english`
49+
- Batch 2: `--specification-id integration-specification-braille --group-id group-accessible`
50+
- Batch 3: `--specification-id integration-specification-arabic --group-id group-international`
51+
52+
**Note:** The default configuration creates 2,505 letters total (835 letters × 3 batches) with an 18-month TTL.
53+
54+
### Script Options
55+
56+
- `--supplier-id` (required): Supplier ID for the letters
57+
- `--environment` (required): Environment (e.g., pr147, main)
58+
- `--awsAccountId` (required): AWS Account ID for S3 bucket resolution
59+
- `--count` (optional): Number of letters per batch (default: 835)
60+
- `--status` (optional): Letter status (default: PENDING)
61+
- `--ttl-hours` (optional): TTL in hours (default: 13140, ~18 months)
Lines changed: 153 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
#!/bin/bash
2+
3+
# Bash wrapper script for creating multiple letter batches
4+
# This script creates 3 batches with different specification-id and group-id values
5+
6+
set -e
7+
8+
# Function to display usage
9+
usage() {
10+
echo "Usage: $0 --supplier-id <supplier-id> --environment <environment> --awsAccountId <aws-account-id> [--count <count>] [--status <status>]"
11+
echo ""
12+
echo "Required parameters:"
13+
echo " --supplier-id Supplier ID for the letters"
14+
echo " --environment Environment (e.g., pr147, main, dev)"
15+
echo " --awsAccountId AWS Account ID for S3 bucket resolution"
16+
echo ""
17+
echo "Optional parameters:"
18+
echo " --count Number of letters per batch (default: 835)"
19+
echo " --status Letter status (default: PENDING)"
20+
echo " --ttl-hours TTL in hours (default: 13140)"
21+
echo ""
22+
echo "Example:"
23+
echo " $0 --supplier-id supplier-123 --environment pr147 --awsAccountId 820178564574"
24+
echo " $0 --supplier-id supplier-123 --environment main --awsAccountId 820178564574 --count 25 --status ACCEPTED"
25+
exit 1
26+
}
27+
28+
# Default values
29+
COUNT=835 #3 batches = 2505 letters
30+
STATUS="PENDING"
31+
TTL_HOURS=13140 # Approximately 18 months
32+
33+
# Parse command line arguments
34+
while [[ $# -gt 0 ]]; do
35+
case $1 in
36+
--supplier-id)
37+
SUPPLIER_ID="$2"
38+
shift 2
39+
;;
40+
--environment)
41+
ENVIRONMENT="$2"
42+
shift 2
43+
;;
44+
--awsAccountId)
45+
AWS_ACCOUNT_ID="$2"
46+
shift 2
47+
;;
48+
--count)
49+
COUNT="$2"
50+
shift 2
51+
;;
52+
--status)
53+
STATUS="$2"
54+
shift 2
55+
;;
56+
--ttl-hours)
57+
TTL_HOURS="$2"
58+
shift 2
59+
;;
60+
-h|--help)
61+
usage
62+
;;
63+
*)
64+
echo "Unknown parameter: $1"
65+
usage
66+
;;
67+
esac
68+
done
69+
70+
# Validate required parameters
71+
if [[ -z "$SUPPLIER_ID" || -z "$ENVIRONMENT" || -z "$AWS_ACCOUNT_ID" ]]; then
72+
echo "Error: Missing required parameters"
73+
echo ""
74+
usage
75+
fi
76+
77+
# Validate status
78+
VALID_STATUSES=("PENDING" "ACCEPTED" "REJECTED" "PRINTED" "ENCLOSED" "CANCELLED" "DISPATCHED" "FAILED" "RETURNED" "FORWARDED" "DELIVERED")
79+
if [[ ! " ${VALID_STATUSES[@]} " =~ " ${STATUS} " ]]; then
80+
echo "Error: Invalid status '$STATUS'. Valid statuses: ${VALID_STATUSES[*]}"
81+
exit 1
82+
fi
83+
84+
# Validate count is a positive number
85+
if ! [[ "$COUNT" =~ ^[1-9][0-9]*$ ]]; then
86+
echo "Error: Count must be a positive integer"
87+
exit 1
88+
fi
89+
90+
echo "Creating letter batches with the following configuration:"
91+
echo " Supplier ID: $SUPPLIER_ID"
92+
echo " Environment: $ENVIRONMENT"
93+
echo " AWS Account ID: $AWS_ACCOUNT_ID"
94+
echo " Count per batch: $COUNT"
95+
echo " Status: $STATUS"
96+
echo " TTL Hours: $TTL_HOURS"
97+
echo ""
98+
99+
# Get the directory of this script to run npm from the correct location
100+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
101+
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
102+
103+
# Change to the project directory
104+
cd "$PROJECT_DIR"
105+
106+
# Define the three batches with different specification and group IDs
107+
BATCHES=(
108+
"integration-specification-english:group-english"
109+
"integration-specification-braille:group-accessible"
110+
"integration-specification-arabic:group-international"
111+
)
112+
113+
# Counter for tracking batch creation
114+
BATCH_COUNTER=1
115+
TOTAL_BATCHES=${#BATCHES[@]}
116+
TOTAL_LETTERS=$((COUNT * TOTAL_BATCHES))
117+
118+
echo "Creating $TOTAL_BATCHES batches with $COUNT letters each ($TOTAL_LETTERS total letters)..."
119+
echo ""
120+
121+
# Create each batch
122+
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"
125+
126+
echo "[$BATCH_COUNTER/$TOTAL_BATCHES] Creating batch with specification-id: $SPEC_ID, group-id: $GROUP_ID-$SUPPLIER_ID"
127+
128+
# Run the npm command
129+
npm run cli -- create-letter-batch \
130+
--supplier-id "$SUPPLIER_ID" \
131+
--environment "$ENVIRONMENT" \
132+
--awsAccountId "$AWS_ACCOUNT_ID" \
133+
--specification-id "$SPEC_ID" \
134+
--group-id "$GROUP_ID-$SUPPLIER_ID" \
135+
--status "$STATUS" \
136+
--count "$COUNT" \
137+
--ttl-hours "$TTL_HOURS"
138+
139+
if [[ $? -eq 0 ]]; then
140+
echo "✓ Batch $BATCH_COUNTER completed successfully"
141+
else
142+
echo "✗ Batch $BATCH_COUNTER failed"
143+
exit 1
144+
fi
145+
146+
echo ""
147+
((BATCH_COUNTER++))
148+
done
149+
150+
echo "🎉 All batches created successfully!"
151+
echo "Total letters created: $TOTAL_LETTERS"
152+
echo "Supplier ID: $SUPPLIER_ID"
153+
echo "Environment: $ENVIRONMENT"

0 commit comments

Comments
 (0)