Skip to content

Commit 39a4722

Browse files
letter data - auto fix
1 parent 82cf3b2 commit 39a4722

File tree

6 files changed

+87
-75
lines changed

6 files changed

+87
-75
lines changed

scripts/utilities/letter-test-data/jest.config.ts

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
import type { Config } from 'jest';
1+
import type { Config } from "jest";
22

33
export const baseJestConfig: Config = {
4-
preset: 'ts-jest',
4+
preset: "ts-jest",
55

66
// Automatically clear mock calls, instances, contexts and results before every test
77
clearMocks: true,
@@ -10,10 +10,10 @@ export const baseJestConfig: Config = {
1010
collectCoverage: true,
1111

1212
// The directory where Jest should output its coverage files
13-
coverageDirectory: './.reports/unit/coverage',
13+
coverageDirectory: "./.reports/unit/coverage",
1414

1515
// Indicates which provider should be used to instrument code for coverage
16-
coverageProvider: 'babel',
16+
coverageProvider: "babel",
1717

1818
coverageThreshold: {
1919
global: {
@@ -24,38 +24,38 @@ export const baseJestConfig: Config = {
2424
},
2525
},
2626

27-
coveragePathIgnorePatterns: ['/__tests__/'],
28-
transform: { '^.+\\.ts$': 'ts-jest' },
29-
testPathIgnorePatterns: ['.build'],
30-
testMatch: ['**/?(*.)+(spec|test).[jt]s?(x)'],
27+
coveragePathIgnorePatterns: ["/__tests__/"],
28+
transform: { "^.+\\.ts$": "ts-jest" },
29+
testPathIgnorePatterns: [".build"],
30+
testMatch: ["**/?(*.)+(spec|test).[jt]s?(x)"],
3131

3232
// Use this configuration option to add custom reporters to Jest
3333
reporters: [
34-
'default',
34+
"default",
3535
[
36-
'jest-html-reporter',
36+
"jest-html-reporter",
3737
{
38-
pageTitle: 'Test Report',
39-
outputPath: './.reports/unit/test-report.html',
38+
pageTitle: "Test Report",
39+
outputPath: "./.reports/unit/test-report.html",
4040
includeFailureMsg: true,
4141
},
4242
],
4343
],
4444

4545
// The test environment that will be used for testing
46-
testEnvironment: 'jsdom',
46+
testEnvironment: "jsdom",
4747
};
4848

4949
const utilsJestConfig = {
5050
...baseJestConfig,
5151

52-
testEnvironment: 'node',
52+
testEnvironment: "node",
5353

5454
coveragePathIgnorePatterns: [
5555
...(baseJestConfig.coveragePathIgnorePatterns ?? []),
56-
'cli/index.ts',
57-
'helpers/s3_helpers.ts',
58-
'letter-repo-factory.ts',
56+
"cli/index.ts",
57+
"helpers/s3_helpers.ts",
58+
"letter-repo-factory.ts",
5959
],
6060
};
6161

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { LetterRepository } from "@internal/datastore/src/letter-repository";
22
import { LetterStatusType } from "@internal/datastore";
3-
import { createLetter, createLetterDto } from "../../helpers/create_letter_helpers";
3+
import {
4+
createLetter,
5+
createLetterDto,
6+
} from "../../helpers/create_letter_helpers";
47
import { uploadFile } from "../../helpers/s3_helpers";
58

69
jest.mock("../../helpers/s3_helpers");

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

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import { hideBin } from "yargs/helpers";
2-
import yargs from 'yargs';
2+
import yargs from "yargs";
33
import { LetterStatusType } from "@internal/datastore/src/types";
4-
import { randomUUID } from "crypto";
5-
import { createLetter, createLetterDto } from "../helpers/create_letter_helpers";
4+
import { randomUUID } from "node:crypto";
5+
import {
6+
createLetter,
7+
createLetterDto,
8+
} from "../helpers/create_letter_helpers";
69
import { createLetterRepository } from "../infrastructure/letter-repo-factory";
710
import { uploadFile } from "../helpers/s3_helpers";
811

@@ -60,17 +63,17 @@ async function main() {
6063
},
6164
},
6265
async (argv) => {
63-
const supplierId = argv.supplierId;
66+
const { supplierId } = argv;
6467
const letterId = argv.letterId ? argv.letterId : randomUUID();
6568
const bucketName = `nhs-${argv.awsAccountId}-eu-west-2-${argv.environment}-supapi-test-letters`;
6669
const targetFilename = `${letterId}.pdf`;
6770
const groupId = argv.groupId ? argv.groupId : randomUUID();
6871
const specificationId = argv.specificationId
6972
? argv.specificationId
7073
: randomUUID();
71-
const status = argv.status;
72-
const environment = argv.environment;
73-
const ttlHours = argv.ttlHours;
74+
const { status } = argv;
75+
const { environment } = argv;
76+
const { ttlHours } = argv;
7477
const letterRepository = createLetterRepository(environment, ttlHours);
7578

7679
createLetter({
@@ -114,7 +117,7 @@ async function main() {
114117
demandOption: false,
115118
default: 336,
116119
},
117-
"count": {
120+
count: {
118121
type: "number",
119122
demandOption: true,
120123
},
@@ -137,41 +140,46 @@ async function main() {
137140
},
138141
},
139142
async (argv) => {
140-
141143
// set batch ID
142144
const batchId = randomUUID();
143145

144146
// parse args
145-
const supplierId = argv.supplierId;
147+
const { supplierId } = argv;
146148
const groupId = argv.groupId ? argv.groupId : randomUUID();
147149
const specificationId = argv.specificationId
148150
? argv.specificationId
149151
: randomUUID();
150-
const status = argv.status;
151-
const environment = argv.environment;
152-
const ttlHours = argv.ttlHours;
152+
const { status } = argv;
153+
const { environment } = argv;
154+
const { ttlHours } = argv;
153155
const letterRepository = createLetterRepository(environment, ttlHours);
154-
const count = argv.count;
155-
156+
const { count } = argv;
156157

157158
// Upload a test file for this batch
158159
const bucketName = `nhs-${argv.awsAccountId}-eu-west-2-${argv.environment}-supapi-test-letters`;
159160
const targetFilename = `${batchId}-${status}.pdf`;
160161
const url = `s3://${bucketName}/${batchId}/${targetFilename}`;
161-
await uploadFile(bucketName, batchId, "../../test_letter.pdf", targetFilename);
162+
await uploadFile(
163+
bucketName,
164+
batchId,
165+
"../../test_letter.pdf",
166+
targetFilename,
167+
);
162168

163169
// Create letter DTOs
164-
let letterDtos = [];
170+
const letterDtos = [];
165171
for (let i = 0; i < count; i++) {
166-
letterDtos.push(createLetterDto({
167-
letterId: randomUUID(),
168-
supplierId,
169-
groupId,
170-
specificationId,
171-
status: status as LetterStatusType,
172-
url,
173-
}));
174-
};
172+
letterDtos.push(
173+
createLetterDto({
174+
letterId: randomUUID(),
175+
supplierId,
176+
groupId,
177+
specificationId,
178+
status: status as LetterStatusType,
179+
url,
180+
}),
181+
);
182+
}
175183

176184
// Upload Letters
177185
await letterRepository.putLetterBatch(letterDtos);
@@ -184,8 +192,8 @@ async function main() {
184192
}
185193

186194
if (require.main === module) {
187-
main().catch((err) => {
188-
console.error(err);
195+
main().catch((error) => {
196+
console.error(error);
189197
process.exitCode = 1;
190198
});
191199
}

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

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {
2-
LetterRepository,
32
Letter,
3+
LetterRepository,
44
LetterStatusType,
55
} from "@internal/datastore";
66
import { uploadFile } from "./s3_helpers";
@@ -16,14 +16,14 @@ export async function createLetter(params: {
1616
letterRepository: LetterRepository;
1717
}) {
1818
const {
19-
letterId,
2019
bucketName,
21-
supplierId,
22-
targetFilename,
23-
specificationId,
2420
groupId,
25-
status,
21+
letterId,
2622
letterRepository,
23+
specificationId,
24+
status,
25+
supplierId,
26+
targetFilename,
2727
} = params;
2828

2929
await uploadFile(
@@ -39,7 +39,7 @@ export async function createLetter(params: {
3939
specificationId,
4040
groupId,
4141
url: `s3://${bucketName}/${supplierId}/${targetFilename}`,
42-
status: status,
42+
status,
4343
createdAt: new Date().toISOString(),
4444
updatedAt: new Date().toISOString(),
4545
};
@@ -56,22 +56,16 @@ export function createLetterDto(params: {
5656
status: LetterStatusType;
5757
url: string;
5858
}) {
59-
const {
60-
letterId,
61-
supplierId,
62-
specificationId,
63-
groupId,
64-
status,
65-
url,
66-
} = params;
59+
const { groupId, letterId, specificationId, status, supplierId, url } =
60+
params;
6761

6862
const letter: Omit<Letter, "ttl" | "supplierStatus" | "supplierStatusSk"> = {
6963
id: letterId,
7064
supplierId,
7165
specificationId,
7266
groupId,
73-
url: url,
74-
status: status,
67+
url,
68+
status,
7569
createdAt: new Date().toISOString(),
7670
updatedAt: new Date().toISOString(),
7771
};
Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
import { S3Client, PutObjectCommand } from "@aws-sdk/client-s3";
2-
import { readFileSync } from "fs";
3-
import path from "path";
1+
import { PutObjectCommand, S3Client } from "@aws-sdk/client-s3";
2+
import { readFileSync } from "node:fs";
3+
import path from "node:path";
44

5-
6-
export async function uploadFile(bucketName: string, supplierId: string, sourceFilename: string, targetFilename: string) {
5+
export async function uploadFile(
6+
bucketName: string,
7+
supplierId: string,
8+
sourceFilename: string,
9+
targetFilename: string,
10+
) {
711
try {
812
const s3 = new S3Client();
913
const filePath = path.join(__dirname, sourceFilename);
@@ -18,7 +22,7 @@ export async function uploadFile(bucketName: string, supplierId: string, sourceF
1822

1923
const command = new PutObjectCommand(uploadParams);
2024
return await s3.send(command);
21-
} catch (err) {
22-
console.error("Error uploading file:", err);
25+
} catch (error) {
26+
console.error("Error uploading file:", error);
2327
}
2428
}

scripts/utilities/letter-test-data/src/infrastructure/letter-repo-factory.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
import { DynamoDBClient } from '@aws-sdk/client-dynamodb';
2-
import { DynamoDBDocumentClient } from '@aws-sdk/lib-dynamodb';
3-
import { pino } from 'pino';
4-
import { LetterRepository } from '@internal/datastore';
1+
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
2+
import { DynamoDBDocumentClient } from "@aws-sdk/lib-dynamodb";
3+
import { pino } from "pino";
4+
import { LetterRepository } from "@internal/datastore";
55

6-
export function createLetterRepository(environment: string, ttlHours:number): LetterRepository {
6+
export function createLetterRepository(
7+
environment: string,
8+
ttlHours: number,
9+
): LetterRepository {
710
const ddbClient = new DynamoDBClient({});
811
const docClient = DynamoDBDocumentClient.from(ddbClient);
912
const log = pino();

0 commit comments

Comments
 (0)