Skip to content

Commit 8a0b081

Browse files
committed
add test letter variation to script
1 parent 92573c0 commit 8a0b081

File tree

8 files changed

+94
-12
lines changed

8 files changed

+94
-12
lines changed

infrastructure/terraform/components/api/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ No requirements.
1212
| <a name="input_aws_account_id"></a> [aws\_account\_id](#input\_aws\_account\_id) | The AWS Account ID (numeric) | `string` | n/a | yes |
1313
| <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 |
1414
| <a name="input_component"></a> [component](#input\_component) | The variable encapsulating the name of this component | `string` | `"supapi"` | no |
15+
| <a name="input_core_account_id"></a> [core\_account\_id](#input\_core\_account\_id) | AWS Account ID for Core | `string` | `"000000000000"` | no |
16+
| <a name="input_core_environment"></a> [core\_environment](#input\_core\_environment) | Environment of Core | `string` | `"prod"` | no |
1517
| <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 |
1618
| <a name="input_enable_backups"></a> [enable\_backups](#input\_enable\_backups) | Enable backups | `bool` | `false` | no |
1719
| <a name="input_environment"></a> [environment](#input\_environment) | The name of the tfscaffold environment | `string` | n/a | yes |

scripts/utilities/letter-test-data/src/__test__/helpers/create_letter_helpers.test.ts

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ describe("Create letter helpers", () => {
1010
jest.resetAllMocks();
1111
});
1212

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

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

3132
await createLetter({
3233
letterId,
@@ -37,12 +38,13 @@ describe("Create letter helpers", () => {
3738
specificationId,
3839
status,
3940
letterRepository: mockedLetterRepository,
41+
testLetter,
4042
});
4143

4244
expect(mockedUploadFile).toHaveBeenCalledWith(
4345
"bucketName",
4446
"supplierId",
45-
"../../test_letter.pdf",
47+
"../test-letters/test-letter-standard.pdf",
4648
"targetFilename",
4749
);
4850
expect(mockPutLetter).toHaveBeenCalledWith({
@@ -57,6 +59,51 @@ describe("Create letter helpers", () => {
5759
});
5860
});
5961

62+
it("should not upload a letter for none", async () => {
63+
jest.useFakeTimers();
64+
jest.setSystemTime(new Date(2020, 1, 1));
65+
66+
const mockPutLetter = jest.fn();
67+
const mockedLetterRepository = {
68+
putLetter: mockPutLetter,
69+
} as any as LetterRepository;
70+
const mockedUploadFile = uploadFile as jest.Mock;
71+
72+
const supplierId = "supplierId";
73+
const letterId = "letterId";
74+
const bucketName = "bucketName";
75+
const targetFilename = "targetFilename";
76+
const groupId = "groupId";
77+
const specificationId = "specificationId";
78+
const status = "PENDING" as LetterStatusType;
79+
const testLetter = "none";
80+
81+
await createLetter({
82+
letterId,
83+
bucketName,
84+
supplierId,
85+
targetFilename,
86+
groupId,
87+
specificationId,
88+
status,
89+
letterRepository: mockedLetterRepository,
90+
testLetter,
91+
});
92+
93+
expect(mockedUploadFile).not.toHaveBeenCalled();
94+
95+
expect(mockPutLetter).toHaveBeenCalledWith({
96+
createdAt: "2020-02-01T00:00:00.000Z",
97+
groupId: "groupId",
98+
id: "letterId",
99+
specificationId: "specificationId",
100+
status: "PENDING",
101+
supplierId: "supplierId",
102+
updatedAt: "2020-02-01T00:00:00.000Z",
103+
url: "s3://bucketName/supplierId/targetFilename",
104+
});
105+
});
106+
60107
it("should create a letter DTO with correct fields", () => {
61108
jest.useFakeTimers();
62109
jest.setSystemTime(new Date(2020, 1, 1));

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

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,15 @@ async function main() {
5858
"DELIVERED",
5959
],
6060
},
61+
"test-letter": {
62+
type: "string",
63+
demandOption: true,
64+
choices: [
65+
"test-letter-large",
66+
"test-letter-standard",
67+
"none", //none exists to specify letter without pdf for error testing scenarios
68+
]
69+
},
6170
},
6271
async (argv) => {
6372
const supplierId = argv.supplierId;
@@ -72,6 +81,7 @@ async function main() {
7281
const environment = argv.environment;
7382
const ttlHours = argv.ttlHours;
7483
const letterRepository = createLetterRepository(environment, ttlHours);
84+
const testLetter = argv.testLetter;
7585

7686
createLetter({
7787
letterId,
@@ -82,6 +92,7 @@ async function main() {
8292
specificationId,
8393
status: status as LetterStatusType,
8494
letterRepository,
95+
testLetter
8596
});
8697
},
8798
)
@@ -135,6 +146,15 @@ async function main() {
135146
"DELIVERED",
136147
],
137148
},
149+
"test-letter": {
150+
type: "string",
151+
demandOption: true,
152+
choices: [
153+
"test-letter-large",
154+
"test-letter-standard",
155+
"none", //none exists to specify letter without pdf for error testing scenarios
156+
]
157+
},
138158
},
139159
async (argv) => {
140160

@@ -152,13 +172,22 @@ async function main() {
152172
const ttlHours = argv.ttlHours;
153173
const letterRepository = createLetterRepository(environment, ttlHours);
154174
const count = argv.count;
175+
const testLetter = argv.testLetter;
155176

156-
157-
// Upload a test file for this batch
177+
// Setup file attributes
158178
const bucketName = `nhs-${argv.awsAccountId}-eu-west-2-${argv.environment}-supapi-test-letters`;
159179
const targetFilename = `${batchId}-${status}.pdf`;
160180
const url = `s3://${bucketName}/${batchId}/${targetFilename}`;
161-
await uploadFile(bucketName, batchId, "../../test_letter.pdf", targetFilename);
181+
182+
// Upload a test file for this batch if it is not an 'none' batch
183+
if(testLetter !== 'none') {
184+
await uploadFile(
185+
bucketName,
186+
supplierId,
187+
`../test-letters/${testLetter}.pdf`,
188+
targetFilename,
189+
);
190+
}
162191

163192
// Create letter DTOs
164193
let letterDtos = [];

scripts/utilities/letter-test-data/src/helpers/create_letter_helpers.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export async function createLetter(params: {
1414
groupId: string;
1515
status: LetterStatusType;
1616
letterRepository: LetterRepository;
17+
testLetter: string;
1718
}) {
1819
const {
1920
letterId,
@@ -24,14 +25,17 @@ export async function createLetter(params: {
2425
groupId,
2526
status,
2627
letterRepository,
28+
testLetter,
2729
} = params;
2830

29-
await uploadFile(
30-
bucketName,
31-
supplierId,
32-
"../../test_letter.pdf",
33-
targetFilename,
34-
);
31+
if(testLetter !== 'none') {
32+
await uploadFile(
33+
bucketName,
34+
supplierId,
35+
`../test-letters/${testLetter}.pdf`,
36+
targetFilename,
37+
);
38+
}
3539

3640
const letter: Omit<Letter, "ttl" | "supplierStatus" | "supplierStatusSk"> = {
3741
id: letterId,

scripts/utilities/letter-test-data/src/helpers/s3_helpers.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import path from "path";
66
export async function uploadFile(bucketName: string, supplierId: string, sourceFilename: string, targetFilename: string) {
77
try {
88
const s3 = new S3Client();
9-
const filePath = path.join(__dirname, sourceFilename);
9+
const filePath = path.join(__dirname, 'test-letters', sourceFilename);
1010
const fileContent = readFileSync(filePath);
1111

1212
const uploadParams = {
Binary file not shown.
Binary file not shown.
-585 KB
Binary file not shown.

0 commit comments

Comments
 (0)