Skip to content

Commit 0c35d21

Browse files
committed
CCM-12045: cleanup
1 parent df94b79 commit 0c35d21

File tree

3 files changed

+29
-71
lines changed

3 files changed

+29
-71
lines changed

lambdas/event-publisher/src/__tests__/domain/event-builder.test.ts

Lines changed: 18 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -296,70 +296,27 @@ test('builds template drafted event', () => {
296296
);
297297
});
298298

299-
test('builds template drafted event when no old image is available', () => {
300-
const event = eventBuilder.buildEvent({
299+
test('builds event when no old image is available', () => {
300+
// although not required by this lambda, an old image would be expected here in real usage
301+
const mockEvent = publishableEventRecord('SUBMITTED');
302+
303+
const noOldImage = {
304+
...mockEvent,
301305
dynamodb: {
302-
SequenceNumber: '4',
303-
NewImage: {
304-
owner: {
305-
S: 'owner',
306-
},
307-
id: {
308-
S: 'id',
309-
},
310-
clientId: {
311-
S: 'client-id',
312-
},
313-
createdAt: {
314-
S: 'created-at',
315-
},
316-
createdBy: {
317-
S: 'created-by',
318-
},
319-
name: {
320-
S: 'name',
321-
},
322-
templateStatus: {
323-
S: 'NOT_YET_SUBMITTED',
324-
},
325-
updatedAt: {
326-
S: 'updated-at',
327-
},
328-
updatedBy: {
329-
S: 'updated-by',
330-
},
331-
templateType: {
332-
S: 'NHS_APP',
333-
},
334-
message: {
335-
S: 'app content',
336-
},
337-
},
306+
SequenceNumber: mockEvent.dynamodb.SequenceNumber,
307+
NewImage: mockEvent.dynamodb.NewImage,
338308
},
339-
eventID: 'event-id',
340-
tableName: 'table-name',
341-
});
309+
};
342310

343-
expect(event).toEqual({
344-
...expectedEvent(
345-
'PROOF_AVAILABLE',
346-
'uk.nhs.notify.template-management.TemplateDrafted.v1',
347-
'https://notify.nhs.uk/events/schemas/TemplateDrafted/v1.json'
348-
),
349-
data: {
350-
clientId: 'client-id',
351-
createdAt: 'created-at',
352-
createdBy: 'created-by',
353-
id: 'id',
354-
message: 'app content',
355-
name: 'name',
356-
owner: 'owner',
357-
templateStatus: 'NOT_YET_SUBMITTED',
358-
templateType: 'NHS_APP',
359-
updatedAt: 'updated-at',
360-
updatedBy: 'updated-by',
361-
},
362-
});
311+
const event = eventBuilder.buildEvent(noOldImage);
312+
313+
expect(event).toEqual(
314+
expectedEvent(
315+
'SUBMITTED',
316+
'uk.nhs.notify.template-management.TemplateCompleted.v1',
317+
'https://notify.nhs.uk/events/schemas/TemplateCompleted/v1.json'
318+
)
319+
);
363320
});
364321

365322
test('builds template deleted event', () => {

lambdas/event-publisher/src/__tests__/domain/should-publish.test.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,23 @@ describe('shouldPublish', () => {
4444
}
4545
);
4646

47-
const letterPublishCases: Record<TemplateStatus, boolean> = {
47+
type LetterStatus = Exclude<TemplateStatus, 'NOT_YET_SUBMITTED'>;
48+
49+
const letterPublishCases: Record<LetterStatus, boolean> = {
4850
DELETED: true,
4951
PENDING_PROOF_REQUEST: true,
5052
PROOF_AVAILABLE: true,
5153
SUBMITTED: true,
5254
WAITING_FOR_PROOF: true,
53-
NOT_YET_SUBMITTED: false,
5455
PENDING_UPLOAD: false,
5556
PENDING_VALIDATION: false,
5657
VALIDATION_FAILED: false,
5758
VIRUS_SCAN_FAILED: false,
5859
};
5960

61+
// not all of these transitions are expected in real usage
6062
test.each(Object.entries(letterPublishCases) as [TemplateStatus, boolean][])(
61-
'templateType LETTER with current status %p should return %p when proofingEnabled is true and status of previous is PENDING_PROOF_REQUEST',
63+
'templateType LETTER with current status %p should return %p when proofingEnabled is true and status of previous is not restrictive',
6264
(templateStatus, publishable) => {
6365
const publish = shouldPublish(
6466
{
@@ -79,8 +81,9 @@ describe('shouldPublish', () => {
7981
}
8082
);
8183

84+
// not all of these transitions are expected in real usage
8285
test.each(Object.entries(letterPublishCases) as [TemplateStatus, boolean][])(
83-
'templateType LETTER with current status DELETED and previous status %p should return %p when proofingEnabled is true',
86+
'templateType LETTER with new status DELETED and previous status %p should return %p when proofingEnabled is true',
8487
(templateStatus, publishable) => {
8588
const publish = shouldPublish(
8689
{

lambdas/event-publisher/src/domain/should-publish.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,16 @@ function shouldPublishLetter(
1212
previous: DynamoDBTemplate | undefined,
1313
current: DynamoDBTemplate
1414
): boolean {
15+
if (!current.proofingEnabled) return false;
16+
1517
if (current.templateStatus === 'DELETED') {
1618
return (
1719
previous !== undefined &&
18-
publishableLetterStatuses.has(previous.templateStatus) &&
19-
!!current.proofingEnabled
20+
publishableLetterStatuses.has(previous.templateStatus)
2021
);
2122
}
2223

23-
return (
24-
publishableLetterStatuses.has(current.templateStatus) &&
25-
!!current.proofingEnabled
26-
);
24+
return publishableLetterStatuses.has(current.templateStatus);
2725
}
2826

2927
export function shouldPublish(

0 commit comments

Comments
 (0)