Skip to content

Commit bf88ba7

Browse files
committed
add test letter variation to script
1 parent 9dfefd1 commit bf88ba7

7 files changed

Lines changed: 92 additions & 16 deletions

File tree

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
@@ -13,7 +13,7 @@ describe("Create letter helpers", () => {
1313
jest.resetAllMocks();
1414
});
1515

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

@@ -30,6 +30,7 @@ describe("Create letter helpers", () => {
3030
const groupId = "groupId";
3131
const specificationId = "specificationId";
3232
const status = "PENDING" as LetterStatusType;
33+
const testLetter = "test-letter-standard";
3334

3435
await createLetter({
3536
letterId,
@@ -40,12 +41,13 @@ describe("Create letter helpers", () => {
4041
specificationId,
4142
status,
4243
letterRepository: mockedLetterRepository,
44+
testLetter,
4345
});
4446

4547
expect(mockedUploadFile).toHaveBeenCalledWith(
4648
"bucketName",
4749
"supplierId",
48-
"../../test_letter.pdf",
50+
"../test-letters/test-letter-standard.pdf",
4951
"targetFilename",
5052
);
5153
expect(mockPutLetter).toHaveBeenCalledWith({
@@ -63,6 +65,51 @@ describe("Create letter helpers", () => {
6365
});
6466
});
6567

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

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

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,15 @@ async function main() {
6161
"DELIVERED",
6262
],
6363
},
64+
"test-letter": {
65+
type: "string",
66+
demandOption: true,
67+
choices: [
68+
"test-letter-large",
69+
"test-letter-standard",
70+
"none", //none exists to specify letter without pdf for error testing scenarios
71+
]
72+
},
6473
},
6574
async (argv) => {
6675
const { supplierId } = argv;
@@ -73,6 +82,7 @@ async function main() {
7382
const { environment } = argv;
7483
const { ttlHours } = argv;
7584
const letterRepository = createLetterRepository(environment, ttlHours);
85+
const testLetter = argv.testLetter;
7686

7787
createLetter({
7888
letterId,
@@ -83,6 +93,7 @@ async function main() {
8393
specificationId,
8494
status: status as LetterStatusType,
8595
letterRepository,
96+
testLetter
8697
});
8798
},
8899
)
@@ -136,6 +147,15 @@ async function main() {
136147
"DELIVERED",
137148
],
138149
},
150+
"test-letter": {
151+
type: "string",
152+
demandOption: true,
153+
choices: [
154+
"test-letter-large",
155+
"test-letter-standard",
156+
"none", //none exists to specify letter without pdf for error testing scenarios
157+
]
158+
},
139159
},
140160
async (argv) => {
141161
// set batch ID
@@ -150,17 +170,22 @@ async function main() {
150170
const { ttlHours } = argv;
151171
const letterRepository = createLetterRepository(environment, ttlHours);
152172
const { count } = argv;
173+
const { testLetter } = argv;
153174

154-
// Upload a test file for this batch
175+
// Setup file attributes
155176
const bucketName = `nhs-${argv.awsAccountId}-eu-west-2-${argv.environment}-supapi-test-letters`;
156177
const targetFilename = `${batchId}-${status}.pdf`;
157178
const url = `s3://${bucketName}/${batchId}/${targetFilename}`;
158-
await uploadFile(
159-
bucketName,
160-
batchId,
161-
"../../test_letter.pdf",
162-
targetFilename,
163-
);
179+
180+
// Upload a test file for this batch if it is not an 'none' batch
181+
if(testLetter !== 'none') {
182+
await uploadFile(
183+
bucketName,
184+
supplierId,
185+
`../test-letters/${testLetter}.pdf`,
186+
targetFilename,
187+
);
188+
}
164189

165190
// Create letter DTOs
166191
const 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
bucketName,
@@ -24,14 +25,17 @@ export async function createLetter(params: {
2425
status,
2526
supplierId,
2627
targetFilename,
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
@@ -10,7 +10,7 @@ export default async function uploadFile(
1010
) {
1111
try {
1212
const s3 = new S3Client();
13-
const filePath = path.join(__dirname, sourceFilename);
13+
const filePath = path.join(__dirname, 'test-letters', sourceFilename);
1414
const fileContent = readFileSync(filePath);
1515

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

0 commit comments

Comments
 (0)