Skip to content
Draft
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
2 changes: 2 additions & 0 deletions infrastructure/terraform/components/api/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ No requirements.
| <a name="input_aws_account_id"></a> [aws\_account\_id](#input\_aws\_account\_id) | The AWS Account ID (numeric) | `string` | n/a | yes |
| <a name="input_ca_pem_filename"></a> [ca\_pem\_filename](#input\_ca\_pem\_filename) | Filename for the CA truststore file within the s3 bucket | `string` | `null` | no |
| <a name="input_component"></a> [component](#input\_component) | The variable encapsulating the name of this component | `string` | `"supapi"` | no |
| <a name="input_core_account_id"></a> [core\_account\_id](#input\_core\_account\_id) | AWS Account ID for Core | `string` | `"000000000000"` | no |
| <a name="input_core_environment"></a> [core\_environment](#input\_core\_environment) | Environment of Core | `string` | `"prod"` | no |
| <a name="input_default_tags"></a> [default\_tags](#input\_default\_tags) | A map of default tags to apply to all taggable resources within the component | `map(string)` | `{}` | no |
| <a name="input_enable_backups"></a> [enable\_backups](#input\_enable\_backups) | Enable backups | `bool` | `false` | no |
| <a name="input_environment"></a> [environment](#input\_environment) | The name of the tfscaffold environment | `string` | n/a | yes |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe("Create letter helpers", () => {
jest.resetAllMocks();
});

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

Expand All @@ -27,6 +27,7 @@ describe("Create letter helpers", () => {
const groupId = "groupId";
const specificationId = "specificationId";
const status = "PENDING" as LetterStatusType;
const testLetter = "test-letter-standard";

await createLetter({
letterId,
Expand All @@ -37,12 +38,13 @@ describe("Create letter helpers", () => {
specificationId,
status,
letterRepository: mockedLetterRepository,
testLetter,
});

expect(mockedUploadFile).toHaveBeenCalledWith(
"bucketName",
"supplierId",
"../../test_letter.pdf",
"../test-letters/test-letter-standard.pdf",
"targetFilename",
);
expect(mockPutLetter).toHaveBeenCalledWith({
Expand All @@ -57,6 +59,51 @@ describe("Create letter helpers", () => {
});
});

it("should not upload a letter for none", async () => {
jest.useFakeTimers();
jest.setSystemTime(new Date(2020, 1, 1));

const mockPutLetter = jest.fn();
const mockedLetterRepository = {
putLetter: mockPutLetter,
} as any as LetterRepository;
const mockedUploadFile = uploadFile as jest.Mock;

const supplierId = "supplierId";
const letterId = "letterId";
const bucketName = "bucketName";
const targetFilename = "targetFilename";
const groupId = "groupId";
const specificationId = "specificationId";
const status = "PENDING" as LetterStatusType;
const testLetter = "none";

await createLetter({
letterId,
bucketName,
supplierId,
targetFilename,
groupId,
specificationId,
status,
letterRepository: mockedLetterRepository,
testLetter,
});

expect(mockedUploadFile).not.toHaveBeenCalled();

expect(mockPutLetter).toHaveBeenCalledWith({
createdAt: "2020-02-01T00:00:00.000Z",
groupId: "groupId",
id: "letterId",
specificationId: "specificationId",
status: "PENDING",
supplierId: "supplierId",
updatedAt: "2020-02-01T00:00:00.000Z",
url: "s3://bucketName/supplierId/targetFilename",
});
});

it("should create a letter DTO with correct fields", () => {
jest.useFakeTimers();
jest.setSystemTime(new Date(2020, 1, 1));
Expand Down
35 changes: 32 additions & 3 deletions scripts/utilities/letter-test-data/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ async function main() {
"DELIVERED",
],
},
"test-letter": {
type: "string",
demandOption: true,
choices: [
"test-letter-large",
"test-letter-standard",
"none", //none exists to specify letter without pdf for error testing scenarios
]
},
},
async (argv) => {
const supplierId = argv.supplierId;
Expand All @@ -72,6 +81,7 @@ async function main() {
const environment = argv.environment;
const ttlHours = argv.ttlHours;
const letterRepository = createLetterRepository(environment, ttlHours);
const testLetter = argv.testLetter;

createLetter({
letterId,
Expand All @@ -82,6 +92,7 @@ async function main() {
specificationId,
status: status as LetterStatusType,
letterRepository,
testLetter
});
},
)
Expand Down Expand Up @@ -135,6 +146,15 @@ async function main() {
"DELIVERED",
],
},
"test-letter": {
type: "string",
demandOption: true,
choices: [
"test-letter-large",
"test-letter-standard",
"none", //none exists to specify letter without pdf for error testing scenarios
]
},
},
async (argv) => {

Expand All @@ -152,13 +172,22 @@ async function main() {
const ttlHours = argv.ttlHours;
const letterRepository = createLetterRepository(environment, ttlHours);
const count = argv.count;
const testLetter = argv.testLetter;


// Upload a test file for this batch
// Setup file attributes
const bucketName = `nhs-${argv.awsAccountId}-eu-west-2-${argv.environment}-supapi-test-letters`;
const targetFilename = `${batchId}-${status}.pdf`;
const url = `s3://${bucketName}/${batchId}/${targetFilename}`;
await uploadFile(bucketName, batchId, "../../test_letter.pdf", targetFilename);

// Upload a test file for this batch if it is not an 'none' batch
if(testLetter !== 'none') {
await uploadFile(
bucketName,
supplierId,
`../test-letters/${testLetter}.pdf`,
targetFilename,
);
}

// Create letter DTOs
let letterDtos = [];
Expand Down
11 changes: 6 additions & 5 deletions scripts/utilities/letter-test-data/src/create-batch-letters.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,9 @@ 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"
"integration-specification-english:group-english:test-letter-standard"
"integration-specification-braille:group-accessible:test-letter-standard"
"integration-specification-arabic:group-international:test-letter-large"
)

# Counter for tracking batch creation
Expand All @@ -121,7 +121,7 @@ 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"
IFS=':' read -r SPEC_ID GROUP_ID TEST_LETTER <<< "$batch"

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

Expand All @@ -134,7 +134,8 @@ for batch in "${BATCHES[@]}"; do
--group-id "$GROUP_ID-$SUPPLIER_ID" \
--status "$STATUS" \
--count "$COUNT" \
--ttl-hours "$TTL_HOURS"
--ttl-hours "$TTL_HOURS" \
--test-letter "$TEST_LETTER"

if [[ $? -eq 0 ]]; then
echo "✓ Batch $BATCH_COUNTER completed successfully"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export async function createLetter(params: {
groupId: string;
status: LetterStatusType;
letterRepository: LetterRepository;
testLetter: string;
}) {
const {
letterId,
Expand All @@ -24,14 +25,17 @@ export async function createLetter(params: {
groupId,
status,
letterRepository,
testLetter,
} = params;

await uploadFile(
bucketName,
supplierId,
"../../test_letter.pdf",
targetFilename,
);
if(testLetter !== 'none') {
await uploadFile(
bucketName,
supplierId,
`../test-letters/${testLetter}.pdf`,
targetFilename,
);
}

const letter: Omit<Letter, "ttl" | "supplierStatus" | "supplierStatusSk"> = {
id: letterId,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import path from "path";
export async function uploadFile(bucketName: string, supplierId: string, sourceFilename: string, targetFilename: string) {
try {
const s3 = new S3Client();
const filePath = path.join(__dirname, sourceFilename);
const filePath = path.join(__dirname, 'test-letters', sourceFilename);
const fileContent = readFileSync(filePath);

const uploadParams = {
Expand Down
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading