Skip to content

Commit bdf2296

Browse files
CCM-13135: Updated client to persist DL information
1 parent 0fffedd commit bdf2296

File tree

13 files changed

+168
-329
lines changed

13 files changed

+168
-329
lines changed

.coverage

0 Bytes
Binary file not shown.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Clone the repository
3333
```shell
3434
git clone https://github.com/NHSDigital/nhs-notify-digital-letters.git
3535
cd nhs-notify-digital-letters
36-
code protject.code-workspace
36+
code project.code-workspace
3737
```
3838

3939
Reopen with container

utils/client-management/src/__test__/app/get-client.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ import { GetClientCommandParameters } from '../../app/get-client';
66
function setup() {
77
const client: Client = {
88
clientId: 'test_client_id',
9-
name: 'test_client_name',
10-
meshMailboxId: 'test_client_mesh_mailbox_id',
11-
meshWorkflowIdSuffix: 'test_client_mesh_workflow_id_suffix',
12-
senderOdsCode: 'test_ods_code',
9+
clientName: 'test_client_name',
10+
meshMailboxSenderId: 'test_client_mesh_mailbox_sender_id',
11+
meshMailboxReportsId: 'test_client_mesh_mailbox_reports_id',
12+
fallbackWaitTimeSeconds: 300,
13+
routingConfigId: '1234',
1314
};
1415

1516
const mocks = mockDeep<AppDependencies>({

utils/client-management/src/__test__/app/list-clients.test.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ function setup() {
66
const clients: Client[] = [
77
{
88
clientId: 'test_client_id',
9-
name: 'test_client_name',
10-
meshMailboxId: 'test_client_mesh_mailbox_id',
11-
meshWorkflowIdSuffix: 'test_client_mesh_workflow_id_suffix',
12-
senderOdsCode: 'test_ods_code',
9+
clientName: 'test_client_name',
10+
meshMailboxSenderId: 'test_client_mesh_mailbox_sender_id',
11+
meshMailboxReportsId: 'test_client_mesh_mailbox_reports_id',
12+
fallbackWaitTimeSeconds: 300,
13+
routingConfigId: '1234',
1314
},
1415
];
1516

utils/client-management/src/__test__/app/put-client.test.ts

Lines changed: 71 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -2,39 +2,37 @@ import { mockDeep } from 'jest-mock-extended';
22
import { Client } from 'utils';
33
import { PutClientCommandParameters } from '../../app/put-client';
44
import { AppDependencies, createApp } from '../../app';
5+
import { ConflictException, ValidationException } from 'domain/exceptions/';
6+
7+
const input: PutClientCommandParameters = {
8+
clientId: 'test_client_id',
9+
clientName: 'test_client_name',
10+
meshMailboxSenderId: 'test_client_mesh_mailbox_id',
11+
meshMailboxReportsId: 'test_client_mesh_workflow_id_suffix',
12+
fallbackWaitTimeSeconds: 300,
13+
routingConfigId: '1234',
14+
};
515

6-
function setup(clientSpec: 'min' | 'max') {
7-
const minimumClient: Client = {
8-
clientId: 'test_client_id',
9-
name: 'test_client_name',
10-
meshMailboxId: 'test_client_mesh_mailbox_id',
11-
meshWorkflowIdSuffix: 'test_client_mesh_workflow_id_suffix',
12-
allowOdsOverride: true,
13-
};
14-
15-
const maximumClient: Client = {
16+
const client: Client = {
1617
clientId: 'test_client_id',
17-
name: 'test_client_name',
18-
meshMailboxId: 'test_client_mesh_mailbox_id',
19-
meshWorkflowIdSuffix: 'test_client_mesh_workflow_id_suffix',
20-
meshWorkflowIdReceiveRequestAck:
21-
'test_client_mesh_workflow_id_receive_request_ack',
22-
meshWorkflowIdCompletedRequestItemsReport:
23-
'test_client_mesh_workflow_id_completed_items_report',
24-
senderOdsCode: 'A12345',
25-
allowAlternativeContactDetails: true,
26-
unprefixedName: true,
27-
allowAnonymousPatient: true,
28-
ignoreSecurityFlag: true,
29-
allowRfrOverride: true,
18+
clientName: 'test_client_name',
19+
meshMailboxSenderId: 'test_client_mesh_mailbox_id',
20+
meshMailboxReportsId: 'test_client_mesh_workflow_id_suffix',
21+
fallbackWaitTimeSeconds: 300,
22+
routingConfigId: '1234',
3023
};
3124

32-
const client = clientSpec === 'min' ? minimumClient : maximumClient;
33-
25+
function setup(existingClients: Client[] = [], createClientResponse = client) {
3426
const mocks = mockDeep<AppDependencies>({
3527
domain: {
3628
client: {
37-
createClient: jest.fn(() => client),
29+
createClient: jest.fn(() => createClientResponse),
30+
},
31+
},
32+
infra: {
33+
clientRepository: {
34+
putClient: jest.fn(),
35+
listClients: jest.fn().mockResolvedValue(existingClients),
3836
},
3937
},
4038
});
@@ -43,18 +41,11 @@ function setup(clientSpec: 'min' | 'max') {
4341
}
4442

4543
describe('putClient', () => {
46-
it('creates a new client with minimum data, stores it in the client repository and returns it', async () => {
47-
const { data, mocks } = setup('min');
44+
it('creates a new client when not existing clients, stores it in the client repository and returns it', async () => {
45+
const { data, mocks } = setup([]);
4846

4947
const app = createApp(mocks);
50-
51-
const input: PutClientCommandParameters = {
52-
clientId: 'input_client_id',
53-
name: 'input_client_name',
54-
meshMailboxId: 'input_client_mesh_mailbox_id',
55-
senderOdsCode: 'A12345',
56-
};
57-
48+
delete(input.clientId); // simulate no clientId provided
5849
const result = await app.putClient(input);
5950

6051
expect(mocks.domain.client.createClient).toHaveBeenCalledWith(input);
@@ -64,24 +55,16 @@ describe('putClient', () => {
6455
expect(result).toBe(data.client);
6556
});
6657

67-
it('creates a new client with maximum data, stores it in the client repository and returns it', async () => {
68-
const { data, mocks } = setup('max');
58+
it('creates a new client when existing clients, stores it in the client repository and returns it', async () => {
59+
const existingClient: Client = {
60+
...client,
61+
clientId: "existing_client_id",
62+
meshMailboxSenderId: "existing_mesh_mailbox_sender_id",
63+
};
64+
const { data, mocks } = setup([existingClient]);
6965

7066
const app = createApp(mocks);
7167

72-
const input: PutClientCommandParameters = {
73-
clientId: 'input_client_id',
74-
name: 'input_client_name',
75-
meshMailboxId: 'input_client_mesh_mailbox_id',
76-
senderOdsCode: 'A12345',
77-
allowOdsOverride: true,
78-
allowAlternativeContactDetails: true,
79-
unprefixedName: true,
80-
allowAnonymousPatient: true,
81-
ignoreSecurityFlag: true,
82-
allowRfrOverride: true,
83-
};
84-
8568
const result = await app.putClient(input);
8669

8770
expect(mocks.domain.client.createClient).toHaveBeenCalledWith(input);
@@ -91,24 +74,15 @@ describe('putClient', () => {
9174
expect(result).toBe(data.client);
9275
});
9376

94-
it('Accepts a client that has a 3 character valid ODS code', async () => {
95-
const { data, mocks } = setup('max');
77+
it('Updates client when it exists, stores it in the client repository and returns it', async () => {
78+
const existingClient: Client = {
79+
...client,
80+
meshMailboxSenderId: "existing_mesh_mailbox_sender_id",
81+
};
82+
const { data, mocks } = setup([existingClient]);
9683

9784
const app = createApp(mocks);
9885

99-
const input: PutClientCommandParameters = {
100-
clientId: 'input_client_id',
101-
name: 'input_client_name',
102-
meshMailboxId: 'input_client_mesh_mailbox_id',
103-
senderOdsCode: 'AB1',
104-
allowOdsOverride: true,
105-
allowAlternativeContactDetails: true,
106-
unprefixedName: true,
107-
allowAnonymousPatient: true,
108-
ignoreSecurityFlag: true,
109-
allowRfrOverride: true,
110-
};
111-
11286
const result = await app.putClient(input);
11387

11488
expect(mocks.domain.client.createClient).toHaveBeenCalledWith(input);
@@ -117,4 +91,35 @@ describe('putClient', () => {
11791
);
11892
expect(result).toBe(data.client);
11993
});
94+
95+
it('throws an error when a different existing client has the same mailbox sender ID', async () => {
96+
const existingClient: Client = {
97+
...client,
98+
clientId: "existing_client_id",
99+
};
100+
const { mocks } = setup([existingClient]);
101+
102+
const app = createApp(mocks);
103+
104+
await expect(app.putClient(input)).rejects.toThrow(ConflictException);
105+
106+
expect(mocks.domain.client.createClient).toHaveBeenCalledWith(input);
107+
expect(mocks.infra.clientRepository.putClient).toHaveBeenCalledTimes(0);
108+
});
109+
110+
it('throws an error when the incoming client is not valid', async () => {
111+
const newInvalidClient: Client = {
112+
...client,
113+
};
114+
delete (newInvalidClient.meshMailboxSenderId);
115+
116+
const { mocks } = setup([], newInvalidClient);
117+
118+
const app = createApp(mocks);
119+
120+
await expect(app.putClient(newInvalidClient)).rejects.toThrow(ValidationException);
121+
122+
expect(mocks.domain.client.createClient).toHaveBeenCalledWith(newInvalidClient);
123+
expect(mocks.infra.clientRepository.putClient).toHaveBeenCalledTimes(0);
124+
});
120125
});

utils/client-management/src/__test__/domain/client.test.ts

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,38 +9,21 @@ jest.mock('node:crypto', () => ({
99
describe('createClient', () => {
1010
it('creates a client entity with maximum fields', () => {
1111
const input: CreateClientParameters = {
12-
clientId: 'input_client_id',
13-
name: 'input_client_name',
14-
meshMailboxId: 'input_mesh_mailbox_id',
15-
allowOdsOverride: true,
16-
senderOdsCode: 'input_client_ods_code',
17-
allowAlternativeContactDetails: true,
18-
allowRfrOverride: true,
12+
clientId: 'test_client_id',
13+
clientName: 'test_client_name',
14+
meshMailboxSenderId: 'test_client_mesh_mailbox_sender_id',
15+
meshMailboxReportsId: 'test_client_mesh_mailbox_reports_id',
16+
fallbackWaitTimeSeconds: 300,
17+
routingConfigId: '1234',
1918
};
2019

2120
expect(createClient(input)).toEqual({
2221
clientId: input.clientId,
23-
name: input.name,
24-
meshMailboxId: input.meshMailboxId,
25-
allowOdsOverride: input.allowOdsOverride,
26-
senderOdsCode: input.senderOdsCode,
27-
allowAlternativeContactDetails: input.allowAlternativeContactDetails,
28-
allowRfrOverride: input.allowRfrOverride,
29-
});
30-
});
31-
32-
it('creates a client entity with minimum fields', () => {
33-
const input: CreateClientParameters = {
34-
name: 'input_client_name',
35-
meshMailboxId: 'input_mesh_mailbox_id',
36-
senderOdsCode: 'test_ods_code',
37-
};
38-
39-
expect(createClient(input)).toEqual({
40-
clientId: mockRandomUUID,
41-
name: input.name,
42-
meshMailboxId: input.meshMailboxId,
43-
senderOdsCode: 'test_ods_code',
22+
clientName: input.clientName,
23+
meshMailboxSenderId: input.meshMailboxSenderId,
24+
meshMailboxReportsId: input.meshMailboxReportsId,
25+
fallbackWaitTimeSeconds: input.fallbackWaitTimeSeconds,
26+
routingConfigId: input.routingConfigId,
4427
});
4528
});
4629
});

0 commit comments

Comments
 (0)