Skip to content

Commit 91f1966

Browse files
CCM-12120: Remove references to campaignId in client config (#729)
1 parent 9f0333f commit 91f1966

File tree

14 files changed

+24
-295
lines changed

14 files changed

+24
-295
lines changed

frontend/src/__tests__/app/upload-letter-template/__snapshots__/page.test.tsx.snap

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,5 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3-
exports[`UploadLetterTemplatePage should render UploadLetterTemplatePage with campaignId field when campaignIds is not available 1`] = `
4-
<LetterTemplateForm
5-
campaignIds={
6-
[
7-
"campaign-id",
8-
]
9-
}
10-
initialState={
11-
{
12-
"campaignId": "campaign-id",
13-
"language": "en",
14-
"letterType": "x0",
15-
"name": "",
16-
"templateType": "LETTER",
17-
}
18-
}
19-
/>
20-
`;
21-
223
exports[`UploadLetterTemplatePage should render UploadLetterTemplatePage with campaignIds field when available 1`] = `
234
<LetterTemplateForm
245
campaignIds={

frontend/src/__tests__/app/upload-letter-template/page.test.tsx

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe('UploadLetterTemplatePage', () => {
3030
});
3131
mockFetchClient.mockResolvedValueOnce({
3232
data: {
33-
campaignId: 'campaign2',
33+
campaignIds: ['campaign2'],
3434
features: {},
3535
},
3636
});
@@ -49,26 +49,6 @@ describe('UploadLetterTemplatePage', () => {
4949
mockFetchClient.mockResolvedValueOnce({
5050
data: {
5151
campaignIds: ['campaign-id', 'other-campaign-id'],
52-
campaignId: 'campaign-id',
53-
features: {},
54-
},
55-
});
56-
57-
const page = await UploadLetterTemplatePage();
58-
59-
expect(await generateMetadata()).toEqual({ title: pageTitle });
60-
expect(page).toMatchSnapshot();
61-
});
62-
63-
it('should render UploadLetterTemplatePage with campaignId field when campaignIds is not available', async () => {
64-
mockGetSessionServer.mockResolvedValueOnce({
65-
accessToken: 'mocktoken',
66-
clientId: 'client1',
67-
});
68-
mockFetchClient.mockResolvedValueOnce({
69-
data: {
70-
campaignIds: undefined,
71-
campaignId: 'campaign-id',
7252
features: {},
7353
},
7454
});
@@ -107,7 +87,7 @@ describe('UploadLetterTemplatePage', () => {
10787
});
10888
mockFetchClient.mockResolvedValueOnce({
10989
data: {
110-
campaignId: 'campaign2',
90+
campaignIds: ['campaign2'],
11191
features: {},
11292
},
11393
});
@@ -130,7 +110,6 @@ describe('UploadLetterTemplatePage', () => {
130110
mockFetchClient.mockResolvedValueOnce({
131111
data: {
132112
campaignIds: [],
133-
campaignId: 'campaign-id',
134113
features: {},
135114
},
136115
});
@@ -143,7 +122,7 @@ describe('UploadLetterTemplatePage', () => {
143122
);
144123
});
145124

146-
it('should redirect to error page when neither campaignIds nor campaignId is present', async () => {
125+
it('should redirect to error page when neither campaignIds are not present', async () => {
147126
const mockRedirect = jest.mocked(redirect);
148127

149128
mockGetSessionServer.mockResolvedValueOnce({
@@ -153,7 +132,6 @@ describe('UploadLetterTemplatePage', () => {
153132
mockFetchClient.mockResolvedValueOnce({
154133
data: {
155134
campaignIds: undefined,
156-
campaignId: undefined,
157135
features: {},
158136
},
159137
});

frontend/src/app/upload-letter-template/page.tsx

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,9 @@ const getSortedCampaignIds = (
2222
return;
2323
}
2424

25-
const { campaignIds, campaignId } = clientConfiguration;
25+
const { campaignIds = [] } = clientConfiguration;
2626

27-
if (campaignIds) {
28-
return campaignIds.sort();
29-
}
30-
31-
if (campaignId) {
32-
return [campaignId];
33-
}
27+
return campaignIds.sort();
3428
};
3529

3630
const UploadLetterTemplatePage = async () => {

infrastructure/terraform/modules/backend-api/spec.tmpl.json

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -296,10 +296,6 @@
296296
},
297297
"ClientConfiguration": {
298298
"properties": {
299-
"campaignId": {
300-
"deprecated": true,
301-
"type": "string"
302-
},
303299
"campaignIds": {
304300
"items": {
305301
"type": "string"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ describe('Template API - get client configuration', () => {
8686

8787
const clientConfiguration: ClientConfiguration = {
8888
features: { proofing: false },
89-
campaignId: 'campaign',
89+
campaignIds: ['campaign'],
9090
};
9191

9292
mocks.templateClient.getClientConfiguration.mockResolvedValueOnce({

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

Lines changed: 11 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -98,33 +98,18 @@ describe('templateClient', () => {
9898
{
9999
features: {},
100100
campaignIds: ['pea-campaign'],
101-
campaignId: 'bean-campaign',
102101
},
103102
'bean-campaign'
104103
)
105104
).toEqual(false);
106105
});
107106

108-
test('campaignIds list not present and campaign ID matches fallback campaign ID', () => {
107+
test('campaignIds not present', () => {
109108
const { templateClient } = setup();
110109
expect(
111110
templateClient.isCampaignIdValid(
112111
{
113112
features: {},
114-
campaignId: 'bean-campaign',
115-
},
116-
'bean-campaign'
117-
)
118-
).toEqual(true);
119-
});
120-
121-
test('campaign ID does not match config', () => {
122-
const { templateClient } = setup();
123-
expect(
124-
templateClient.isCampaignIdValid(
125-
{
126-
features: {},
127-
campaignId: 'pea-campaign',
128113
},
129114
'bean-campaign'
130115
)
@@ -191,34 +176,6 @@ describe('templateClient', () => {
191176
});
192177
});
193178

194-
test('should return a failure result when client configuration unexpectedly cant be fetched', async () => {
195-
const { templateClient, mocks } = setup();
196-
197-
const data: CreateUpdateTemplate = {
198-
templateType: 'EMAIL',
199-
name: 'name',
200-
message: 'message',
201-
subject: 'subject',
202-
};
203-
204-
mocks.clientConfigRepository.get.mockResolvedValueOnce({
205-
error: { errorMeta: { code: 500, description: 'err' } },
206-
});
207-
208-
const result = await templateClient.createTemplate(data, user);
209-
210-
expect(mocks.templateRepository.create).not.toHaveBeenCalled();
211-
212-
expect(result).toEqual({
213-
error: {
214-
errorMeta: {
215-
code: 500,
216-
description: 'err',
217-
},
218-
},
219-
});
220-
});
221-
222179
test('should return a failure result, when saving to the database unexpectedly fails', async () => {
223180
const { templateClient, mocks } = setup();
224181

@@ -247,8 +204,7 @@ describe('templateClient', () => {
247204
expect(mocks.templateRepository.create).toHaveBeenCalledWith(
248205
data,
249206
user,
250-
'NOT_YET_SUBMITTED',
251-
undefined
207+
'NOT_YET_SUBMITTED'
252208
);
253209

254210
expect(result).toEqual({
@@ -298,8 +254,7 @@ describe('templateClient', () => {
298254
expect(mocks.templateRepository.create).toHaveBeenCalledWith(
299255
data,
300256
user,
301-
'NOT_YET_SUBMITTED',
302-
undefined
257+
'NOT_YET_SUBMITTED'
303258
);
304259

305260
expect(result).toEqual({
@@ -354,8 +309,7 @@ describe('templateClient', () => {
354309
expect(mocks.templateRepository.create).toHaveBeenCalledWith(
355310
data,
356311
user,
357-
'NOT_YET_SUBMITTED',
358-
undefined
312+
'NOT_YET_SUBMITTED'
359313
);
360314

361315
expect(result).toEqual({
@@ -1762,7 +1716,7 @@ describe('templateClient', () => {
17621716
const { templateClient, mocks, logMessages } = setup();
17631717

17641718
mocks.clientConfigRepository.get.mockResolvedValueOnce({
1765-
data: { features: { proofing: true }, campaignId: 'campaignId' },
1719+
data: { features: { proofing: true }, campaignIds: ['campaignId'] },
17661720
});
17671721

17681722
const actualError = new Error('from db');
@@ -1779,7 +1733,7 @@ describe('templateClient', () => {
17791733

17801734
mocks.clientConfigRepository.get.mockResolvedValueOnce({
17811735
data: {
1782-
campaignId: 'campaignId',
1736+
campaignIds: ['campaignId'],
17831737
features: {
17841738
proofing: true,
17851739
},
@@ -1840,7 +1794,7 @@ describe('templateClient', () => {
18401794

18411795
mocks.clientConfigRepository.get.mockResolvedValueOnce({
18421796
data: {
1843-
campaignId: 'campaignId',
1797+
campaignIds: ['campaignId'],
18441798
features: {
18451799
proofing: true,
18461800
},
@@ -1891,7 +1845,7 @@ describe('templateClient', () => {
18911845

18921846
mocks.clientConfigRepository.get.mockResolvedValueOnce({
18931847
data: {
1894-
campaignId: 'campaignId',
1848+
campaignIds: ['campaignId'],
18951849
features: {
18961850
proofing: true,
18971851
},
@@ -1959,7 +1913,7 @@ describe('templateClient', () => {
19591913

19601914
mocks.clientConfigRepository.get.mockResolvedValueOnce({
19611915
data: {
1962-
campaignId: 'campaign-id-from-ssm',
1916+
campaignIds: ['campaign-id-from-ssm'],
19631917
features: {
19641918
proofing: true,
19651919
},
@@ -2027,7 +1981,7 @@ describe('templateClient', () => {
20271981

20281982
mocks.clientConfigRepository.get.mockResolvedValueOnce({
20291983
data: {
2030-
campaignId: 'campaign-from-ssm',
1984+
campaignIds: ['campaign-from-ssm'],
20311985
features: {
20321986
proofing: true,
20331987
},
@@ -2179,7 +2133,7 @@ describe('templateClient', () => {
21792133

21802134
const client: ClientConfiguration = {
21812135
features: { proofing: true },
2182-
campaignId: 'campaign',
2136+
campaignIds: ['campaign'],
21832137
};
21842138

21852139
mocks.clientConfigRepository.get.mockResolvedValueOnce({ data: client });

lambdas/backend-api/src/__tests__/templates/infra/client-config-repository.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const mockClientId = 'test-client-123';
3030
const mockKey = `${mockSSMKeyPrefix}/${mockClientId}`;
3131

3232
const validClient: ClientConfiguration = {
33-
campaignId: 'campaign-123',
33+
campaignIds: ['campaign-123'],
3434
features: {
3535
proofing: true,
3636
},

lambdas/backend-api/src/templates/app/template-client.ts

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -62,26 +62,10 @@ export class TemplateClient {
6262
return validationResult;
6363
}
6464

65-
const clientConfigurationResult = await this.clientConfigRepository.get(
66-
user.clientId
67-
);
68-
69-
if (clientConfigurationResult.error) {
70-
log
71-
.child(clientConfigurationResult.error.errorMeta)
72-
.error(
73-
'Failed to fetch client configuration',
74-
clientConfigurationResult.error.actualError
75-
);
76-
77-
return clientConfigurationResult;
78-
}
79-
8065
const createResult = await this.templateRepository.create(
8166
validationResult.data,
8267
user,
83-
'NOT_YET_SUBMITTED',
84-
clientConfigurationResult.data?.campaignId
68+
'NOT_YET_SUBMITTED'
8569
);
8670

8771
if (createResult.error) {
@@ -539,13 +523,9 @@ export class TemplateClient {
539523
return false;
540524
}
541525

542-
const { campaignIds, campaignId } = clientConfiguration;
543-
544-
const validCampaignId = campaignIds?.includes(campaignIdFromRequest);
545-
const validFallbackCampaignId =
546-
!campaignIds && campaignIdFromRequest === campaignId;
526+
const { campaignIds = [] } = clientConfiguration;
547527

548-
return validCampaignId || validFallbackCampaignId;
528+
return campaignIds.includes(campaignIdFromRequest);
549529
}
550530

551531
async getClientConfiguration(

lambdas/backend-client/src/types/generated/types.gen.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,6 @@ export type Channel = 'EMAIL' | 'LETTER' | 'NHSAPP' | 'SMS';
7070
export type ChannelType = 'primary' | 'secondary';
7171

7272
export type ClientConfiguration = {
73-
/**
74-
* @deprecated
75-
*/
76-
campaignId?: string;
7773
campaignIds?: Array<string>;
7874
features: ClientFeatures;
7975
};

tests/accessibility/test-user-client.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export class TestUserClient {
3939
Name: `${this.clientSsmPathPrefix}/${clientId}`,
4040
Value: JSON.stringify({
4141
features: { proofing: true },
42-
campaignId: 'accessibility-test-campaign',
42+
campaignIds: ['accessibility-test-campaign'],
4343
} satisfies ClientConfiguration),
4444
Overwrite: true,
4545
Type: 'String',

0 commit comments

Comments
 (0)