Skip to content

Commit 43fa02e

Browse files
committed
use plain objects for api clients
1 parent 8f9e110 commit 43fa02e

File tree

7 files changed

+41
-109
lines changed

7 files changed

+41
-109
lines changed

lambdas/backend-api/src/__tests__/templates/domain/validate-letter-template-files.test.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import { TemplatePdf } from '@backend-api/templates/domain/template-pdf';
33
import { TestDataCsv } from '@backend-api/templates/domain/test-data-csv';
44
import { validateLetterTemplateFiles } from '@backend-api/templates/domain/validate-letter-template-files';
55

6+
jest.mock('nhs-notify-web-template-management-utils/logger');
7+
68
describe('pdf has no custom personalisation', () => {
79
test('returns true if pdf contains expected address lines', () => {
810
const pdf = mock<TemplatePdf>({

lambdas/backend-client/src/__tests__/client-configuration-api-client.test.ts

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import axios from 'axios';
2-
import { ClientConfigurationApiClient } from '../client-configuration-api-client';
2+
import { ClientConfigurationApiClient as client } from '../client-configuration-api-client';
33
import MockAdapter from 'axios-mock-adapter';
44

55
describe('ClientConfiguration', () => {
@@ -20,9 +20,7 @@ describe('ClientConfiguration', () => {
2020
},
2121
});
2222

23-
const apiClient = new ClientConfigurationApiClient();
24-
25-
const notifyClientConfig = await apiClient.fetch('token');
23+
const notifyClientConfig = await client.fetch('token');
2624

2725
expect(notifyClientConfig).toEqual({
2826
data: {
@@ -40,9 +38,7 @@ describe('ClientConfiguration', () => {
4038
technicalMessage: 'Client configuration is not available',
4139
});
4240

43-
const apiClient = new ClientConfigurationApiClient();
44-
45-
const notifyClientConfig = await apiClient.fetch('token');
41+
const notifyClientConfig = await client.fetch('token');
4642

4743
expect(notifyClientConfig).toEqual({
4844
data: null,
@@ -55,9 +51,7 @@ describe('ClientConfiguration', () => {
5551
technicalMessage: 'Invalid Request',
5652
});
5753

58-
const apiClient = new ClientConfigurationApiClient();
59-
60-
const notifyClientConfig = await apiClient.fetch('token');
54+
const notifyClientConfig = await client.fetch('token');
6155

6256
expect(notifyClientConfig).toEqual({
6357
error: {
@@ -80,9 +74,7 @@ describe('ClientConfiguration', () => {
8074
},
8175
},
8276
});
83-
const apiClient = new ClientConfigurationApiClient();
84-
85-
const notifyClientConfig = await apiClient.fetch('token');
77+
const notifyClientConfig = await client.fetch('token');
8678

8779
expect(notifyClientConfig).toEqual({
8880
error: {

lambdas/backend-client/src/__tests__/routing-config-api-client.test.ts

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
import axios from 'axios';
2-
import {
3-
RoutingConfigurationApiClient,
4-
routingConfigurationApiClient,
5-
} from '../routing-config-api-client';
2+
import { routingConfigurationApiClient as client } from '../routing-config-api-client';
63
import MockAdapter from 'axios-mock-adapter';
74

85
describe('RoutingConfigurationApiClient', () => {
@@ -12,10 +9,6 @@ describe('RoutingConfigurationApiClient', () => {
129
axiosMock.reset();
1310
});
1411

15-
it('should export client', () => {
16-
expect(routingConfigurationApiClient).not.toBeUndefined();
17-
});
18-
1912
describe('count', () => {
2013
it('should return error when failing to fetch from API', async () => {
2114
axiosMock
@@ -30,8 +23,6 @@ describe('RoutingConfigurationApiClient', () => {
3023
},
3124
});
3225

33-
const client = new RoutingConfigurationApiClient();
34-
3526
const response = await client.count('token', 'DRAFT');
3627

3728
expect(response.error).toEqual({
@@ -56,8 +47,6 @@ describe('RoutingConfigurationApiClient', () => {
5647
})
5748
.reply(200, { data: { count: 10 } });
5849

59-
const client = new RoutingConfigurationApiClient();
60-
6150
const response = await client.count('token', 'COMPLETED');
6251

6352
expect(response.data).toEqual({ count: 10 });
@@ -78,8 +67,6 @@ describe('RoutingConfigurationApiClient', () => {
7867
},
7968
});
8069

81-
const client = new RoutingConfigurationApiClient();
82-
8370
const response = await client.list('token');
8471

8572
expect(response.error).toEqual({
@@ -114,8 +101,6 @@ describe('RoutingConfigurationApiClient', () => {
114101
data: [data],
115102
});
116103

117-
const client = new RoutingConfigurationApiClient();
118-
119104
const response = await client.list('token');
120105

121106
expect(response.data).toEqual([data]);

lambdas/backend-client/src/__tests__/template-api-client.test.ts

Lines changed: 1 addition & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import axios from 'axios';
22
import MockAdapter from 'axios-mock-adapter';
3-
import { TemplateApiClient } from '../template-api-client';
3+
import { templateApiClient as client } from '../template-api-client';
44

55
const axiosMock = new MockAdapter(axios);
66

@@ -20,8 +20,6 @@ describe('TemplateAPIClient', () => {
2020
},
2121
});
2222

23-
const client = new TemplateApiClient();
24-
2523
const result = await client.createTemplate(
2624
{
2725
name: 'test',
@@ -57,8 +55,6 @@ describe('TemplateAPIClient', () => {
5755
},
5856
});
5957

60-
const client = new TemplateApiClient();
61-
6258
const result = await client.createTemplate(
6359
{
6460
name: 'name',
@@ -87,8 +83,6 @@ describe('TemplateAPIClient', () => {
8783
},
8884
});
8985

90-
const client = new TemplateApiClient();
91-
9286
const result = await client.uploadLetterTemplate(
9387
{
9488
name: 'test',
@@ -140,8 +134,6 @@ describe('TemplateAPIClient', () => {
140134
},
141135
});
142136

143-
const client = new TemplateApiClient();
144-
145137
const result = await client.uploadLetterTemplate(
146138
{
147139
name: 'test',
@@ -187,8 +179,6 @@ describe('TemplateAPIClient', () => {
187179
},
188180
});
189181

190-
const client = new TemplateApiClient();
191-
192182
const result = await client.updateTemplate(
193183
'real-id',
194184
{
@@ -228,8 +218,6 @@ describe('TemplateAPIClient', () => {
228218
data,
229219
});
230220

231-
const client = new TemplateApiClient();
232-
233221
const result = await client.updateTemplate(
234222
'real-id',
235223
{
@@ -254,8 +242,6 @@ describe('TemplateAPIClient', () => {
254242
},
255243
});
256244

257-
const client = new TemplateApiClient();
258-
259245
const result = await client.getTemplate('real-id', testToken);
260246

261247
expect(result.error).toEqual({
@@ -287,8 +273,6 @@ describe('TemplateAPIClient', () => {
287273
data,
288274
});
289275

290-
const client = new TemplateApiClient();
291-
292276
const result = await client.getTemplate('real-id', testToken);
293277

294278
expect(result.data).toEqual(data);
@@ -302,8 +286,6 @@ describe('TemplateAPIClient', () => {
302286
technicalMessage: 'Internal server error',
303287
});
304288

305-
const client = new TemplateApiClient();
306-
307289
const result = await client.listTemplates(testToken);
308290

309291
expect(result.error).toEqual({
@@ -332,8 +314,6 @@ describe('TemplateAPIClient', () => {
332314
data: [data],
333315
});
334316

335-
const client = new TemplateApiClient();
336-
337317
const result = await client.listTemplates(testToken);
338318

339319
expect(result.data).toEqual([data]);
@@ -351,8 +331,6 @@ describe('TemplateAPIClient', () => {
351331
},
352332
});
353333

354-
const client = new TemplateApiClient();
355-
356334
const result = await client.submitTemplate('real-id', testToken);
357335

358336
expect(result.error).toEqual({
@@ -384,8 +362,6 @@ describe('TemplateAPIClient', () => {
384362
data,
385363
});
386364

387-
const client = new TemplateApiClient();
388-
389365
const result = await client.submitTemplate('real-id', testToken);
390366

391367
expect(result.data).toEqual(data);
@@ -404,8 +380,6 @@ describe('TemplateAPIClient', () => {
404380
},
405381
});
406382

407-
const client = new TemplateApiClient();
408-
409383
const result = await client.deleteTemplate('real-id', testToken);
410384

411385
expect(result.error).toEqual({
@@ -426,8 +400,6 @@ describe('TemplateAPIClient', () => {
426400
test('should return no content', async () => {
427401
axiosMock.onDelete('/v1/template/real-id').reply(204);
428402

429-
const client = new TemplateApiClient();
430-
431403
const result = await client.deleteTemplate('real-id', testToken);
432404

433405
expect(result.data).toBeUndefined();
@@ -446,8 +418,6 @@ describe('TemplateAPIClient', () => {
446418
},
447419
});
448420

449-
const client = new TemplateApiClient();
450-
451421
const result = await client.requestProof('real-id', testToken);
452422

453423
expect(result.error).toEqual({
@@ -476,8 +446,6 @@ describe('TemplateAPIClient', () => {
476446

477447
axiosMock.onPost('/v1/template/real-id/proof').reply(204, { data });
478448

479-
const client = new TemplateApiClient();
480-
481449
const result = await client.requestProof('real-id', testToken);
482450

483451
expect(result.data).toEqual(data);

lambdas/backend-client/src/client-configuration-api-client.ts

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ import { catchAxiosError, createAxiosClient } from './axios-client';
44
import { Result } from './types/result';
55
import { ErrorCase } from './types/error-cases';
66

7-
export class ClientConfigurationApiClient {
8-
private readonly httpClient = createAxiosClient();
7+
const httpClient = createAxiosClient();
98

9+
export const clientConfigurationApiClient = {
1010
async fetch(token: string): Promise<Result<ClientConfiguration | null>> {
1111
const response = await catchAxiosError(
12-
this.httpClient.get<{ clientConfiguration: ClientConfiguration }>(
12+
httpClient.get<{ clientConfiguration: ClientConfiguration }>(
1313
`/v1/client-configuration`,
1414
{
1515
headers: { Authorization: token },
@@ -42,7 +42,5 @@ export class ClientConfigurationApiClient {
4242
}
4343

4444
return { data: parseResult.data };
45-
}
46-
}
47-
48-
export const clientConfigurationApiClient = new ClientConfigurationApiClient();
45+
},
46+
};

lambdas/backend-client/src/routing-config-api-client.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ import type {
99
import { catchAxiosError, createAxiosClient } from './axios-client';
1010
import { Result } from './types/result';
1111

12-
export class RoutingConfigurationApiClient {
13-
private readonly httpClient = createAxiosClient();
12+
const httpClient = createAxiosClient();
1413

14+
export const routingConfigurationApiClient = {
1515
async count(
1616
token: string,
1717
status: RoutingConfigStatusActive
@@ -20,7 +20,7 @@ export class RoutingConfigurationApiClient {
2020
'/v1/routing-configurations/count' satisfies GetV1RoutingConfigurationsCountData['url'];
2121

2222
const { data, error } = await catchAxiosError(
23-
this.httpClient.get<CountSuccess>(url, {
23+
httpClient.get<CountSuccess>(url, {
2424
headers: { Authorization: token },
2525
params: { status },
2626
})
@@ -31,14 +31,14 @@ export class RoutingConfigurationApiClient {
3131
}
3232

3333
return { ...data };
34-
}
34+
},
3535

3636
async list(token: string): Promise<Result<RoutingConfig[]>> {
3737
const url =
3838
'/v1/routing-configurations' satisfies GetV1RoutingConfigurationsData['url'];
3939

4040
const { data, error } = await catchAxiosError(
41-
this.httpClient.get<RoutingConfigSuccessList>(url, {
41+
httpClient.get<RoutingConfigSuccessList>(url, {
4242
headers: { Authorization: token },
4343
})
4444
);
@@ -48,8 +48,5 @@ export class RoutingConfigurationApiClient {
4848
}
4949

5050
return { ...data };
51-
}
52-
}
53-
54-
export const routingConfigurationApiClient =
55-
new RoutingConfigurationApiClient();
51+
},
52+
};

0 commit comments

Comments
 (0)