Skip to content

Commit 4fee6c9

Browse files
CCM-13135: Add tests
1 parent bdf2296 commit 4fee6c9

File tree

4 files changed

+136
-26
lines changed

4 files changed

+136
-26
lines changed

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

Lines changed: 27 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,26 @@
11
import { mockDeep } from 'jest-mock-extended';
22
import { Client } from 'utils';
3+
import { ConflictException, ValidationException } from 'domain/exceptions/';
34
import { PutClientCommandParameters } from '../../app/put-client';
45
import { AppDependencies, createApp } from '../../app';
5-
import { ConflictException, ValidationException } from 'domain/exceptions/';
66

77
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-
};
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+
};
1515

1616
const client: Client = {
17-
clientId: 'test_client_id',
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',
23-
};
17+
clientId: 'test_client_id',
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',
23+
};
2424

2525
function setup(existingClients: Client[] = [], createClientResponse = client) {
2626
const mocks = mockDeep<AppDependencies>({
@@ -45,7 +45,7 @@ describe('putClient', () => {
4545
const { data, mocks } = setup([]);
4646

4747
const app = createApp(mocks);
48-
delete(input.clientId); // simulate no clientId provided
48+
delete input.clientId; // simulate no clientId provided
4949
const result = await app.putClient(input);
5050

5151
expect(mocks.domain.client.createClient).toHaveBeenCalledWith(input);
@@ -58,8 +58,8 @@ describe('putClient', () => {
5858
it('creates a new client when existing clients, stores it in the client repository and returns it', async () => {
5959
const existingClient: Client = {
6060
...client,
61-
clientId: "existing_client_id",
62-
meshMailboxSenderId: "existing_mesh_mailbox_sender_id",
61+
clientId: 'existing_client_id',
62+
meshMailboxSenderId: 'existing_mesh_mailbox_sender_id',
6363
};
6464
const { data, mocks } = setup([existingClient]);
6565

@@ -77,7 +77,7 @@ describe('putClient', () => {
7777
it('Updates client when it exists, stores it in the client repository and returns it', async () => {
7878
const existingClient: Client = {
7979
...client,
80-
meshMailboxSenderId: "existing_mesh_mailbox_sender_id",
80+
meshMailboxSenderId: 'existing_mesh_mailbox_sender_id',
8181
};
8282
const { data, mocks } = setup([existingClient]);
8383

@@ -95,7 +95,7 @@ describe('putClient', () => {
9595
it('throws an error when a different existing client has the same mailbox sender ID', async () => {
9696
const existingClient: Client = {
9797
...client,
98-
clientId: "existing_client_id",
98+
clientId: 'existing_client_id',
9999
};
100100
const { mocks } = setup([existingClient]);
101101

@@ -111,15 +111,19 @@ describe('putClient', () => {
111111
const newInvalidClient: Client = {
112112
...client,
113113
};
114-
delete (newInvalidClient.meshMailboxSenderId);
114+
delete (newInvalidClient as Partial<Client>).meshMailboxSenderId;
115115

116116
const { mocks } = setup([], newInvalidClient);
117117

118118
const app = createApp(mocks);
119119

120-
await expect(app.putClient(newInvalidClient)).rejects.toThrow(ValidationException);
120+
await expect(app.putClient(newInvalidClient)).rejects.toThrow(
121+
ValidationException,
122+
);
121123

122-
expect(mocks.domain.client.createClient).toHaveBeenCalledWith(newInvalidClient);
124+
expect(mocks.domain.client.createClient).toHaveBeenCalledWith(
125+
newInvalidClient,
126+
);
123127
expect(mocks.infra.clientRepository.putClient).toHaveBeenCalledTimes(0);
124128
});
125129
});

utils/client-management/src/__test__/infra/client-repository/ssm.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { Parameter, ParameterNotFound } from '@aws-sdk/client-ssm';
22
import { Client, IParameterStore } from 'utils';
33
import { mockDeep } from 'jest-mock-extended';
4-
import { ConflictException } from '../../../domain/exceptions';
54
import { ClientRepository } from '../../../infra/client-repository/repository';
65

76
// update name repository.test.ts

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@ import { AppDependencies } from './types';
55

66
export type PutClientCommandParameters = CreateClientParameters;
77

8-
export async function validateClient(client: Client, infra: AppDependencies['infra']): Promise<void> {
8+
export async function validateClient(
9+
client: Client,
10+
infra: AppDependencies['infra'],
11+
): Promise<void> {
912
try {
1013
$Client.parse(client);
1114
} catch (error) {
@@ -15,7 +18,10 @@ export async function validateClient(client: Client, infra: AppDependencies['inf
1518
const existingClients = await infra.clientRepository.listClients();
1619

1720
const conflicts = existingClients.filter((c) => {
18-
return c.clientId !== client.clientId && c.meshMailboxSenderId === client.meshMailboxSenderId;
21+
return (
22+
c.clientId !== client.clientId &&
23+
c.meshMailboxSenderId === client.meshMailboxSenderId
24+
);
1925
});
2026

2127
if (conflicts.length > 0) {
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
import { $Client } from "validators";
2+
3+
describe("Client Validator", () => {
4+
it("should validate a correct Client object", () => {
5+
const validClient = {
6+
clientId: "123e4567-e89b-12d3-a456-426614174000",
7+
clientName: "Test Client",
8+
meshMailboxSenderId: "SENDER123",
9+
meshMailboxReportsId: "REPORTS123",
10+
fallbackWaitTimeSeconds: 300,
11+
routingConfigId: "ROUTE123",
12+
};
13+
14+
expect(() => $Client.parse(validClient)).not.toThrow();
15+
});
16+
17+
it("should throw an error when clientId is missing", () => {
18+
const invalidClient = {
19+
clientName: "Test Client",
20+
meshMailboxSenderId: "SENDER123",
21+
meshMailboxReportsId: "REPORTS123",
22+
fallbackWaitTimeSeconds: 300,
23+
routingConfigId: "ROUTE123",
24+
};
25+
26+
expect(() => $Client.parse(invalidClient)).toThrow();
27+
});
28+
29+
it("should throw an error when clientName is missing", () => {
30+
const invalidClient = {
31+
clientId: "123e4567-e89b-12d3-a456-426614174000",
32+
meshMailboxSenderId: "SENDER123",
33+
meshMailboxReportsId: "REPORTS123",
34+
fallbackWaitTimeSeconds: 300,
35+
routingConfigId: "ROUTE123",
36+
};
37+
38+
expect(() => $Client.parse(invalidClient)).toThrow();
39+
});
40+
41+
it("should throw an error when meshMailboxSenderId is missing", () => {
42+
const invalidClient = {
43+
clientId: "123e4567-e89b-12d3-a456-426614174000",
44+
clientName: "Test Client",
45+
meshMailboxReportsId: "REPORTS123",
46+
fallbackWaitTimeSeconds: 300,
47+
routingConfigId: "ROUTE123",
48+
};
49+
50+
expect(() => $Client.parse(invalidClient)).toThrow();
51+
});
52+
53+
it("should throw an error when meshMailboxReportsId is missing", () => {
54+
const invalidClient = {
55+
clientId: "123e4567-e89b-12d3-a456-426614174000",
56+
clientName: "Test Client",
57+
meshMailboxSenderId: "SENDER123",
58+
fallbackWaitTimeSeconds: 300,
59+
routingConfigId: "ROUTE123",
60+
};
61+
62+
expect(() => $Client.parse(invalidClient)).toThrow();
63+
});
64+
65+
it("should throw an error when fallbackWaitTimeSeconds is missing", () => {
66+
const invalidClient = {
67+
clientId: "123e4567-e89b-12d3-a456-426614174000",
68+
clientName: "Test Client",
69+
meshMailboxSenderId: "SENDER123",
70+
meshMailboxReportsId: "REPORTS123",
71+
routingConfigId: "ROUTE123",
72+
};
73+
74+
expect(() => $Client.parse(invalidClient)).toThrow();
75+
});
76+
77+
it("should throw an error when routingConfigId is missing", () => {
78+
const invalidClient = {
79+
clientId: "123e4567-e89b-12d3-a456-426614174000",
80+
clientName: "Test Client",
81+
meshMailboxSenderId: "SENDER123",
82+
meshMailboxReportsId: "REPORTS123",
83+
fallbackWaitTimeSeconds: 300,
84+
};
85+
86+
expect(() => $Client.parse(invalidClient)).toThrow();
87+
});
88+
89+
it("should throw an error when fallbackWaitTimeSeconds has wrong type", () => {
90+
const invalidClient = {
91+
clientId: "123e4567-e89b-12d3-a456-426614174000",
92+
clientName: "Test Client",
93+
meshMailboxSenderId: "SENDER123",
94+
meshMailboxReportsId: "REPORTS123",
95+
fallbackWaitTimeSeconds: "300",
96+
routingConfigId: "ROUTE123",
97+
};
98+
99+
expect(() => $Client.parse(invalidClient)).toThrow();
100+
});
101+
});

0 commit comments

Comments
 (0)