Skip to content

Commit 251efa6

Browse files
committed
CCM-10387: coverage
1 parent 813fc61 commit 251efa6

File tree

3 files changed

+143
-21
lines changed

3 files changed

+143
-21
lines changed

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

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1461,6 +1461,57 @@ describe('templateRepository', () => {
14611461
});
14621462
});
14631463

1464+
it('adds the virus scan status of the proof to the database record and updates the template status if scan status is passed, template is user-owned', async () => {
1465+
const { templateRepository, mocks } = setup();
1466+
mocks.ddbDocClient.on(UpdateCommand).resolves({
1467+
Attributes: {
1468+
templateStatus: 'WAITING_FOR_PROOF',
1469+
},
1470+
});
1471+
1472+
await templateRepository.setLetterFileVirusScanStatusForProof(
1473+
{ owner: userId, id: 'template-id', clientOwned: false },
1474+
'pdf-template.pdf',
1475+
'PASSED',
1476+
'MBA'
1477+
);
1478+
1479+
expect(mocks.ddbDocClient).toHaveReceivedCommandWith(UpdateCommand, {
1480+
TableName: 'templates',
1481+
Key: { id: 'template-id', owner: userId },
1482+
UpdateExpression:
1483+
'SET files.proofs.#fileName = :virusScanResult, updatedAt = :updatedAt',
1484+
ConditionExpression:
1485+
'attribute_not_exists(files.proofs.#fileName) and not templateStatus in (:templateStatusDeleted, :templateStatusSubmitted)',
1486+
ExpressionAttributeNames: {
1487+
'#fileName': 'pdf-template.pdf',
1488+
},
1489+
ExpressionAttributeValues: {
1490+
':templateStatusDeleted': 'DELETED',
1491+
':templateStatusSubmitted': 'SUBMITTED',
1492+
':updatedAt': new Date().toISOString(),
1493+
':virusScanResult': {
1494+
fileName: 'pdf-template.pdf',
1495+
virusScanStatus: 'PASSED',
1496+
supplier: 'MBA',
1497+
},
1498+
},
1499+
});
1500+
1501+
expect(mocks.ddbDocClient).toHaveReceivedCommandWith(UpdateCommand, {
1502+
TableName: 'templates',
1503+
Key: { id: 'template-id', owner: userId },
1504+
UpdateExpression:
1505+
'SET templateStatus = :templateStatusProofAvailable, updatedAt = :updatedAt',
1506+
ExpressionAttributeValues: {
1507+
':templateStatusWaitingForProof': 'WAITING_FOR_PROOF',
1508+
':templateStatusProofAvailable': 'PROOF_AVAILABLE',
1509+
':updatedAt': new Date().toISOString(),
1510+
},
1511+
ConditionExpression: 'templateStatus = :templateStatusWaitingForProof',
1512+
});
1513+
});
1514+
14641515
it('adds the virus scan status of the proof to the database record and does not update the template status if scan status is failed', async () => {
14651516
const { templateRepository, mocks } = setup();
14661517
mocks.ddbDocClient.on(UpdateCommand).resolves({
@@ -1589,6 +1640,22 @@ describe('templateRepository', () => {
15891640
it('gets owner', async () => {
15901641
const { templateRepository, mocks } = setup();
15911642

1643+
mocks.ddbDocClient.on(QueryCommand).resolves({
1644+
Items: [
1645+
{
1646+
owner: 'CLIENT#template-owner',
1647+
},
1648+
],
1649+
});
1650+
1651+
const owner = await templateRepository.getOwner('template-id');
1652+
1653+
expect(owner).toEqual({ owner: 'template-owner', clientOwned: true });
1654+
});
1655+
1656+
it('gets owner when template is user-owned', async () => {
1657+
const { templateRepository, mocks } = setup();
1658+
15921659
mocks.ddbDocClient.on(QueryCommand).resolves({
15931660
Items: [
15941661
{

lambdas/sftp-letters/src/__tests__/infra/template-lock-repository.test.ts

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,41 @@ describe('TemplateLockRepository', () => {
5757
});
5858
});
5959

60+
test('returns true when database update succeeds with user owned template', async () => {
61+
const { mocks, templateRepository } = setup();
62+
63+
mocks.client.on(UpdateCommand).resolvesOnce({});
64+
65+
const res = await templateRepository.acquireLock(
66+
owner,
67+
templateId,
68+
false
69+
);
70+
71+
expect(res).toBe(true);
72+
73+
expect(mocks.client).toHaveReceivedCommandWith(UpdateCommand, {
74+
ExpressionAttributeNames: {
75+
'#updatedAt': 'updatedAt',
76+
'#sftpSendLockTime': 'sftpSendLockTime',
77+
},
78+
ExpressionAttributeValues: {
79+
':condition_2_sftpSendLockTime': mockDate.getTime() + sendLockTtlMs,
80+
':updatedAt': expect.stringMatching(isoDateRegExp),
81+
':sftpSendLockTime': mockDate.getTime(),
82+
},
83+
ConditionExpression:
84+
'attribute_not_exists (#sftpSendLockTime) OR #sftpSendLockTime > :condition_2_sftpSendLockTime',
85+
Key: {
86+
id: templateId,
87+
owner,
88+
},
89+
TableName: templatesTableName,
90+
UpdateExpression:
91+
'SET #sftpSendLockTime = :sftpSendLockTime, #updatedAt = :updatedAt',
92+
});
93+
});
94+
6095
test('returns false when database update fails due to a ConditionalCheckFailedException', async () => {
6196
const { mocks, templateRepository } = setup();
6297

@@ -109,5 +144,31 @@ describe('TemplateLockRepository', () => {
109144
'SET #sftpSendLockTime = :sftpSendLockTime, #updatedAt = :updatedAt',
110145
});
111146
});
147+
148+
test('unconditionally sets lockTime to one month in the future with user-owned template', async () => {
149+
const { mocks, templateRepository } = setup();
150+
151+
mocks.client.on(UpdateCommand).resolvesOnce({});
152+
153+
await templateRepository.finaliseLock(owner, templateId, false);
154+
155+
expect(mocks.client).toHaveReceivedCommandWith(UpdateCommand, {
156+
ExpressionAttributeNames: {
157+
'#updatedAt': 'updatedAt',
158+
'#sftpSendLockTime': 'sftpSendLockTime',
159+
},
160+
ExpressionAttributeValues: {
161+
':updatedAt': expect.any(String),
162+
':sftpSendLockTime': mockDate.getTime() + 2_592_000_000,
163+
},
164+
Key: {
165+
id: templateId,
166+
owner,
167+
},
168+
TableName: templatesTableName,
169+
UpdateExpression:
170+
'SET #sftpSendLockTime = :sftpSendLockTime, #updatedAt = :updatedAt',
171+
});
172+
});
112173
});
113174
});

tests/test-team/template-mgmt-component-tests/template-mgmt-submitted-page.component.spec.ts

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,28 @@ import { TemplateMgmtTemplateSubmittedLetterPage } from '../pages/letter/templat
2121

2222
function createTemplates(user: TestUser) {
2323
return {
24-
email: TemplateFactory.create({
25-
owner: user.owner,
26-
clientId: user.clientId,
27-
templateType: 'EMAIL',
24+
email: {
25+
...TemplateFactory.createEmailTemplate(
26+
'valid-email-template',
27+
user,
28+
'test-template-email'
29+
),
2830
templateStatus: 'SUBMITTED',
29-
id: 'valid-email-template',
30-
name: 'test-template-email',
3131
subject: 'test-template-subject',
3232
message: 'test example content',
33-
}),
34-
'text-message': TemplateFactory.create({
35-
owner: user.owner,
36-
clientId: user.clientId,
37-
templateType: 'SMS',
33+
},
34+
'text-message': {
35+
...TemplateFactory.createSmsTemplate('valid-text-message-template', user),
3836
templateStatus: 'SUBMITTED',
39-
id: 'valid-text-message-template',
40-
name: 'test-template-sms',
4137
message: 'test example content',
42-
}),
43-
'nhs-app': TemplateFactory.create({
44-
owner: user.owner,
45-
clientId: user.clientId,
46-
templateType: 'NHS_APP',
38+
name: 'test-template-sms',
39+
},
40+
'nhs-app': {
41+
...TemplateFactory.createNhsAppTemplate('valid-nhs-app-template', user),
4742
templateStatus: 'SUBMITTED',
48-
id: 'valid-nhs-app-template',
49-
name: 'test-template-nhs-app',
5043
message: 'test example content',
51-
}),
44+
name: 'test-template-nhs-app',
45+
},
5246
letter: TemplateFactory.uploadLetterTemplate(
5347
'valid-submitted-letter-template',
5448
user,

0 commit comments

Comments
 (0)