Skip to content

Commit 9d2d436

Browse files
fix
1 parent 57cae58 commit 9d2d436

7 files changed

Lines changed: 17 additions & 23 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ TEST_CMD := APIGEE_ACCESS_TOKEN="$(APIGEE_ACCESS_TOKEN)" \
135135
--color=yes \
136136
-n 4 \
137137
--api-name=nhs-notify-supplier \
138-
--proxy-name="nhs-notify-supplier--internal-dev--nhs-notify-supplier" \
138+
--proxy-name="$(PROXY_NAME)" \
139139
-s \
140140
--reruns 5 \
141141
--reruns-delay 5 \

tests/component-tests/events-tests/event-subscription.spec.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,7 @@ test.describe("Event Subscription SNS Tests", () => {
120120
expect(getLetterResponse.status()).toBe(500);
121121
await pollUpsertLetterLogForError(
122122
"Message did not match an expected schema",
123+
domainId,
123124
);
124125
});
125126

tests/constants/api-constants.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,8 @@ export const MI_ENDPOINT = "mi";
1010
export const SUPPLIERTABLENAME = `nhs-${envName}-supapi-suppliers`;
1111
export const UPSERT_LETTER_LAMBDA_ARN = `arn:aws:lambda:eu-west-2:820178564574:function:nhs-${envName}-supapi-upsertletter`;
1212
export const DATA = "data";
13-
export const EVENT_SUBSCRIPTION_TOPIC_NAME = "nhs-main-supapi-eventsub";
13+
export const EVENT_SUBSCRIPTION_TOPIC_NAME = `nhs-${envName}-supapi-eventsub`;
14+
export const AWS_ACCOUNT_ID = process.env.AWS_ACCOUNT_ID ?? "820178564574";
15+
export const EVENT_SUBSCRIPTION_TOPIC_ARN =
16+
process.env.EVENT_SUBSCRIPTION_TOPIC_ARN ??
17+
`arn:aws:sns:${AWS_REGION}:${AWS_ACCOUNT_ID}:${EVENT_SUBSCRIPTION_TOPIC_NAME}`;

tests/helpers/aws-cloudwatch-helper.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {
22
CloudWatchLogsClient,
33
FilterLogEventsCommand,
44
} from "@aws-sdk/client-cloudwatch-logs";
5-
import { envName } from "tests/constants/api-constants";
5+
import { AWS_REGION, envName } from "tests/constants/api-constants";
66

77
const sleep = (ms: number) =>
88
new Promise((resolve) => {
@@ -16,7 +16,7 @@ export async function pollSupplierAllocatorLogForResolvedSpec(
1616
const startTimeMs = Date.now() - 5 * 60_000;
1717
const timeoutMs = 120_000;
1818

19-
const client = new CloudWatchLogsClient({});
19+
const client = new CloudWatchLogsClient({ region: AWS_REGION });
2020
const logGroupName = `/aws/lambda/nhs-${envName}-supapi-supplier-allocator`;
2121
const deadline = Date.now() + timeoutMs;
2222

@@ -42,7 +42,6 @@ export async function pollSupplierAllocatorLogForResolvedSpec(
4242
(!domainId || message.includes(domainId))
4343
);
4444
});
45-
4645
if (foundEvent?.message) {
4746
return foundEvent.message;
4847
}
@@ -57,12 +56,13 @@ export async function pollSupplierAllocatorLogForResolvedSpec(
5756

5857
export async function pollUpsertLetterLogForError(
5958
msgToCheck: string,
59+
domainId?: string,
6060
): Promise<string> {
6161
const intervalMs = 5000;
6262
const startTimeMs = Date.now() - 5 * 60_000;
6363
const timeoutMs = 120_000;
6464

65-
const client = new CloudWatchLogsClient({});
65+
const client = new CloudWatchLogsClient({ region: AWS_REGION });
6666
const logGroupName = `/aws/lambda/nhs-${envName}-supapi-upsertletter`;
6767
const deadline = Date.now() + timeoutMs;
6868

@@ -73,7 +73,9 @@ export async function pollUpsertLetterLogForError(
7373
startTime: startTimeMs,
7474
interleaved: true,
7575
limit: 100,
76-
filterPattern: `"Error processing upsert of record"`,
76+
filterPattern: domainId
77+
? `"Error processing upsert of record" "${domainId}"`
78+
: `"Error processing upsert of record"`,
7779
}),
7880
);
7981

@@ -94,6 +96,6 @@ export async function pollUpsertLetterLogForError(
9496
}
9597

9698
throw new Error(
97-
`Timed out waiting for resolved supplier spec log in ${logGroupName}`,
99+
`Timed out waiting for upsert letter error log in ${logGroupName}`,
98100
);
99101
}

tests/helpers/send-sns-event.ts

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,20 @@
11
import {
2-
CreateTopicCommand,
32
MessageAttributeValue,
43
PublishCommand,
54
PublishCommandOutput,
65
} from "@aws-sdk/client-sns";
6+
import { EVENT_SUBSCRIPTION_TOPIC_ARN } from "tests/constants/api-constants";
77
import { snsClient } from "tests/helpers/aws-sns-helper";
8-
import { EVENT_SUBSCRIPTION_TOPIC_NAME } from "tests/constants/api-constants";
98

109
export type SnsEventMessage = Record<string, unknown> | string;
1110

1211
export async function sendSnsEvent(
1312
message: SnsEventMessage,
1413
messageAttributes?: Record<string, MessageAttributeValue>,
1514
): Promise<PublishCommandOutput> {
16-
const { TopicArn } = await snsClient.send(
17-
new CreateTopicCommand({
18-
Name: EVENT_SUBSCRIPTION_TOPIC_NAME,
19-
}),
20-
);
21-
22-
if (!TopicArn) {
23-
throw new Error(
24-
`Failed to resolve SNS topic ARN for ${EVENT_SUBSCRIPTION_TOPIC_NAME}`,
25-
);
26-
}
27-
2815
return snsClient.send(
2916
new PublishCommand({
30-
TopicArn,
17+
TopicArn: EVENT_SUBSCRIPTION_TOPIC_ARN,
3118
Message: typeof message === "string" ? message : JSON.stringify(message),
3219
...(messageAttributes ? { MessageAttributes: messageAttributes } : {}),
3320
}),

tests/sandbox/create-mi.spec.ts

Whitespace-only changes.

tests/sandbox/get-letter-data.spec.ts

Whitespace-only changes.

0 commit comments

Comments
 (0)