Skip to content

Commit e6326d8

Browse files
committed
CCM-15676: rename delete to markWithdrawn
1 parent 51c7528 commit e6326d8

4 files changed

Lines changed: 19 additions & 17 deletions

File tree

lambdas/nhsapp-status-handler/src/__tests__/apis/sqs-trigger-lambda.test.ts

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ describe('createHandler', () => {
4343
};
4444

4545
beforeEach(() => {
46-
ttlActions = { delete: jest.fn() };
46+
ttlActions = { markWithdrawn: jest.fn() };
4747
eventPublisher = { sendEvents: jest.fn().mockResolvedValue([]) };
4848
logger = { error: jest.fn(), info: jest.fn(), warn: jest.fn() };
4949
handler = createHandler({ ttlActions, eventPublisher, logger });
5050
});
5151

5252
it('processes a valid SQS event and returns success', async () => {
53-
ttlActions.delete.mockResolvedValue({
53+
ttlActions.markWithdrawn.mockResolvedValue({
5454
result: 'success',
5555
ttlItem: { event: messageDownloadedEvent },
5656
});
@@ -61,7 +61,7 @@ describe('createHandler', () => {
6161
const res = await handler(event);
6262

6363
expect(res.batchItemFailures).toEqual([]);
64-
expect(ttlActions.delete).toHaveBeenCalledWith(nhsAppStatusEvent);
64+
expect(ttlActions.markWithdrawn).toHaveBeenCalledWith(nhsAppStatusEvent);
6565
expect(eventPublisher.sendEvents).toHaveBeenCalledWith(
6666
[digitalLetterReadEvent],
6767
validateDigitalLetterRead,
@@ -131,14 +131,16 @@ describe('createHandler', () => {
131131
});
132132
});
133133

134-
it('handles ttlActions.delete failure', async () => {
135-
ttlActions.delete.mockResolvedValue({ result: 'failed' });
134+
it('handles ttlActions.markWithdrawn failure', async () => {
135+
ttlActions.markWithdrawn.mockResolvedValue({ result: 'failed' });
136136
const event: SQSEvent = {
137137
Records: [{ body: JSON.stringify(eventBusEvent), messageId: 'msg1' }],
138138
} as any;
139139

140140
const res = await handler(event);
141141

142+
expect(ttlActions.markWithdrawn).toHaveBeenCalledWith(nhsAppStatusEvent);
143+
expect(eventPublisher.sendEvents).not.toHaveBeenCalled();
142144
expect(res.batchItemFailures).toEqual([{ itemIdentifier: 'msg1' }]);
143145
expect(logger.info).toHaveBeenCalledWith({
144146
description: 'Processed SQS Event.',
@@ -202,7 +204,7 @@ describe('createHandler', () => {
202204
});
203205

204206
it('processes multiple successful events and sends them as a batch', async () => {
205-
ttlActions.delete.mockResolvedValue({
207+
ttlActions.markWithdrawn.mockResolvedValue({
206208
result: 'success',
207209
ttlItem: { event: messageDownloadedEvent },
208210
});
@@ -217,7 +219,7 @@ describe('createHandler', () => {
217219
const res = await handler(sqsEvent);
218220

219221
expect(res.batchItemFailures).toEqual([]);
220-
expect(ttlActions.delete).toHaveBeenCalledTimes(3);
222+
expect(ttlActions.markWithdrawn).toHaveBeenCalledTimes(3);
221223
expect(eventPublisher.sendEvents).toHaveBeenCalledWith(
222224
[digitalLetterReadEvent, digitalLetterReadEvent, digitalLetterReadEvent],
223225
validateDigitalLetterRead,
@@ -231,7 +233,7 @@ describe('createHandler', () => {
231233
});
232234

233235
it('handles partial event publishing failures and logs warning', async () => {
234-
ttlActions.delete.mockResolvedValue({
236+
ttlActions.markWithdrawn.mockResolvedValue({
235237
result: 'success',
236238
ttlItem: { event: messageDownloadedEvent },
237239
});
@@ -260,7 +262,7 @@ describe('createHandler', () => {
260262
});
261263

262264
it('handles event publishing exception and logs warning', async () => {
263-
ttlActions.delete.mockResolvedValue({
265+
ttlActions.markWithdrawn.mockResolvedValue({
264266
result: 'success',
265267
ttlItem: { event: messageDownloadedEvent },
266268
});
@@ -286,7 +288,7 @@ describe('createHandler', () => {
286288
});
287289

288290
it('does not call eventPublisher when no successful events', async () => {
289-
ttlActions.delete.mockResolvedValue({ result: 'failed' });
291+
ttlActions.markWithdrawn.mockResolvedValue({ result: 'failed' });
290292

291293
const event: SQSEvent = {
292294
Records: [{ body: JSON.stringify(eventBusEvent), messageId: 'msg1' }],
@@ -305,7 +307,7 @@ describe('createHandler', () => {
305307
});
306308

307309
it('does not call eventPublisher when no TTL record is found', async () => {
308-
ttlActions.delete.mockResolvedValue({ result: 'success' });
310+
ttlActions.markWithdrawn.mockResolvedValue({ result: 'success' });
309311

310312
const event: SQSEvent = {
311313
Records: [{ body: JSON.stringify(eventBusEvent), messageId: 'msg1' }],
@@ -324,7 +326,7 @@ describe('createHandler', () => {
324326
});
325327

326328
it('handles mixed success and failure scenarios', async () => {
327-
ttlActions.delete
329+
ttlActions.markWithdrawn
328330
.mockResolvedValueOnce({
329331
result: 'success',
330332
ttlItem: { event: messageDownloadedEvent },

lambdas/nhsapp-status-handler/src/__tests__/app/ttl-actions.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ describe('TtlActions', () => {
1616
it('returns success when markWithdrawn succeeds', async () => {
1717
repo.markWithdrawn.mockResolvedValue({ event: messageDownloadedEvent });
1818

19-
const result = await ttlActions.delete(nhsAppStatusEvent);
19+
const result = await ttlActions.markWithdrawn(nhsAppStatusEvent);
2020

2121
expect(result).toEqual({
2222
result: 'success',
@@ -31,7 +31,7 @@ describe('TtlActions', () => {
3131
// eslint-disable-next-line unicorn/no-useless-undefined
3232
repo.markWithdrawn.mockResolvedValue(undefined);
3333

34-
const result = await ttlActions.delete(nhsAppStatusEvent);
34+
const result = await ttlActions.markWithdrawn(nhsAppStatusEvent);
3535

3636
expect(result).toEqual({ result: 'success' });
3737

@@ -50,7 +50,7 @@ describe('TtlActions', () => {
5050
const error = new Error('fail');
5151
repo.markWithdrawn.mockRejectedValue(error);
5252

53-
const result = await ttlActions.delete(nhsAppStatusEvent);
53+
const result = await ttlActions.markWithdrawn(nhsAppStatusEvent);
5454

5555
expect(result).toEqual({ result: 'failed' });
5656
expect(logger.warn).toHaveBeenCalledWith(

lambdas/nhsapp-status-handler/src/apis/sqs-trigger-lambda.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ export const createHandler = ({
5555
return { outcome: { result: 'failed' } };
5656
}
5757

58-
const result = await ttlActions.delete(item);
58+
const result = await ttlActions.markWithdrawn(item);
5959

6060
if (result.result === 'failed') {
6161
batchItemFailures.push({ itemIdentifier: messageId });

lambdas/nhsapp-status-handler/src/app/ttl-actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export class TtlActions {
1515
private readonly logger: Logger,
1616
) {}
1717

18-
async delete(item: NhsAppStatus): Promise<TtlActionOutcome> {
18+
async markWithdrawn(item: NhsAppStatus): Promise<TtlActionOutcome> {
1919
let ttlItem: TtlItem;
2020

2121
try {

0 commit comments

Comments
 (0)