Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 30 additions & 0 deletions scripts/utilities/letter-test-data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,33 @@ npm run cli -- create-letter-batch \
--status PENDING \
--count 10
```

## Batch Creation Script

For creating multiple batches with different specification and group IDs, use the bash wrapper script:

```bash
./src/create-batch-letters.sh \
--supplier-id supplier-id \
--environment main \
--awsAccountId 820178564574 \
--count 25 \
--status PENDING
```

This script creates 3 batches with the following configurations:

- Batch 1: `--specification-id integration-specification-english --group-id group-english`
- Batch 2: `--specification-id integration-specification-braille --group-id group-accessible`
- Batch 3: `--specification-id integration-specification-arabic --group-id group-international`

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

### Script Options

- `--supplier-id` (required): Supplier ID for the letters
- `--environment` (required): Environment (e.g., pr147, main)
- `--awsAccountId` (required): AWS Account ID for S3 bucket resolution
- `--count` (optional): Number of letters per batch (default: 835)
- `--status` (optional): Letter status (default: PENDING)
- `--ttl-hours` (optional): TTL in hours (default: 13140, ~18 months)
153 changes: 153 additions & 0 deletions scripts/utilities/letter-test-data/src/create-batch-letters.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,153 @@
#!/bin/bash

# Bash wrapper script for creating multiple letter batches
# This script creates 3 batches with different specification-id and group-id values

set -e

# Function to display usage
usage() {
echo "Usage: $0 --supplier-id <supplier-id> --environment <environment> --awsAccountId <aws-account-id> [--count <count>] [--status <status>]"
echo ""
echo "Required parameters:"
echo " --supplier-id Supplier ID for the letters"
echo " --environment Environment (e.g., pr147, main, dev)"
echo " --awsAccountId AWS Account ID for S3 bucket resolution"
echo ""
echo "Optional parameters:"
echo " --count Number of letters per batch (default: 835)"
echo " --status Letter status (default: PENDING)"
echo " --ttl-hours TTL in hours (default: 13140)"
echo ""
echo "Example:"
echo " $0 --supplier-id supplier-123 --environment pr147 --awsAccountId 820178564574"
echo " $0 --supplier-id supplier-123 --environment main --awsAccountId 820178564574 --count 25 --status ACCEPTED"
exit 1
}

# Default values
COUNT=835 #3 batches = 2505 letters
STATUS="PENDING"
TTL_HOURS=13140 # Approximately 18 months

# Parse command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
--supplier-id)
SUPPLIER_ID="$2"
shift 2
;;
--environment)
ENVIRONMENT="$2"
shift 2
;;
--awsAccountId)
AWS_ACCOUNT_ID="$2"
shift 2
;;
--count)
COUNT="$2"
shift 2
;;
--status)
STATUS="$2"
shift 2
;;
--ttl-hours)
TTL_HOURS="$2"
shift 2
;;
-h|--help)
usage
;;
*)
echo "Unknown parameter: $1"
usage
;;
esac
done

# Validate required parameters
if [[ -z "$SUPPLIER_ID" || -z "$ENVIRONMENT" || -z "$AWS_ACCOUNT_ID" ]]; then
echo "Error: Missing required parameters"
echo ""
usage
fi

# Validate status
VALID_STATUSES=("PENDING" "ACCEPTED" "REJECTED" "PRINTED" "ENCLOSED" "CANCELLED" "DISPATCHED" "FAILED" "RETURNED" "FORWARDED" "DELIVERED")
if [[ ! " ${VALID_STATUSES[@]} " =~ " ${STATUS} " ]]; then
echo "Error: Invalid status '$STATUS'. Valid statuses: ${VALID_STATUSES[*]}"
exit 1
fi

# Validate count is a positive number
if ! [[ "$COUNT" =~ ^[1-9][0-9]*$ ]]; then
echo "Error: Count must be a positive integer"
exit 1
fi

echo "Creating letter batches with the following configuration:"
echo " Supplier ID: $SUPPLIER_ID"
echo " Environment: $ENVIRONMENT"
echo " AWS Account ID: $AWS_ACCOUNT_ID"
echo " Count per batch: $COUNT"
echo " Status: $STATUS"
echo " TTL Hours: $TTL_HOURS"
echo ""

# Get the directory of this script to run npm from the correct location
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"

# Change to the project directory
cd "$PROJECT_DIR"

# Define the three batches with different specification and group IDs
BATCHES=(
"integration-specification-english:group-english"
"integration-specification-braille:group-accessible"
"integration-specification-arabic:group-international"
)

# Counter for tracking batch creation
BATCH_COUNTER=1
TOTAL_BATCHES=${#BATCHES[@]}
TOTAL_LETTERS=$((COUNT * TOTAL_BATCHES))

echo "Creating $TOTAL_BATCHES batches with $COUNT letters each ($TOTAL_LETTERS total letters)..."
echo ""

# Create each batch
for batch in "${BATCHES[@]}"; do
# Parse specification-id and group-id from the batch definition
IFS=':' read -r SPEC_ID GROUP_ID <<< "$batch"

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

# Run the npm command
npm run cli -- create-letter-batch \
--supplier-id "$SUPPLIER_ID" \
--environment "$ENVIRONMENT" \
--awsAccountId "$AWS_ACCOUNT_ID" \
--specification-id "$SPEC_ID" \
--group-id "$GROUP_ID-$SUPPLIER_ID" \
--status "$STATUS" \
--count "$COUNT" \
--ttl-hours "$TTL_HOURS"

if [[ $? -eq 0 ]]; then
echo "✓ Batch $BATCH_COUNTER completed successfully"
else
echo "✗ Batch $BATCH_COUNTER failed"
exit 1
fi

echo ""
((BATCH_COUNTER++))
done

echo "🎉 All batches created successfully!"
echo "Total letters created: $TOTAL_LETTERS"
echo "Supplier ID: $SUPPLIER_ID"
echo "Environment: $ENVIRONMENT"
Loading