Skip to content

Commit 4621423

Browse files
committed
Merge branch 'main' into feature/CCM-11474_message-plan-name-screen
2 parents 333954f + 91f1966 commit 4621423

File tree

16 files changed

+26
-301
lines changed

16 files changed

+26
-301
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: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,6 @@ describe('UploadLetterTemplatePage', () => {
2323
it('should render UploadLetterTemplatePage with campaignIds field when available', async () => {
2424
mockFetchClient.mockResolvedValueOnce({
2525
campaignIds: ['campaign-id', 'other-campaign-id'],
26-
campaignId: 'campaign-id',
27-
features: {},
28-
});
29-
30-
const page = await UploadLetterTemplatePage();
31-
32-
expect(await generateMetadata()).toEqual({ title: pageTitle });
33-
expect(page).toMatchSnapshot();
34-
});
35-
36-
it('should render UploadLetterTemplatePage with campaignId field when campaignIds is not available', async () => {
37-
mockFetchClient.mockResolvedValueOnce({
38-
campaignIds: undefined,
39-
campaignId: 'campaign-id',
4026
features: {},
4127
});
4228

@@ -64,7 +50,6 @@ describe('UploadLetterTemplatePage', () => {
6450

6551
mockFetchClient.mockResolvedValueOnce({
6652
campaignIds: [],
67-
campaignId: 'campaign-id',
6853
features: {},
6954
});
7055

@@ -76,12 +61,11 @@ describe('UploadLetterTemplatePage', () => {
7661
);
7762
});
7863

79-
it('should redirect to error page when neither campaignIds nor campaignId is present', async () => {
64+
it('should redirect to error page when campaignIds are not present', async () => {
8065
const mockRedirect = jest.mocked(redirect);
8166

8267
mockFetchClient.mockResolvedValueOnce({
8368
campaignIds: undefined,
84-
campaignId: undefined,
8569
features: {},
8670
});
8771

frontend/src/__tests__/components/providers/client-config-provider-server.test.tsx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ const mockFetchClient = jest.mocked(fetchClient);
99
describe('ClientConfigProviderServer', () => {
1010
it('returns ClientConfigProvider with value set', async () => {
1111
mockFetchClient.mockResolvedValueOnce({
12-
campaignId: 'legacy-campaign-id',
1312
campaignIds: ['new-campaign-id'],
1413
features: { proofing: true, routing: true },
1514
});
@@ -19,7 +18,6 @@ describe('ClientConfigProviderServer', () => {
1918
expect(rendered.type).toBe(ClientConfigProvider);
2019

2120
expect(rendered.props.value).toEqual({
22-
campaignId: 'legacy-campaign-id',
2321
campaignIds: ['new-campaign-id'],
2422
features: { proofing: true, routing: true },
2523
});

frontend/src/__tests__/components/providers/client-config-provider.test.tsx

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ const renderProvider =
1919

2020
it('returns client config from context', () => {
2121
const config: ClientConfiguration = {
22-
campaignId: 'campaign-0',
2322
campaignIds: ['campaign-1', 'campaign-2'],
2423
features: { proofing: true, routing: false },
2524
};
@@ -32,9 +31,8 @@ it('returns client config from context', () => {
3231
});
3332

3433
describe('useCampaignIds', () => {
35-
it('returns a sorted list of all campaign ids (ignores deprecated)', () => {
34+
it('returns a sorted list of all campaign ids', () => {
3635
const config: ClientConfiguration = {
37-
campaignId: 'b',
3836
campaignIds: ['c', 'a'],
3937
features: {},
4038
};
@@ -46,9 +44,8 @@ describe('useCampaignIds', () => {
4644
expect(result.current).toEqual(['a', 'c']);
4745
});
4846

49-
it('returns a empty list of all campaign ids if present (ignores deprecated)', () => {
47+
it('returns an empty list of campaign ids if present', () => {
5048
const config: ClientConfiguration = {
51-
campaignId: 'b',
5249
campaignIds: [],
5350
features: {},
5451
};
@@ -60,17 +57,16 @@ describe('useCampaignIds', () => {
6057
expect(result.current).toEqual([]);
6158
});
6259

63-
it('returns a list of campaign ids (only legacy present)', () => {
60+
it('returns an empty list of campaign ids if not present', () => {
6461
const config: ClientConfiguration = {
65-
campaignId: 'campaign-0',
6662
features: {},
6763
};
6864

6965
const { result } = renderHook(useCampaignIds, {
7066
wrapper: renderProvider(config),
7167
});
7268

73-
expect(result.current).toEqual(['campaign-0']);
69+
expect(result.current).toEqual([]);
7470
});
7571

7672
it('removes duplicates', () => {

frontend/src/utils/client-config.ts

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,7 @@ export const initialFeatureFlags: ClientFeatures = Object.fromEntries(
77
) as ClientFeatures;
88

99
export const getCampaignIds = (client: ClientConfiguration | null) => {
10-
if (!client) return [];
10+
if (!client?.campaignIds) return [];
1111

12-
const { campaignIds, campaignId } = client;
13-
14-
if (campaignIds) {
15-
return [...new Set(campaignIds)].sort();
16-
}
17-
18-
if (campaignId) {
19-
return [campaignId];
20-
}
21-
22-
return [];
12+
return [...new Set(client.campaignIds)].sort();
2313
};

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

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,10 +297,6 @@
297297
},
298298
"ClientConfiguration": {
299299
"properties": {
300-
"campaignId": {
301-
"deprecated": true,
302-
"type": "string"
303-
},
304300
"campaignIds": {
305301
"items": {
306302
"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(

0 commit comments

Comments
 (0)