Skip to content

Commit 19b0731

Browse files
committed
move supplier to the event
1 parent 5ff253b commit 19b0731

File tree

22 files changed

+255
-707
lines changed

22 files changed

+255
-707
lines changed

infrastructure/terraform/components/acct/variables.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,5 +111,6 @@ variable "letter_suppliers" {
111111
default_supplier = optional(bool)
112112
}))
113113
description = "Letter suppliers enabled in the account (across all environments)"
114-
default = {}
114+
115+
default = {}
115116
}

infrastructure/terraform/components/app/variables.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,16 @@ variable "letter_suppliers" {
198198
enable_polling = bool
199199
default_supplier = optional(bool)
200200
}))
201+
202+
validation {
203+
condition = (
204+
length(var.letter_suppliers) == 0 ||
205+
length([for s in values(var.suppliers) : s if s.default_supplier]) == 1
206+
)
207+
error_message = "If letter suppliers are configured, exactly one must be default_supplier"
208+
}
209+
201210
default = {}
211+
202212
description = "Letter suppliers enabled in the environment"
203213
}

infrastructure/terraform/components/sandbox/variables.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,22 @@ variable "letter_suppliers" {
6868
enable_polling = bool
6969
default_supplier = optional(bool)
7070
}))
71+
7172
default = {
7273
"WTMMOCK" = {
7374
enable_polling = true
7475
default_supplier = true
7576
}
7677
}
78+
79+
validation {
80+
condition = (
81+
length(var.letter_suppliers) == 0 ||
82+
length([for s in values(var.suppliers) : s if s.default_supplier]) == 1
83+
)
84+
error_message = "If letter suppliers are configured, exactly one must be default_supplier"
85+
}
86+
7787
description = "Letter suppliers enabled in the environment"
7888
}
7989

