Skip to content

Commit b1b39ab

Browse files
authored
CCM-10282: expanded template ID in SFTP (#556)
1 parent 7ff2f53 commit b1b39ab

File tree

53 files changed

+822
-401
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+822
-401
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
},
99
{
1010
"properties": {
11+
"campaignId": {
12+
"type": "string"
13+
},
1114
"clientId": {
1215
"type": "string"
1316
},

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

Lines changed: 45 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -145,16 +145,16 @@ describe('templateClient', () => {
145145

146146
const expectedTemplateDto: TemplateDto = {
147147
...data,
148-
id: templateId,
148+
campaignId: 'campaignId',
149149
createdAt: new Date().toISOString(),
150-
updatedAt: new Date().toISOString(),
150+
id: templateId,
151151
templateStatus: 'NOT_YET_SUBMITTED',
152+
updatedAt: new Date().toISOString(),
152153
};
153154

154155
const template: DatabaseTemplate = {
155156
...expectedTemplateDto,
156157
owner: user.userId,
157-
campaignId: 'campaignId',
158158
version: 1,
159159
};
160160

@@ -267,24 +267,24 @@ describe('templateClient', () => {
267267
const { templateClient, mocks } = setup();
268268

269269
const data: CreateUpdateTemplate = {
270-
templateType: 'EMAIL',
271-
name: 'name',
272270
message: 'message',
271+
name: 'name',
273272
subject: 'subject',
273+
templateType: 'EMAIL',
274274
};
275275

276276
const expectedTemplateDto: TemplateDto = {
277277
...data,
278-
id: templateId,
278+
campaignId: 'campaignId',
279279
createdAt: new Date().toISOString(),
280-
updatedAt: new Date().toISOString(),
280+
id: templateId,
281281
templateStatus: 'NOT_YET_SUBMITTED',
282+
updatedAt: new Date().toISOString(),
282283
};
283284

284285
const template: DatabaseTemplate = {
285286
...expectedTemplateDto,
286287
owner: user.userId,
287-
campaignId: 'campaignId',
288288
version: 1,
289289
};
290290

@@ -1569,7 +1569,7 @@ describe('templateClient', () => {
15691569
const { templateClient, mocks, logMessages } = setup();
15701570

15711571
mocks.clientConfigRepository.get.mockResolvedValueOnce({
1572-
data: { features: { proofing: true } },
1572+
data: { features: { proofing: true }, campaignId: 'campaignId' },
15731573
});
15741574

15751575
const actualError = new Error('from db');
@@ -1595,7 +1595,7 @@ describe('templateClient', () => {
15951595

15961596
expect(mocks.templateRepository.proofRequestUpdate).toHaveBeenCalledWith(
15971597
templateId,
1598-
user.userId
1598+
user
15991599
);
16001600

16011601
expect(result).toEqual({
@@ -1618,7 +1618,7 @@ describe('templateClient', () => {
16181618
});
16191619
});
16201620

1621-
test('should return a failure result, when updated database template is invalid', async () => {
1621+
test('should return a failure result, when updated database template is not suitable for proofing', async () => {
16221622
const { templateClient, mocks } = setup();
16231623

16241624
const expectedTemplateDto: TemplateDto = {
@@ -1654,7 +1654,7 @@ describe('templateClient', () => {
16541654

16551655
expect(mocks.templateRepository.proofRequestUpdate).toHaveBeenCalledWith(
16561656
templateId,
1657-
user.userId
1657+
user
16581658
);
16591659

16601660
expect(result).toEqual({
@@ -1703,7 +1703,7 @@ describe('templateClient', () => {
17031703

17041704
expect(mocks.templateRepository.proofRequestUpdate).toHaveBeenCalledWith(
17051705
templateId,
1706-
user.userId
1706+
user
17071707
);
17081708

17091709
expect(result).toEqual({
@@ -1721,22 +1721,23 @@ describe('templateClient', () => {
17211721
const personalisationParameters = ['myParam'];
17221722

17231723
const template: TemplateDto = {
1724-
name: templateName,
1725-
templateStatus: 'SUBMITTED',
1726-
templateType: 'LETTER',
1727-
id: templateId,
1724+
campaignId: 'campaign-id-from-template',
17281725
createdAt: new Date().toISOString(),
1729-
updatedAt: new Date().toISOString(),
1730-
personalisationParameters,
1731-
letterType: 'x1',
1732-
language: 'en',
17331726
files: {
17341727
pdfTemplate: {
17351728
virusScanStatus: 'PASSED',
17361729
currentVersion: pdfVersionId,
17371730
fileName: 'template.pdf',
17381731
},
17391732
},
1733+
id: templateId,
1734+
language: 'en',
1735+
letterType: 'x1',
1736+
name: templateName,
1737+
personalisationParameters,
1738+
templateStatus: 'SUBMITTED',
1739+
templateType: 'LETTER',
1740+
updatedAt: new Date().toISOString(),
17401741
};
17411742

17421743
mocks.templateRepository.proofRequestUpdate.mockResolvedValueOnce({
@@ -1755,7 +1756,7 @@ describe('templateClient', () => {
17551756

17561757
mocks.clientConfigRepository.get.mockResolvedValueOnce({
17571758
data: {
1758-
campaignId: 'campaignId',
1759+
campaignId: 'campaign-id-from-ssm',
17591760
features: {
17601761
proofing: true,
17611762
},
@@ -1766,15 +1767,18 @@ describe('templateClient', () => {
17661767

17671768
expect(mocks.templateRepository.proofRequestUpdate).toHaveBeenCalledWith(
17681769
templateId,
1769-
user.userId
1770+
user
17701771
);
17711772

17721773
expect(mocks.queueMock.send).toHaveBeenCalledTimes(1);
17731774
expect(mocks.queueMock.send).toHaveBeenCalledWith(
17741775
templateId,
17751776
templateName,
1776-
user.userId,
1777+
user,
1778+
'campaign-id-from-template',
17771779
personalisationParameters,
1780+
'x1',
1781+
'en',
17781782
pdfVersionId,
17791783
undefined,
17801784
defaultLetterSupplier
@@ -1794,7 +1798,7 @@ describe('templateClient', () => {
17941798

17951799
const result = await templateClient.requestProof(templateId, {
17961800
userId: user.userId,
1797-
clientId: undefined,
1801+
clientId: undefined as unknown as string,
17981802
});
17991803

18001804
expect(mocks.clientConfigRepository.get).not.toHaveBeenCalled();
@@ -1818,29 +1822,31 @@ describe('templateClient', () => {
18181822

18191823
const pdfVersionId = 'a';
18201824
const personalisationParameters = ['myParam'];
1825+
const campaignFromTemplate = 'campaign-from-template';
18211826

18221827
const template: TemplateDto = {
1823-
name: templateName,
1824-
templateStatus: 'SUBMITTED',
1825-
templateType: 'LETTER',
1826-
id: templateId,
1828+
campaignId: campaignFromTemplate,
18271829
createdAt: new Date().toISOString(),
1828-
updatedAt: new Date().toISOString(),
1829-
personalisationParameters,
1830-
letterType: 'x1',
1831-
language: 'en',
18321830
files: {
18331831
pdfTemplate: {
18341832
virusScanStatus: 'PASSED',
18351833
currentVersion: pdfVersionId,
18361834
fileName: 'template.pdf',
18371835
},
18381836
},
1837+
id: templateId,
1838+
language: 'en',
1839+
letterType: 'x1',
1840+
name: templateName,
1841+
personalisationParameters,
1842+
templateStatus: 'SUBMITTED',
1843+
templateType: 'LETTER',
1844+
updatedAt: new Date().toISOString(),
18391845
};
18401846

18411847
mocks.clientConfigRepository.get.mockResolvedValueOnce({
18421848
data: {
1843-
campaignId: 'campaignId',
1849+
campaignId: 'campaign-from-ssm',
18441850
features: {
18451851
proofing: true,
18461852
},
@@ -1857,15 +1863,18 @@ describe('templateClient', () => {
18571863

18581864
expect(mocks.templateRepository.proofRequestUpdate).toHaveBeenCalledWith(
18591865
templateId,
1860-
user.userId
1866+
user
18611867
);
18621868

18631869
expect(mocks.queueMock.send).toHaveBeenCalledTimes(1);
18641870
expect(mocks.queueMock.send).toHaveBeenCalledWith(
18651871
templateId,
18661872
templateName,
1867-
user.userId,
1873+
user,
1874+
campaignFromTemplate,
18681875
personalisationParameters,
1876+
'x1',
1877+
'en',
18691878
pdfVersionId,
18701879
undefined,
18711880
defaultLetterSupplier

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1490,28 +1490,30 @@ describe('templateRepository', () => {
14901490
});
14911491

14921492
const result = await templateRepository.proofRequestUpdate(
1493-
'template-owner',
1494-
'template-id'
1493+
'template-id',
1494+
{ userId: 'template-owner', clientId: 'client' }
14951495
);
14961496

14971497
expect(result).toEqual({ data: { id: 'template-id' } });
14981498

14991499
expect(mocks.ddbDocClient).toHaveReceivedCommandWith(UpdateCommand, {
15001500
ConditionExpression:
1501-
'#templateStatus = :condition_1_templateStatus AND #templateType = :condition_2_templateType AND attribute_exists (#id)',
1501+
'#templateStatus = :condition_1_templateStatus AND #templateType = :condition_2_templateType AND #clientId = :condition_3_clientId AND attribute_exists (#id)',
15021502
ExpressionAttributeNames: {
15031503
'#id': 'id',
1504+
'#clientId': 'clientId',
15041505
'#templateStatus': 'templateStatus',
15051506
'#templateType': 'templateType',
15061507
'#updatedAt': 'updatedAt',
15071508
},
15081509
ExpressionAttributeValues: {
15091510
':condition_1_templateStatus': 'PENDING_PROOF_REQUEST',
15101511
':condition_2_templateType': 'LETTER',
1512+
':condition_3_clientId': 'client',
15111513
':templateStatus': 'WAITING_FOR_PROOF',
15121514
':updatedAt': '2024-12-27T00:00:00.000Z',
15131515
},
1514-
Key: { id: 'template-owner', owner: 'template-id' },
1516+
Key: { id: 'template-id', owner: 'template-owner' },
15151517
ReturnValues: 'ALL_NEW',
15161518
ReturnValuesOnConditionCheckFailure: 'ALL_OLD',
15171519
TableName: 'templates',
@@ -1531,8 +1533,8 @@ describe('templateRepository', () => {
15311533
mocks.ddbDocClient.on(UpdateCommand).rejectsOnce(err);
15321534

15331535
const result = await templateRepository.proofRequestUpdate(
1534-
'template-owner',
1535-
'template-id'
1536+
'template-id',
1537+
{ userId: 'template-owner', clientId: 'client' }
15361538
);
15371539

15381540
expect(result).toEqual({
@@ -1558,8 +1560,8 @@ describe('templateRepository', () => {
15581560
mocks.ddbDocClient.on(UpdateCommand).rejectsOnce(err);
15591561

15601562
const result = await templateRepository.proofRequestUpdate(
1561-
'template-owner',
1562-
'template-id'
1563+
'template-id',
1564+
{ userId: 'template-owner', clientId: 'client' }
15631565
);
15641566

15651567
expect(result).toEqual({
@@ -1579,8 +1581,8 @@ describe('templateRepository', () => {
15791581
mocks.ddbDocClient.on(UpdateCommand).rejectsOnce(err);
15801582

15811583
const result = await templateRepository.proofRequestUpdate(
1582-
'template-owner',
1583-
'template-id'
1584+
'template-id',
1585+
{ userId: 'template-owner', clientId: 'client' }
15841586
);
15851587

15861588
expect(result).toEqual({

lambdas/backend-api/src/templates/api/proof.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ export function createHandler({
1212

1313
const templateId = event.pathParameters?.templateId;
1414

15-
if (!userId || !templateId) {
15+
if (!userId || !templateId || !clientId) {
1616
return apiFailure(400, 'Invalid request');
1717
}
1818

0 commit comments

Comments
 (0)