Skip to content

Commit cf802fc

Browse files
committed
CCM-10387: coverage
1 parent 23c18a2 commit cf802fc

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
@@ -1464,6 +1464,57 @@ describe('templateRepository', () => {
14641464
});
14651465
});
14661466

1467+
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 () => {
1468+
const { templateRepository, mocks } = setup();
1469+
mocks.ddbDocClient.on(UpdateCommand).resolves({
1470+
Attributes: {
1471+
templateStatus: 'WAITING_FOR_PROOF',
1472+
},
1473+
});
1474+
1475+
await templateRepository.setLetterFileVirusScanStatusForProof(
1476+
{ owner: userId, id: 'template-id', clientOwned: false },
1477+
'pdf-template.pdf',
1478+
'PASSED',
1479+
'MBA'
1480+
);
1481+
1482+
expect(mocks.ddbDocClient).toHaveReceivedCommandWith(UpdateCommand, {
1483+
TableName: 'templates',
1484+
Key: { id: 'template-id', owner: userId },
1485+
UpdateExpression:
1486+
'SET files.proofs.#fileName = :virusScanResult, updatedAt = :updatedAt',
1487+
ConditionExpression:
1488+
'attribute_not_exists(files.proofs.#fileName) and not templateStatus in (:templateStatusDeleted, :templateStatusSubmitted)',
1489+
ExpressionAttributeNames: {
1490+
'#fileName': 'pdf-template.pdf',
1491+
},
1492+
ExpressionAttributeValues: {
1493+
':templateStatusDeleted': 'DELETED',
1494+
':templateStatusSubmitted': 'SUBMITTED',
1495+
':updatedAt': new Date().toISOString(),
1496+
':virusScanResult': {
1497+
fileName: 'pdf-template.pdf',
1498+
virusScanStatus: 'PASSED',
1499+
supplier: 'MBA',
1500+
},
1501+
},
1502+
});
1503+
1504+
expect(mocks.ddbDocClient).toHaveReceivedCommandWith(UpdateCommand, {
1505+
TableName: 'templates',
1506+
Key: { id: 'template-id', owner: userId },
1507+
UpdateExpression:
1508+
'SET templateStatus = :templateStatusProofAvailable, updatedAt = :updatedAt',
1509+
ExpressionAttributeValues: {
1510+
':templateStatusWaitingForProof': 'WAITING_FOR_PROOF',
1511+
':templateStatusProofAvailable': 'PROOF_AVAILABLE',
1512+
':updatedAt': new Date().toISOString(),
1513+
},
1514+
ConditionExpression: 'templateStatus = :templateStatusWaitingForProof',
1515+
});
1516+
});
1517+
14671518
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 () => {
14681519
const { templateRepository, mocks } = setup();
14691520
mocks.ddbDocClient.on(UpdateCommand).resolves({
@@ -1592,6 +1643,22 @@ describe('templateRepository', () => {
15921643
it('gets owner', async () => {
15931644
const { templateRepository, mocks } = setup();
15941645

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

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)