infrastructure/terraform/modules/backend-api/module_lambda_send_letter_proof.tf

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,8 @@ module "lambda_send_letter_proof" {
1515
execution_role_policy_document = data.aws_iam_policy_document.send_letter_proof.json
1616

1717
environment_variables = {
18-
CREDENTIALS_TTL_MS = 900 * 1000
18+
CREDENTIALS_TTL_SECONDS = 900
1919
CSI = local.csi
20-
DEFAULT_LETTER_SUPPLIER = try(local.default_letter_supplier.name, "unset")
2120
ENVIRONMENT = var.environment
2221
INTERNAL_BUCKET_NAME = module.s3bucket_internal.id
2322
NODE_OPTIONS = "--enable-source-maps",

lambdas/sftp-letters/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
"nhs-notify-entity-update-command-builder": "*",
3737
"nhs-notify-web-template-management-test-helper-utils": "*",
3838
"nhs-notify-web-template-management-utils": "*",
39+
"node-cache": "^5.1.2",
3940
"ssh2-sftp-client": "^9.1.0",
4041
"zod": "^3.24.2"
4142
}

lambdas/sftp-letters/src/__tests__/api/send-handler.test.ts

Lines changed: 2 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,9 @@ import { createHandler } from '../../api/send-handler';
33
import { App } from '../../app/send';
44
import { createMockLogger } from 'nhs-notify-web-template-management-test-helper-utils/mock-logger';
55
import { SftpSupplierClientRepository } from '../../infra/sftp-supplier-client-repository';
6-
import { SftpClient } from '../../infra/sftp-client';
76
import { Callback, Context } from 'aws-lambda';
87
import { makeSQSRecord } from 'nhs-notify-web-template-management-test-helper-utils';
98

10-
const defaultSupplier = 'LETTERSUPPLIER';
11-
const baseUploadDir = 'Incoming';
12-
const baseDownloadDir = 'Outgoing';
13-
149
function setup() {
1510
const app = mock<App>();
1611

@@ -20,8 +15,6 @@ function setup() {
2015

2116
const handler = createHandler({
2217
app,
23-
sftpSupplierClientRepository,
24-
defaultSupplier,
2518
logger,
2619
});
2720

@@ -33,27 +26,15 @@ function setup() {
3326
}
3427

3528
describe('handler', () => {
36-
test('opens SFTP connection, handles proof requests, and closes connection', async () => {
29+
test('handles proof requests', async () => {
3730
const { mocks, handler, logMessages } = setup();
3831

39-
const client = mock<SftpClient>();
40-
41-
client.connect.mockResolvedValueOnce();
42-
43-
mocks.sftpSupplierClientRepository.getClient.mockResolvedValueOnce({
44-
sftpClient: client,
45-
baseDownloadDir,
46-
baseUploadDir,
47-
});
48-
4932
mocks.app.send
5033
.mockResolvedValueOnce('sent')
5134
.mockRejectedValueOnce(new Error('!'))
5235
.mockResolvedValueOnce('failed')
5336
.mockResolvedValueOnce('already-sent');
5437

55-
client.end.mockResolvedValueOnce();
56-
5738
const record1 = makeSQSRecord({ body: JSON.stringify({}), messageId: 'a' });
5839
const record2 = makeSQSRecord({ body: JSON.stringify({}), messageId: 'b' });
5940
const record3 = makeSQSRecord({ body: JSON.stringify({}), messageId: 'c' });
@@ -68,27 +49,14 @@ describe('handler', () => {
6849
mock<Callback>()
6950
);
7051

71-
expect(mocks.sftpSupplierClientRepository.getClient).toHaveBeenCalledTimes(
72-
1
73-
);
74-
expect(mocks.sftpSupplierClientRepository.getClient).toHaveBeenCalledWith(
75-
defaultSupplier
76-
);
77-
78-
expect(client.connect).toHaveBeenCalledTimes(1);
79-
8052
expect(mocks.app.send).toHaveBeenCalledTimes(4);
8153
for (const record of records) {
8254
expect(mocks.app.send).toHaveBeenCalledWith(
8355
record.body,
84-
record.messageId,
85-
client,
86-
baseUploadDir
56+
record.messageId
8757
);
8858
}
8959

90-
expect(client.end).toHaveBeenCalledTimes(1);
91-
9260
expect(response).toEqual({
9361
batchItemFailures: [{ itemIdentifier: 'b' }, { itemIdentifier: 'c' }],
9462
});
@@ -105,50 +73,6 @@ describe('handler', () => {
10573
expect(logMessages).toContainEqual(
10674
expect.objectContaining({
10775
message: { 'already-sent': 1, failed: 2, sent: 1 },
108-
recordCount: 4,
109-
supplier: defaultSupplier,
110-
})
111-
);
112-
});
113-
114-
test('logs error and resolves when failing to close SFTP connection', async () => {
115-
const { mocks, handler, logMessages } = setup();
116-
117-
const client = mock<SftpClient>();
118-
119-
client.connect.mockResolvedValueOnce();
120-
121-
mocks.sftpSupplierClientRepository.getClient.mockResolvedValueOnce({
122-
sftpClient: client,
123-
baseDownloadDir,
124-
baseUploadDir,
125-
});
126-
127-
mocks.app.send.mockResolvedValue('sent');
128-
129-
const error = new Error('close error');
130-
131-
client.end.mockRejectedValue(error);
132-
133-
const response = await handler(
134-
{
135-
Records: [],
136-
},
137-
mock<Context>(),
138-
mock<Callback>()
139-
);
140-
141-
expect(client.connect).toHaveBeenCalledTimes(1);
142-
expect(client.end).toHaveBeenCalledTimes(1);
143-
144-
expect(response).toEqual({ batchItemFailures: [] });
145-
146-
expect(logMessages).toContainEqual(
147-
expect.objectContaining({
148-
description: 'Failed to close SFTP connection',
149-
recordCount: 0,
150-
message: error.message,
151-
stack: error.stack,
15276
})
15377
);
15478
});

0 commit comments

Comments
 (0)