Skip to content

Commit 3df81bb

Browse files
Fix names
1 parent 2ae8486 commit 3df81bb

File tree

12 files changed

+62
-65
lines changed

12 files changed

+62
-65
lines changed

infrastructure/terraform/components/api/README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,10 @@ No requirements.
3838
| <a name="module_get_letter_data"></a> [get\_letter\_data](#module\_get\_letter\_data) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-lambda.zip | n/a |
3939
| <a name="module_get_letters"></a> [get\_letters](#module\_get\_letters) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-lambda.zip | n/a |
4040
| <a name="module_kms"></a> [kms](#module\_kms) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.20/terraform-kms.zip | n/a |
41+
| <a name="module_letter_status_update"></a> [letter\_status\_update](#module\_letter\_status\_update) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-lambda.zip | n/a |
42+
| <a name="module_letter_status_updates_queue"></a> [letter\_status\_updates\_queue](#module\_letter\_status\_updates\_queue) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-sqs.zip | n/a |
4143
| <a name="module_logging_bucket"></a> [logging\_bucket](#module\_logging\_bucket) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.20/terraform-s3bucket.zip | n/a |
4244
| <a name="module_patch_letter"></a> [patch\_letter](#module\_patch\_letter) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-lambda.zip | n/a |
43-
| <a name="module_post_letters_processor"></a> [post\_letters\_processor](#module\_post\_letters\_processor) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-lambda.zip | n/a |
44-
| <a name="module_post_letters_queue"></a> [post\_letters\_queue](#module\_post\_letters\_queue) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-sqs.zip | n/a |
4545
| <a name="module_post_letters_receiver"></a> [post\_letters\_receiver](#module\_post\_letters\_receiver) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-lambda.zip | n/a |
4646
| <a name="module_post_mi"></a> [post\_mi](#module\_post\_mi) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-lambda.zip | n/a |
4747
| <a name="module_s3bucket_test_letters"></a> [s3bucket\_test\_letters](#module\_s3bucket\_test\_letters) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.20/terraform-s3bucket.zip | n/a |

infrastructure/terraform/components/api/iam_role_api_gateway_execution_role.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ data "aws_iam_policy_document" "api_gateway_execution_policy" {
5353
module.get_letter_data.function_arn,
5454
module.get_letters.function_arn,
5555
module.patch_letter.function_arn,
56-
module.post_letters.function_arn,
56+
module.post_letters_receiver.function_arn,
5757
module.post_mi.function_arn
5858
]
5959
}

infrastructure/terraform/components/api/locals.tf

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ locals {
55
root_domain_nameservers = local.acct.route53_zone_nameservers["supplier-api"]
66

77
openapi_spec = templatefile("${path.module}/resources/spec.tmpl.json", {
8-
APIG_EXECUTION_ROLE_ARN = aws_iam_role.api_gateway_execution_role.arn
9-
AWS_REGION = var.region
10-
AUTHORIZER_LAMBDA_ARN = module.authorizer_lambda.function_arn
11-
GET_LETTER_LAMBDA_ARN = module.get_letter.function_arn
12-
GET_LETTERS_LAMBDA_ARN = module.get_letters.function_arn
13-
GET_LETTER_DATA_LAMBDA_ARN = module.get_letter_data.function_arn
14-
PATCH_LETTER_LAMBDA_ARN = module.patch_letter.function_arn
15-
POST_LETTERS_LAMBDA_ARN = module.post_letters.function_arn
16-
POST_MI_LAMBDA_ARN = module.post_mi.function_arn
8+
APIG_EXECUTION_ROLE_ARN = aws_iam_role.api_gateway_execution_role.arn
9+
AWS_REGION = var.region
10+
AUTHORIZER_LAMBDA_ARN = module.authorizer_lambda.function_arn
11+
GET_LETTER_LAMBDA_ARN = module.get_letter.function_arn
12+
GET_LETTERS_LAMBDA_ARN = module.get_letters.function_arn
13+
GET_LETTER_DATA_LAMBDA_ARN = module.get_letter_data.function_arn
14+
PATCH_LETTER_LAMBDA_ARN = module.patch_letter.function_arn
15+
POST_LETTERS_RECEIVER_LAMBDA_ARN = module.post_letters_receiver.function_arn
16+
POST_MI_LAMBDA_ARN = module.post_mi.function_arn
1717
})
1818

1919
destination_arn = "arn:aws:logs:${var.region}:${var.shared_infra_account_id}:destination:nhs-main-obs-firehose-logs"

infrastructure/terraform/components/api/module_lambda_post_letters_processor.tf renamed to infrastructure/terraform/components/api/module_lambda_letter_status_update.tf

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
module "post_letters_processor" {
1+
module "letter_status_update" {
22
source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-lambda.zip"
33

4-
function_name = "post_letters_processor"
4+
function_name = "letter_status_update"
55
description = "Processes letter status updates"
66

77
aws_account_id = var.aws_account_id
@@ -15,14 +15,14 @@ module "post_letters_processor" {
1515
kms_key_arn = module.kms.key_arn
1616

1717
iam_policy_document = {
18-
body = data.aws_iam_policy_document.post_letters_processor.json
18+
body = data.aws_iam_policy_document.letter_status_update.json
1919
}
2020

2121
function_s3_bucket = local.acct.s3_buckets["lambda_function_artefacts"]["id"]
2222
function_code_base_path = local.aws_lambda_functions_dir_path
2323
function_code_dir = "api-handler/dist"
2424
function_include_common = true
25-
handler_function_name = "postLetters"
25+
handler_function_name = "statusUpdateHandler"
2626
runtime = "nodejs22.x"
2727
memory = 128
2828
timeout = 5
@@ -38,7 +38,7 @@ module "post_letters_processor" {
3838
lambda_env_vars = merge(local.common_lambda_env_vars, {})
3939
}
4040

41-
data "aws_iam_policy_document" "post_letters_processor" {
41+
data "aws_iam_policy_document" "letter_status_update" {
4242
statement {
4343
sid = "KMSPermissions"
4444
effect = "Allow"
@@ -78,7 +78,7 @@ data "aws_iam_policy_document" "post_letters_processor" {
7878
]
7979

8080
resources = [
81-
module.post_letters_queue.sqs_queue_arn
81+
module.letter_status_updates_queue.sqs_queue_arn
8282
]
8383
}
8484
}

infrastructure/terraform/components/api/module_lambda_post_letters_receiver.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ module "post_letters_receiver" {
2222
function_code_base_path = local.aws_lambda_functions_dir_path
2323
function_code_dir = "api-handler/dist"
2424
function_include_common = true
25-
handler_function_name = "postLetters"
25+
handler_function_name = "postLettersReceiver"
2626
runtime = "nodejs22.x"
2727
memory = 128
2828
timeout = 5
@@ -36,7 +36,7 @@ module "post_letters_receiver" {
3636
log_subscription_role_arn = local.acct.log_subscription_role_arn
3737

3838
lambda_env_vars = merge(local.common_lambda_env_vars, {
39-
QUEUE_URL = module.post_letters_queue.sqs_queue_url
39+
QUEUE_URL = module.letter_status_updates_queue.sqs_queue_url
4040
})
4141
}
4242

@@ -65,7 +65,7 @@ data "aws_iam_policy_document" "post_letters_receiver" {
6565
]
6666

6767
resources = [
68-
module.post_letters_queue.sqs_queue_arn
68+
module.letter_status_updates_queue.sqs_queue_arn
6969
]
7070
}
7171
}

infrastructure/terraform/components/api/module_sqs_post_letters_queue.tf renamed to infrastructure/terraform/components/api/module_sqs_letter_status_updates.tf

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
module "post_letters_queue" {
1+
module "letter_status_updates_queue" {
22
source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.24/terraform-sqs.zip"
33

4-
name = "post_letters_queue"
5-
description = "Queues a collection of letters to update"
4+
name = "letter_status_updates_queue"
5+
description = "Queue to transport update letter status messages"
66

77
aws_account_id = var.aws_account_id
88
component = var.component
@@ -14,11 +14,11 @@ module "post_letters_queue" {
1414
sqs_kms_key_arn = module.kms.key_arn
1515

1616
iam_policy_document = {
17-
body = data.aws_iam_policy_document.post_letters_queue.json
17+
body = data.aws_iam_policy_document.letter_status_updates_queue.json
1818
}
1919
}
2020

21-
data "aws_iam_policy_document" "post_letters_queue" {
21+
data "aws_iam_policy_document" "letter_status_updates_queue" {
2222

2323
statement {
2424
sid = "KMSPermissions"
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
resource "aws_lambda_event_source_mapping" "sqs_to_processor" {
2-
event_source_arn = module.post_letters_queue.sqs_queue_arn
3-
function_name = module.post_letters_processor.arn
1+
resource "aws_lambda_event_source_mapping" "status_update_sqs_to_status_update_handler" {
2+
event_source_arn = module.letter_status_updates_queue.sqs_queue_arn
3+
function_name = module.letter_status_update.arn
44
batch_size = 10
55
maximum_batching_window_in_seconds = 1
66
scaling_config { maximum_concurrency = 10 }
77
}
88

99
depends_on = [
10-
module.post_letters_queue, # ensures queue exists
11-
module.post_letters_processor # ensures processor exists
12-
# aws_iam_role_policy.post_letters_processor, # ensures permissions exist
13-
# aws_iam_role_policy.post_letters_receiver, # ensures permissions exist
10+
module.letter_status_updates_queue, # ensures queue exists
11+
module.letter_status_update # ensures update handler exists
12+
# aws_iam_role_policy.letter_status_update, # ensures permissions exist?
13+
# aws_iam_role_policy.post_letters_receiver # ensures permissions exist?
1414
]

infrastructure/terraform/components/api/resources/spec.tmpl.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@
8686
},
8787
"timeoutInMillis": 29000,
8888
"type": "AWS_PROXY",
89-
"uri": "arn:aws:apigateway:${AWS_REGION}:lambda:path/2015-03-31/functions/${POST_LETTERS_LAMBDA_ARN}/invocations"
89+
"uri": "arn:aws:apigateway:${AWS_REGION}:lambda:path/2015-03-31/functions/${POST_LETTERS_RECEIVER_LAMBDA_ARN}/invocations"
9090
}
9191
}
9292
},

lambdas/api-handler/src/handlers/__tests__/post-letters-processor.test.ts renamed to lambdas/api-handler/src/handlers/__tests__/letter-status-update.test.ts

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,14 @@
1-
import { APIGatewayProxyResult, Context, SQSEvent, SQSRecord } from 'aws-lambda';
1+
import { Context, SQSEvent, SQSRecord } from 'aws-lambda';
22
import { mockDeep } from 'jest-mock-extended';
3-
import { makeApiGwEvent } from './utils/test-utils';
4-
import { LetterDto, PostLettersRequest } from '../../contracts/letters';
5-
import { ValidationError } from '../../errors';
6-
import * as errors from '../../contracts/errors';
3+
import { LetterDto } from '../../contracts/letters';
74
import { S3Client } from '@aws-sdk/client-s3';
85
import pino from 'pino';
96
import { LetterRepository } from '@internal/datastore/src';
107
import { EnvVars } from '../../config/env';
118
import { Deps } from '../../config/deps';
12-
import { createPostLettersReceiverHandler } from '../post-letters-receiver';
13-
import { createPostLettersProcessorHandler } from '../post-letters-processor';
9+
import { createLetterStatusUpdateHandler } from '../letter-status-update';
1410

15-
describe('postLettersProcessorHandler', () => {
11+
describe('createLetterStatusUpdateHandler', () => {
1612

1713
beforeEach(() => {
1814
jest.clearAllMocks();
@@ -63,8 +59,8 @@ describe('postLettersProcessorHandler', () => {
6359
const context = mockDeep<Context>();
6460
const callback = jest.fn();
6561

66-
const postLettersHandler = createPostLettersProcessorHandler(mockedDeps);
67-
await postLettersHandler(buildEvent(lettersToUpdate), context, callback);
62+
const letterStatusUpdateHandler = createLetterStatusUpdateHandler(mockedDeps);
63+
await letterStatusUpdateHandler(buildEvent(lettersToUpdate), context, callback);
6864

6965
expect(mockedDeps.letterRepo.updateLetterStatus).toHaveBeenNthCalledWith(1, lettersToUpdate[0]);
7066
expect(mockedDeps.letterRepo.updateLetterStatus).toHaveBeenNthCalledWith(2, lettersToUpdate[1]);
@@ -99,8 +95,8 @@ describe('postLettersProcessorHandler', () => {
9995
supplierId: 's1'
10096
}];
10197

102-
const postLettersHandler = createPostLettersProcessorHandler(mockedDeps);
103-
await postLettersHandler(buildEvent(letterToUpdate), context, callback);
98+
const letterStatusUpdateHandler = createLetterStatusUpdateHandler(mockedDeps);
99+
await letterStatusUpdateHandler(buildEvent(letterToUpdate), context, callback);
104100

105101
expect(mockedDeps.letterRepo.updateLetterStatus).toHaveBeenCalledWith(letterToUpdate[0]);
106102
expect(mockedDeps.logger.error).toHaveBeenCalledWith({ err: mockError},

lambdas/api-handler/src/handlers/__tests__/post-letters-receiver.test.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,8 @@ describe('postLetters API Handler', () => {
9292

9393
mockedBatchUpdateStatus.mockResolvedValue();
9494

95-
const postLettersHandler = createPostLettersReceiverHandler(mockedDeps);
96-
const result = await postLettersHandler(event, context, callback);
95+
const postLettersReceiverHandler = createPostLettersReceiverHandler(mockedDeps);
96+
const result = await postLettersReceiverHandler(event, context, callback);
9797

9898
expect(result).toEqual({
9999
statusCode: 202,
@@ -113,8 +113,8 @@ describe('postLetters API Handler', () => {
113113
const context = mockDeep<Context>();
114114
const callback = jest.fn();
115115

116-
const postLettersHandler = createPostLettersReceiverHandler(mockedDeps);
117-
const result = await postLettersHandler(event, context, callback);
116+
const postLettersReceiverHandler = createPostLettersReceiverHandler(mockedDeps);
117+
const result = await postLettersReceiverHandler(event, context, callback);
118118

119119
expect(mockedProcessError).toHaveBeenCalledWith(new Error('The supplier ID is missing from the request'), 'correlationId', mockedDeps.logger);
120120
expect(result).toEqual(expectedErrorResponse);
@@ -132,8 +132,8 @@ describe('postLetters API Handler', () => {
132132
const context = mockDeep<Context>();
133133
const callback = jest.fn();
134134

135-
const postLettersHandler = createPostLettersReceiverHandler(mockedDeps);
136-
const result = await postLettersHandler(event, context, callback);
135+
const postLettersReceiverHandler = createPostLettersReceiverHandler(mockedDeps);
136+
const result = await postLettersReceiverHandler(event, context, callback);
137137

138138
expect(mockedProcessError).toHaveBeenCalledWith(new Error("The request headers don't contain the APIM correlation id"), undefined, mockedDeps.logger);
139139
expect(result).toEqual(expectedErrorResponse);
@@ -151,8 +151,8 @@ describe('postLetters API Handler', () => {
151151
const context = mockDeep<Context>();
152152
const callback = jest.fn();
153153

154-
const postLettersHandler = createPostLettersReceiverHandler(mockedDeps);
155-
const result = await postLettersHandler(event, context, callback);
154+
const postLettersReceiverHandler = createPostLettersReceiverHandler(mockedDeps);
155+
const result = await postLettersReceiverHandler(event, context, callback);
156156

157157
expect(mockedProcessError).toHaveBeenCalledWith(new ValidationError(errors.ApiErrorDetail.InvalidRequestMissingBody), 'correlationId', mockedDeps.logger);
158158
expect(result).toEqual(expectedErrorResponse);
@@ -171,8 +171,8 @@ describe('postLetters API Handler', () => {
171171
const context = mockDeep<Context>();
172172
const callback = jest.fn();
173173

174-
const postLettersHandler = createPostLettersReceiverHandler(mockedDeps);
175-
const result = await postLettersHandler(event, context, callback);
174+
const postLettersReceiverHandler = createPostLettersReceiverHandler(mockedDeps);
175+
const result = await postLettersReceiverHandler(event, context, callback);
176176

177177
expect(mockedProcessError).toHaveBeenCalledWith(new ValidationError(errors.ApiErrorDetail.InvalidRequestBody), 'correlationId', mockedDeps.logger);
178178
expect(result).toEqual(expectedErrorResponse);
@@ -202,8 +202,8 @@ describe('postLetters API Handler', () => {
202202
const context = mockDeep<Context>();
203203
const callback = jest.fn();
204204

205-
const postLettersHandler = createPostLettersReceiverHandler(mockedDeps);
206-
const result = await postLettersHandler(event, context, callback);
205+
const postLettersReceiverHandler = createPostLettersReceiverHandler(mockedDeps);
206+
const result = await postLettersReceiverHandler(event, context, callback);
207207

208208
expect(mockedProcessError).toHaveBeenCalledWith(new ValidationError(errors.ApiErrorDetail.InvalidRequestLettersToUpdate, { args: [mockedDeps.env.MAX_LIMIT]}), 'correlationId', mockedDeps.logger);
209209
expect(result).toEqual(expectedErrorResponse);
@@ -222,8 +222,8 @@ describe('postLetters API Handler', () => {
222222
const context = mockDeep<Context>();
223223
const callback = jest.fn();
224224

225-
const postLettersHandler = createPostLettersReceiverHandler(mockedDeps);
226-
const result = await postLettersHandler(event, context, callback);
225+
const postLettersReceiverHandler = createPostLettersReceiverHandler(mockedDeps);
226+
const result = await postLettersReceiverHandler(event, context, callback);
227227

228228
expect(mockedProcessError).toHaveBeenCalledWith(new ValidationError(errors.ApiErrorDetail.InvalidRequestBody), 'correlationId', mockedDeps.logger);
229229
expect(result).toEqual(expectedErrorResponse);
@@ -247,8 +247,8 @@ describe('postLetters API Handler', () => {
247247
throw error;
248248
});
249249

250-
const postLettersHandler = createPostLettersReceiverHandler(mockedDeps);
251-
const result = await postLettersHandler(event, context, callback);
250+
const postLettersReceiverHandler = createPostLettersReceiverHandler(mockedDeps);
251+
const result = await postLettersReceiverHandler(event, context, callback);
252252

253253
expect(mockedProcessError).toHaveBeenCalledWith(error, 'correlationId', mockedDeps.logger);
254254
expect(result).toEqual(expectedErrorResponse);

0 commit comments

Comments
 (0)