Skip to content

Commit b297c6e

Browse files
committed
Revert "Merge remote-tracking branch 'origin/main' into feature/CCM-11188"
This reverts commit 2b862fd, reversing changes made to 7d9230d.
1 parent 2b862fd commit b297c6e

File tree

35 files changed

+485
-947
lines changed

35 files changed

+485
-947
lines changed

.vscode/launch.json

Lines changed: 0 additions & 50 deletions
This file was deleted.

infrastructure/terraform/components/api/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@ No requirements.
3232
| Name | Source | Version |
3333
|------|--------|---------|
3434
| <a name="module_authorizer_lambda"></a> [authorizer\_lambda](#module\_authorizer\_lambda) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.20/terraform-lambda.zip | n/a |
35-
| <a name="module_domain_truststore"></a> [domain\_truststore](#module\_domain\_truststore) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.20/terraform-s3bucket.zip | n/a |
35+
| <a name="module_domain_truststore"></a> [domain\_truststore](#module\_domain\_truststore) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/s3bucket | v2.0.17 |
3636
| <a name="module_get_letters"></a> [get\_letters](#module\_get\_letters) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.20/terraform-lambda.zip | n/a |
3737
| <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 |
38-
| <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 |
38+
| <a name="module_logging_bucket"></a> [logging\_bucket](#module\_logging\_bucket) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/s3bucket | v2.0.17 |
3939
| <a name="module_patch_letters"></a> [patch\_letters](#module\_patch\_letters) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.20/terraform-lambda.zip | n/a |
40-
| <a name="module_supplier_ssl"></a> [supplier\_ssl](#module\_supplier\_ssl) | https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.20/terraform-ssl.zip | n/a |
40+
| <a name="module_supplier_ssl"></a> [supplier\_ssl](#module\_supplier\_ssl) | git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/ssl | v2.0.17 |
4141
## Outputs
4242

4343
| Name | Description |

infrastructure/terraform/components/api/locals.tf

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,4 @@ locals {
1313
})
1414

1515
destination_arn = "arn:aws:logs:${var.region}:${var.shared_infra_account_id}:destination:nhs-main-obs-firehose-logs"
16-
17-
common_db_access_lambda_env_vars = {
18-
LETTERS_TABLE_NAME = aws_dynamodb_table.letters.name,
19-
LETTER_TTL_HOURS = 24,
20-
SUPPLIER_ID_HEADER = "nhsd-supplier-id"
21-
SUPPLIER_ID_HEADER = "nhsd-correlation-id"
22-
}
2316
}

infrastructure/terraform/components/api/module_domain_truststore.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module "domain_truststore" {
2-
source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.20/terraform-s3bucket.zip"
2+
source = "git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/s3bucket?ref=v2.0.17"
33

44
name = "truststore"
55
aws_account_id = var.aws_account_id

infrastructure/terraform/components/api/module_lambda_get_letters.tf

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ module "get_letters" {
3535
log_destination_arn = local.destination_arn
3636
log_subscription_role_arn = local.acct.log_subscription_role_arn
3737

38-
lambda_env_vars = merge(local.common_db_access_lambda_env_vars, {
39-
MAX_LIMIT = var.max_get_limit
40-
})
38+
lambda_env_vars = {
39+
LETTERS_TABLE_NAME = aws_dynamodb_table.letters.name,
40+
LETTER_TTL_HOURS = var.letter_table_ttl_hours,
41+
MAX_LIMIT = var.max_get_limit,
42+
}
4143
}
4244

4345
data "aws_iam_policy_document" "get_letters_lambda" {

infrastructure/terraform/components/api/module_lambda_patch_letters.tf

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ module "patch_letters" {
3535
log_destination_arn = local.destination_arn
3636
log_subscription_role_arn = local.acct.log_subscription_role_arn
3737

38-
lambda_env_vars = merge(local.common_db_access_lambda_env_vars, {})
38+
lambda_env_vars = {
39+
LETTERS_TABLE_NAME = aws_dynamodb_table.letters.name,
40+
LETTER_TTL_HOURS = 24
41+
}
3942
}
4043

4144
data "aws_iam_policy_document" "patch_letters_lambda" {

infrastructure/terraform/components/api/module_logging_bucket.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
module "logging_bucket" {
2-
source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.20/terraform-s3bucket.zip"
2+
source = "git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/s3bucket?ref=v2.0.17"
33

44
name = "bucket-logs"
55
aws_account_id = var.aws_account_id

infrastructure/terraform/components/api/module_supplier_ssl.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module "supplier_ssl" {
22
count = var.manually_configure_mtls_truststore ? 0 : 1
33

4-
source = "https://github.com/NHSDigital/nhs-notify-shared-modules/releases/download/v2.0.20/terraform-ssl.zip"
4+
source = "git::https://github.com/NHSDigital/nhs-notify-shared-modules.git//infrastructure/modules/ssl?ref=v2.0.17"
55

66
name = "sapi_trust"
77
aws_account_id = var.aws_account_id

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

Lines changed: 131 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -67,29 +67,154 @@
6767
],
6868
"patch": {
6969
"description": "Update the status of a letter by providing the new status in the request body.",
70-
"operationId": "patchLetters",
7170
"requestBody": {
71+
"content": {
72+
"application/vnd.api+json": {
73+
"schema": {
74+
"properties": {
75+
"data": {
76+
"properties": {
77+
"attributes": {
78+
"properties": {
79+
"reasonCode": {
80+
"description": "Reason code for the given status",
81+
"type": "number"
82+
},
83+
"reasonText": {
84+
"description": "Reason text for the given status",
85+
"type": "string"
86+
},
87+
"requestedProductionStatus": {
88+
"description": "The requested production status for this letter.\nMay only be set by NHS Notify.",
89+
"enum": [
90+
"ACTIVE",
91+
"HOLD",
92+
"CANCEL"
93+
],
94+
"title": "ProductionStatus",
95+
"type": "string"
96+
},
97+
"status": {
98+
"default": "PENDING",
99+
"description": "The supplier status of an individual letter",
100+
"enum": [
101+
"PENDING",
102+
"ACCEPTED",
103+
"REJECTED",
104+
"PRINTED",
105+
"ENCLOSED",
106+
"CANCELLED",
107+
"DISPATCHED",
108+
"FAILED",
109+
"RETURNED",
110+
"DESTROYED",
111+
"FORWARDED"
112+
],
113+
"type": "string"
114+
}
115+
},
116+
"type": "object"
117+
},
118+
"id": {
119+
"type": "string"
120+
},
121+
"type": {
122+
"const": "Letter",
123+
"type": "string"
124+
}
125+
},
126+
"type": "object"
127+
}
128+
},
129+
"type": "object"
130+
}
131+
}
132+
},
72133
"required": true
73134
},
74135
"responses": {
75136
"200": {
76-
"description": "List of letters to process"
137+
"content": {
138+
"application/vnd.api+json": {
139+
"schema": {
140+
"properties": {
141+
"data": {
142+
"properties": {
143+
"attributes": {
144+
"properties": {
145+
"reasonCode": {
146+
"description": "Reason code for the given status",
147+
"type": "number"
148+
},
149+
"reasonText": {
150+
"description": "Reason text for the given status",
151+
"type": "string"
152+
},
153+
"requestedProductionStatus": {
154+
"description": "A requested status for the production of a letter",
155+
"enum": [
156+
"ACTIVE",
157+
"HOLD",
158+
"CANCEL"
159+
],
160+
"title": "ProductionStatus",
161+
"type": "string"
162+
},
163+
"status": {
164+
"default": "PENDING",
165+
"description": "The supplier status of an individual letter",
166+
"enum": [
167+
"PENDING",
168+
"ACCEPTED",
169+
"REJECTED",
170+
"PRINTED",
171+
"ENCLOSED",
172+
"CANCELLED",
173+
"DISPATCHED",
174+
"FAILED",
175+
"RETURNED",
176+
"DESTROYED",
177+
"FORWARDED"
178+
],
179+
"type": "string"
180+
}
181+
},
182+
"required": [
183+
"status",
184+
"requestedProductionStatus"
185+
],
186+
"type": "object"
187+
},
188+
"id": {
189+
"type": "string"
190+
},
191+
"type": {
192+
"const": "Letter",
193+
"type": "string"
194+
}
195+
},
196+
"type": "object"
197+
}
198+
},
199+
"type": "object"
200+
}
201+
}
202+
},
203+
"description": "Letter resource updated successfully"
77204
},
78205
"400": {
79-
"description": "Bad request, invalid input data"
206+
"description": "Bad request"
80207
},
81208
"404": {
82209
"description": "Resource not found"
83-
},
84-
"500": {
85-
"description": "Server error"
86210
}
87211
},
88212
"security": [
89213
{
90214
"LambdaAuthorizer": []
91215
}
92216
],
217+
"summary": "Update the status of a letter",
93218
"x-amazon-apigateway-integration": {
94219
"contentHandling": "CONVERT_TO_TEXT",
95220
"credentials": "${APIG_EXECUTION_ROLE_ARN}",

internal/datastore/src/__test__/letter-repository.test.ts

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -50,23 +50,21 @@ describe('LetterRepository', () => {
5050
await db.container.stop();
5151
});
5252

53+
async function checkLetterExists(supplierId: string, letterId: string) {
54+
const letter = await letterRepository.getLetterById(supplierId, letterId);
55+
expect(letter).toBeDefined();
56+
expect(letter.id).toBe(letterId);
57+
expect(letter.supplierId).toBe(supplierId);
58+
}
59+
5360
async function checkLetterStatus(supplierId: string, letterId: string, status: Letter['status']) {
5461
const letter = await letterRepository.getLetterById(supplierId, letterId);
5562
expect(letter.status).toBe(status);
5663
}
5764

5865
test('adds a letter to the database', async () => {
59-
const supplierId = 'supplier1';
60-
const letterId = 'letter1';
61-
62-
await letterRepository.putLetter(createLetter(supplierId, letterId));
63-
64-
const letter = await letterRepository.getLetterById(supplierId, letterId);
65-
expect(letter).toBeDefined();
66-
expect(letter.id).toBe(letterId);
67-
expect(letter.supplierId).toBe(supplierId);
68-
expect(letter.reasonCode).toBeUndefined();
69-
expect(letter.reasonText).toBeUndefined();
66+
await letterRepository.putLetter(createLetter('supplier1', 'letter1'));
67+
await checkLetterExists('supplier1', 'letter1');
7068
});
7169

7270
test('fetches a letter by id', async () => {
@@ -102,16 +100,11 @@ describe('LetterRepository', () => {
102100
});
103101

104102
test('updates a letter\'s status in the database', async () => {
105-
const letter = createLetter('supplier1', 'letter1', 'PENDING');
106-
await letterRepository.putLetter(letter);
103+
await letterRepository.putLetter(createLetter('supplier1', 'letter1', 'PENDING'));
107104
await checkLetterStatus('supplier1', 'letter1', 'PENDING');
108105

109-
await letterRepository.updateLetterStatus('supplier1', 'letter1', 'REJECTED', 1, "Reason text");
110-
111-
const updatedLetter = await letterRepository.getLetterById('supplier1', 'letter1');
112-
expect(updatedLetter.status).toBe('REJECTED');
113-
expect(updatedLetter.reasonCode).toBe(1);
114-
expect(updatedLetter.reasonText).toBe('Reason text');
106+
await letterRepository.updateLetterStatus('supplier1', 'letter1', 'DELIVERED');
107+
await checkLetterStatus('supplier1', 'letter1', 'DELIVERED');
115108
});
116109

117110
test('updates a letter\'s updatedAt date', async () => {
@@ -124,13 +117,13 @@ describe('LetterRepository', () => {
124117
// Month is zero-indexed in JavaScript Date
125118
// Day is one-indexed
126119
jest.setSystemTime(new Date(2020, 1, 2));
127-
await letterRepository.updateLetterStatus('supplier1', 'letter1', 'DELIVERED', undefined, undefined);
120+
await letterRepository.updateLetterStatus('supplier1', 'letter1', 'DELIVERED');
128121
const updatedLetter = await letterRepository.getLetterById('supplier1', 'letter1');
129122
expect(updatedLetter.updatedAt).toBe('2020-02-02T00:00:00.000Z');
130123
});
131124

132125
test('can\'t update a letter that does not exist', async () => {
133-
await expect(letterRepository.updateLetterStatus('supplier1', 'letter1', 'DELIVERED', undefined, undefined))
126+
await expect(letterRepository.updateLetterStatus('supplier1', 'letter1', 'DELIVERED'))
134127
.rejects.toThrow('Letter with id letter1 not found for supplier supplier1');
135128
});
136129

@@ -139,7 +132,7 @@ describe('LetterRepository', () => {
139132
...db.config,
140133
lettersTableName: 'nonexistent-table'
141134
});
142-
await expect(misconfiguredRepository.updateLetterStatus('supplier1', 'letter1', 'DELIVERED', undefined, undefined))
135+
await expect(misconfiguredRepository.updateLetterStatus('supplier1', 'letter1', 'DELIVERED'))
143136
.rejects.toThrow('Cannot do operations on a non-existent table');
144137
});
145138

@@ -164,7 +157,7 @@ describe('LetterRepository', () => {
164157
const pendingLetters = await letterRepository.getLettersByStatus('supplier1', 'PENDING');
165158
expect(pendingLetters.letters).toHaveLength(2);
166159

167-
await letterRepository.updateLetterStatus('supplier1', 'letter1', 'DELIVERED', undefined, undefined);
160+
await letterRepository.updateLetterStatus('supplier1', 'letter1', 'DELIVERED');
168161
const remainingLetters = await letterRepository.getLettersByStatus('supplier1', 'PENDING');
169162
expect(remainingLetters.letters).toHaveLength(1);
170163
expect(remainingLetters.letters[0].id).toBe('letter2');

0 commit comments

Comments
 (0)