Skip to content

Commit 8db51f0

Browse files
committed
CCM-14205 - Refactored tests to share helper files
1 parent 19bbc52 commit 8db51f0

19 files changed

Lines changed: 197 additions & 170 deletions

File tree

eslint.config.mjs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ export default defineConfig([
6767
project: [
6868
"frontend/tsconfig.json",
6969
"lambdas/*/tsconfig.json",
70+
"tests/integration/tsconfig.json",
7071
"tests/performance/tsconfig.json",
72+
"tests/test-support/tsconfig.json",
7173
"tests/test-team/tsconfig.json",
7274
"utils/*/tsconfig.json",
7375
],
@@ -214,7 +216,7 @@ export default defineConfig([
214216
{
215217
// Files inside helpers/ are loaded transitively by globalSetup/globalTeardown which run
216218
// outside Jest's module system, so moduleNameMapper does not apply — relative imports only
217-
files: ["tests/integration/helpers/**", "tests/performance/helpers/**"],
219+
files: ["tests/integration/helpers/**", "tests/performance/helpers/**", "tests/test-support/helpers/**"],
218220
rules: {
219221
"no-relative-import-paths/no-relative-import-paths": 0,
220222
},

package-lock.json

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
"lambdas/mock-webhook-lambda",
7171
"tests/integration",
7272
"tests/performance",
73+
"tests/test-support",
7374
"tools/client-subscriptions-management"
7475
]
7576
}

scripts/config/sonar-scanner.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@ sonar.qualitygate.wait=true
55
sonar.sourceEncoding=UTF-8
66
sonar.terraform.provider.aws.version=5.54.1
77
sonar.cpd.exclusions=**.test.*, src/models/**
8-
sonar.coverage.exclusions=tests/**, lambdas/**/src/__tests__/**, src/**/src/__tests__/**, src/models/**, scripts/**/src/__tests__/**, tools/**/src/__tests__/**, **/jest.config.*
8+
sonar.coverage.exclusions=tests/test-support/**, tests/**, lambdas/**/src/__tests__/**, src/**/src/__tests__/**, src/models/**, scripts/**/src/__tests__/**, tools/**/src/__tests__/**, **/jest.config.*
99
sonar.javascript.lcov.reportPaths=lcov.info
Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,5 @@
1-
import { CloudWatchLogsClient } from "@aws-sdk/client-cloudwatch-logs";
2-
import { S3Client } from "@aws-sdk/client-s3";
3-
import { SQSClient } from "@aws-sdk/client-sqs";
4-
5-
import type { DeploymentDetails } from "./deployment";
6-
7-
export function createCloudWatchLogsClient({
8-
region,
9-
}: DeploymentDetails): CloudWatchLogsClient {
10-
return new CloudWatchLogsClient({ region });
11-
}
12-
13-
export function createS3Client({ region }: DeploymentDetails): S3Client {
14-
return new S3Client({ region });
15-
}
16-
17-
export function createSqsClient({ region }: DeploymentDetails): SQSClient {
18-
return new SQSClient({ region });
19-
}
1+
export {
2+
createCloudWatchLogsClient,
3+
createS3Client,
4+
createSqsClient,
5+
} from "@nhs-notify-client-callbacks/test-support/helpers/clients";
Lines changed: 6 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,6 @@
1-
export type DeploymentDetails = {
2-
region: string;
3-
environment: string;
4-
project: string;
5-
component: string;
6-
accountId: string;
7-
};
8-
9-
export function getDeploymentDetails(): DeploymentDetails {
10-
const region = process.env.AWS_REGION ?? "eu-west-2";
11-
const environment = process.env.ENVIRONMENT;
12-
const project = process.env.PROJECT ?? "nhs";
13-
const component = process.env.COMPONENT ?? "callbacks";
14-
const accountId = process.env.AWS_ACCOUNT_ID;
15-
16-
if (!environment) {
17-
throw new Error("ENVIRONMENT environment variable must be set");
18-
}
19-
20-
if (!accountId) {
21-
throw new Error("AWS_ACCOUNT_ID environment variable must be set");
22-
}
23-
24-
return { region, environment, project, component, accountId };
25-
}
26-
27-
export function buildSubscriptionConfigBucketName({
28-
accountId,
29-
component,
30-
environment,
31-
project,
32-
region,
33-
}: DeploymentDetails): string {
34-
return `${project}-${accountId}-${region}-${environment}-${component}-subscription-config`;
35-
}
36-
37-
export function buildLambdaLogGroupName(
38-
{ component, environment, project }: DeploymentDetails,
39-
functionIdentifier: string,
40-
): string {
41-
return `/aws/lambda/${project}-${environment}-${component}-${functionIdentifier}`;
42-
}
1+
export {
2+
buildLambdaLogGroupName,
3+
buildSubscriptionConfigBucketName,
4+
type DeploymentDetails,
5+
getDeploymentDetails,
6+
} from "@nhs-notify-client-callbacks/test-support/helpers/deployment";

tests/integration/helpers/sqs.ts

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,11 @@ import {
1111
import { logger } from "@nhs-notify-client-callbacks/logger";
1212
import { waitUntil } from "async-wait-until";
1313

14-
import type { DeploymentDetails } from "./deployment";
14+
export {
15+
buildInboundEventDlqQueueUrl,
16+
buildInboundEventQueueUrl,
17+
buildMockClientDlqQueueUrl,
18+
} from "@nhs-notify-client-callbacks/test-support/helpers/sqs";
1519

1620
const QUEUE_WAIT_TIMEOUT_MS = 60_000;
1721
const POLL_INTERVAL_MS = 500;
@@ -33,38 +37,6 @@ function buildReceiveMessageInput(
3337
};
3438
}
3539

36-
function buildQueueUrl(
37-
{ accountId, component, environment, project, region }: DeploymentDetails,
38-
name: string,
39-
options?: { appendQueueSuffix?: boolean },
40-
): string {
41-
const appendQueueSuffix = options?.appendQueueSuffix ?? true;
42-
const queueName = appendQueueSuffix
43-
? `${project}-${environment}-${component}-${name}-queue`
44-
: `${project}-${environment}-${component}-${name}`;
45-
return `https://sqs.${region}.amazonaws.com/${accountId}/${queueName}`;
46-
}
47-
48-
export function buildInboundEventQueueUrl(
49-
deploymentDetails: DeploymentDetails,
50-
): string {
51-
return buildQueueUrl(deploymentDetails, "inbound-event");
52-
}
53-
54-
export function buildInboundEventDlqQueueUrl(
55-
deploymentDetails: DeploymentDetails,
56-
): string {
57-
return buildQueueUrl(deploymentDetails, "inbound-event-dlq", {
58-
appendQueueSuffix: false,
59-
});
60-
}
61-
62-
export function buildMockClientDlqQueueUrl(
63-
deploymentDetails: DeploymentDetails,
64-
): string {
65-
return buildQueueUrl(deploymentDetails, "mock-client-dlq");
66-
}
67-
6840
export async function sendSqsEvent<T>(
6941
client: SQSClient,
7042
queueUrl: string,

tests/integration/package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
"@aws-sdk/client-cloudwatch-logs": "^3.991.0",
1616
"@aws-sdk/client-s3": "^3.821.0",
1717
"@aws-sdk/client-sqs": "^3.990.0",
18-
"async-wait-until": "^2.0.12"
18+
"async-wait-until": "^2.0.12",
19+
"@nhs-notify-client-callbacks/test-support": "*"
1920
},
2021
"devDependencies": {
2122
"@aws-sdk/client-sqs": "^3.990.0",
Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,5 @@
1-
import { CloudWatchLogsClient } from "@aws-sdk/client-cloudwatch-logs";
2-
import { S3Client } from "@aws-sdk/client-s3";
3-
import { SQSClient } from "@aws-sdk/client-sqs";
4-
5-
import type { DeploymentDetails } from "./deployment";
6-
7-
export function createCloudWatchLogsClient({
8-
region,
9-
}: DeploymentDetails): CloudWatchLogsClient {
10-
return new CloudWatchLogsClient({ region });
11-
}
12-
13-
export function createS3Client({ region }: DeploymentDetails): S3Client {
14-
return new S3Client({ region });
15-
}
16-
17-
export function createSqsClient({ region }: DeploymentDetails): SQSClient {
18-
return new SQSClient({ region });
19-
}
1+
export {
2+
createCloudWatchLogsClient,
3+
createS3Client,
4+
createSqsClient,
5+
} from "@nhs-notify-client-callbacks/test-support/helpers/clients";
Lines changed: 14 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,43 +1,17 @@
1-
export type DeploymentDetails = {
2-
region: string;
3-
environment: string;
4-
project: string;
5-
component: string;
6-
accountId: string;
7-
};
1+
import {
2+
type DeploymentDetails,
3+
buildLambdaLogGroupName,
4+
} from "@nhs-notify-client-callbacks/test-support/helpers/deployment";
85

9-
export function getDeploymentDetails(): DeploymentDetails {
10-
const region = process.env.AWS_REGION ?? "eu-west-2";
11-
const environment = process.env.ENVIRONMENT;
12-
const project = process.env.PROJECT ?? "nhs";
13-
const component = process.env.COMPONENT ?? "callbacks";
14-
const accountId = process.env.AWS_ACCOUNT_ID;
15-
16-
if (!environment) {
17-
throw new Error("ENVIRONMENT environment variable must be set");
18-
}
19-
20-
if (!accountId) {
21-
throw new Error("AWS_ACCOUNT_ID environment variable must be set");
22-
}
23-
24-
return { region, environment, project, component, accountId };
6+
export function buildTransformFilterLambdaLogGroupName(
7+
details: DeploymentDetails,
8+
): string {
9+
return buildLambdaLogGroupName(details, "client-transform-filter");
2510
}
2611

27-
export function buildSubscriptionConfigBucketName({
28-
accountId,
29-
component,
30-
environment,
31-
project,
32-
region,
33-
}: DeploymentDetails): string {
34-
return `${project}-${accountId}-${region}-${environment}-${component}-subscription-config`;
35-
}
36-
37-
export function buildTransformFilterLambdaLogGroupName({
38-
component,
39-
environment,
40-
project,
41-
}: DeploymentDetails): string {
42-
return `/aws/lambda/${project}-${environment}-${component}-client-transform-filter`;
43-
}
12+
export {
13+
buildSubscriptionConfigBucketName,
14+
type DeploymentDetails,
15+
getDeploymentDetails,
16+
buildLambdaLogGroupName,
17+
} from "@nhs-notify-client-callbacks/test-support/helpers/deployment";

0 commit comments

Comments
 (0)