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
104 changes: 26 additions & 78 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion scripts/utilities/letter-test-data/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,12 @@ For creating multiple batches with different specification and group IDs, use th
--status PENDING
```

This script creates 3 batches with the following configurations:
This script creates 4 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`
- Batch 4: `--specification-id integration-specification-missing-pdf --group-id group-error`

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

Expand All @@ -57,5 +58,6 @@ This script creates 3 batches with the following configurations:
- `--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)
- `--missing-count` (optional): Number of letters with missing PDFs (default: 5)
- `--status` (optional): Letter status (default: PENDING)
- `--ttl-hours` (optional): TTL in hours (default: 13140, ~18 months)
2 changes: 1 addition & 1 deletion scripts/utilities/letter-test-data/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"@internal/datastore": "*",
"esbuild": "^0.25.11",
"pino": "^9.7.0",
"yargs": "^18.0.0"
"yargs": "^17.7.2"
},
"devDependencies": {
"@tsconfig/node22": "^22.0.2",
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
48 changes: 43 additions & 5 deletions scripts/utilities/letter-test-data/src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ async function main() {
awsAccountId: {
type: "string",
demandOption: true,
choices: [
"820178564574", // Supplier Dev
"885964308133" //Supplier Nonprod
],
},
"letter-id": {
type: "string",
Expand Down Expand Up @@ -58,6 +62,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 +85,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 +96,7 @@ async function main() {
specificationId,
status: status as LetterStatusType,
letterRepository,
testLetter
});
},
)
Expand All @@ -100,6 +115,10 @@ async function main() {
awsAccountId: {
type: "string",
demandOption: true,
choices: [
"820178564574", // Supplier Dev
"885964308133" //Supplier Nonprod
],
},
"group-id": {
type: "string",
Expand Down Expand Up @@ -135,6 +154,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 +180,23 @@ 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);
const folder = `${supplierId}/${batchId}`;
const url = `s3://${bucketName}/${folder}/${targetFilename}`;

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

// Create letter DTOs
let letterDtos = [];
Expand All @@ -176,7 +214,7 @@ async function main() {
// Upload Letters
await letterRepository.putLetterBatch(letterDtos);

console.log(`Created batch ${batchId} of ${letterDtos.length}`);
console.log(`Created batch ${batchId} of ${letterDtos.length} letters`);
},
)
.demandCommand(1)
Expand Down
Loading
Loading