From adff34668d50e8f4061df3f26b4b639a276aeebe Mon Sep 17 00:00:00 2001 From: Matt <173997080+sw-mattw@users.noreply.github.com> Date: Fri, 31 Jan 2025 14:01:27 +0000 Subject: [PATCH 1/3] feat(FN-3737): clear old record correction transient form data (portal) --- .../index.test.ts | 182 ++++++++++++++++++ .../index.ts | 30 +++ .../index.test.ts | 92 --------- .../index.ts | 23 --- .../src/cron-scheduler-jobs/index.ts | 4 +- ...ord-correction-transient-form-data.repo.ts | 14 +- 6 files changed, 227 insertions(+), 118 deletions(-) create mode 100644 dtfs-central-api/src/cron-scheduler-jobs/delete-correction-and-correction-request-transient-form-data/index.test.ts create mode 100644 dtfs-central-api/src/cron-scheduler-jobs/delete-correction-and-correction-request-transient-form-data/index.ts delete mode 100644 dtfs-central-api/src/cron-scheduler-jobs/delete-correction-request-transient-form-data/index.test.ts delete mode 100644 dtfs-central-api/src/cron-scheduler-jobs/delete-correction-request-transient-form-data/index.ts diff --git a/dtfs-central-api/src/cron-scheduler-jobs/delete-correction-and-correction-request-transient-form-data/index.test.ts b/dtfs-central-api/src/cron-scheduler-jobs/delete-correction-and-correction-request-transient-form-data/index.test.ts new file mode 100644 index 0000000000..7a9634b76e --- /dev/null +++ b/dtfs-central-api/src/cron-scheduler-jobs/delete-correction-and-correction-request-transient-form-data/index.test.ts @@ -0,0 +1,182 @@ +import { LessThan } from 'typeorm'; +import { deleteCorrectionAndCorrectionRequestTransientFormData, deleteCorrectionAndCorrectionRequestTransientFormDataJob } from '.'; +import { FeeRecordCorrectionRequestTransientFormDataRepo } from '../../repositories/fee-record-correction-request-transient-form-data-repo/fee-record-correction-request-transient-form-data.repo'; +import { FeeRecordCorrectionTransientFormDataRepo } from '../../repositories/fee-record-correction-transient-form-data-repo'; + +console.error = jest.fn(); + +describe('delete-correction-and-correction-request-transient-form-data', () => { + jest.mock('typeorm', () => ({ + LessThan: jest.fn(), + })); + + const mockCorrectionDelete = jest.fn(); + const mockCorrectionRequestDelete = jest.fn(); + + beforeAll(() => { + jest.useFakeTimers(); + }); + + afterAll(() => { + jest.useRealTimers(); + }); + + describe('deleteCorrectionAndCorrectionRequestTransientFormData', () => { + beforeEach(() => { + jest.useFakeTimers().setSystemTime(new Date('2025-01-02 12:10:00')); + + FeeRecordCorrectionTransientFormDataRepo.delete = mockCorrectionDelete; + FeeRecordCorrectionRequestTransientFormDataRepo.delete = mockCorrectionRequestDelete; + }); + + afterEach(() => { + jest.resetAllMocks(); + }); + + it('should delete records older than one day', async () => { + // Act + await deleteCorrectionAndCorrectionRequestTransientFormData(); + + // Assert + const expectedDeletionCallArgs = { + lastUpdatedAt: LessThan(new Date('2025-01-01:12:10:00')), + }; + + expect(mockCorrectionDelete).toHaveBeenCalledTimes(1); + expect(mockCorrectionDelete).toHaveBeenCalledWith(expectedDeletionCallArgs); + + expect(mockCorrectionRequestDelete).toHaveBeenCalledTimes(1); + expect(mockCorrectionRequestDelete).toHaveBeenCalledWith(expectedDeletionCallArgs); + }); + + it('should delete records older than one day if it is the first day of the month', async () => { + // Arrange + jest.useFakeTimers().setSystemTime(new Date('2025-01-01 12:10:00')); + + // Act + await deleteCorrectionAndCorrectionRequestTransientFormData(); + + // Assert + const expectedDeletionCallArgs = { + lastUpdatedAt: LessThan(new Date('2024-12-31:12:10:00')), + }; + + expect(mockCorrectionDelete).toHaveBeenCalledTimes(1); + expect(mockCorrectionDelete).toHaveBeenCalledWith(expectedDeletionCallArgs); + + expect(mockCorrectionRequestDelete).toHaveBeenCalledTimes(1); + expect(mockCorrectionRequestDelete).toHaveBeenCalledWith(expectedDeletionCallArgs); + }); + + describe('when record correction transient data deletion fails', () => { + it('should throw an error', async () => { + // Arrange + const errorMessage = 'This is an error'; + const error = new Error(errorMessage); + + jest.mocked(mockCorrectionDelete).mockRejectedValue(error); + + // Act + await deleteCorrectionAndCorrectionRequestTransientFormData(); + + // Assert + expect(mockCorrectionDelete).toHaveBeenCalledTimes(1); + + expect(console.error).toHaveBeenCalledTimes(1); + expect(console.error).toHaveBeenCalledWith( + 'Error deleting old transient record correction form data - deleteCorrectionRequestTransientFormData CRON job: %o', + error, + ); + }); + + it('should still call record correction request transient data deletion', async () => { + // Act + await deleteCorrectionAndCorrectionRequestTransientFormData(); + + // Assert + expect(mockCorrectionRequestDelete).toHaveBeenCalledTimes(1); + }); + }); + + describe('when record correction request transient data deletion fails', () => { + it('should throw an error', async () => { + // Arrange + const errorMessage = 'This is an error'; + const error = new Error(errorMessage); + + jest.mocked(mockCorrectionRequestDelete).mockRejectedValue(error); + + // Act + await deleteCorrectionAndCorrectionRequestTransientFormData(); + + // Assert + expect(mockCorrectionRequestDelete).toHaveBeenCalledTimes(1); + + expect(console.error).toHaveBeenCalledTimes(1); + expect(console.error).toHaveBeenCalledWith( + 'Error deleting old transient record correction request form data - deleteCorrectionRequestTransientFormData CRON job: %o', + error, + ); + }); + + it('should still call record correction transient data deletion', async () => { + // Act + await deleteCorrectionAndCorrectionRequestTransientFormData(); + + // Assert + expect(mockCorrectionDelete).toHaveBeenCalledTimes(1); + }); + }); + }); + + describe('deleteRecordCorrectionRequestTransientFormDataJob', () => { + beforeEach(() => { + jest.useFakeTimers().setSystemTime(new Date('2025-01-02 12:10:00')); + + FeeRecordCorrectionTransientFormDataRepo.delete = mockCorrectionDelete; + FeeRecordCorrectionRequestTransientFormDataRepo.delete = mockCorrectionRequestDelete; + }); + + afterEach(() => { + jest.resetAllMocks(); + }); + + it('should be scheduled to run', () => { + // Assert + expect(deleteCorrectionAndCorrectionRequestTransientFormDataJob.cronExpression).toEqual( + process.env.RECORD_CORRECTION_TRANSIENT_FORM_DATA_DELETE_SCHEDULE, + ); + }); + + it('should have the correct description', () => { + // Assert + expect(deleteCorrectionAndCorrectionRequestTransientFormDataJob.description).toEqual( + 'Deletes record correction and record correction request transient form data older than 1 day', + ); + }); + + it('should call FeeRecordCorrectionTransientFormDataRepo.delete', async () => { + // Act + await deleteCorrectionAndCorrectionRequestTransientFormDataJob.task('manual'); + + // Assert + expect(mockCorrectionDelete).toHaveBeenCalledTimes(1); + + expect(mockCorrectionDelete).toHaveBeenCalledWith({ + lastUpdatedAt: LessThan(new Date('2025-01-01:12:10:00')), + }); + }); + + it('should call FeeRecordCorrectionRequestTransientFormDataRepo.delete', async () => { + // Act + await deleteCorrectionAndCorrectionRequestTransientFormDataJob.task('manual'); + + // Assert + expect(mockCorrectionRequestDelete).toHaveBeenCalledTimes(1); + + expect(mockCorrectionRequestDelete).toHaveBeenCalledWith({ + lastUpdatedAt: LessThan(new Date('2025-01-01:12:10:00')), + }); + }); + }); +}); diff --git a/dtfs-central-api/src/cron-scheduler-jobs/delete-correction-and-correction-request-transient-form-data/index.ts b/dtfs-central-api/src/cron-scheduler-jobs/delete-correction-and-correction-request-transient-form-data/index.ts new file mode 100644 index 0000000000..d199178d40 --- /dev/null +++ b/dtfs-central-api/src/cron-scheduler-jobs/delete-correction-and-correction-request-transient-form-data/index.ts @@ -0,0 +1,30 @@ +import { asString, CronSchedulerJob } from '@ukef/dtfs2-common'; +import { FeeRecordCorrectionRequestTransientFormDataRepo } from '../../repositories/fee-record-correction-request-transient-form-data-repo'; +import { FeeRecordCorrectionTransientFormDataRepo } from '../../repositories/fee-record-correction-transient-form-data-repo'; + +const { RECORD_CORRECTION_TRANSIENT_FORM_DATA_DELETE_SCHEDULE } = process.env; + +/** + * Deletes record correction and correction request transient form data more than 1 day old. + */ +export const deleteCorrectionAndCorrectionRequestTransientFormData = async (): Promise => { + console.info('Deleting old transient record corrections and correction requests - deleteCorrectionRequestTransientFormData CRON job'); + + try { + await FeeRecordCorrectionTransientFormDataRepo.deleteByLastUpdatedOlderThanOneDayAgo(); + } catch (error) { + console.error('Error deleting old transient record correction form data - deleteCorrectionRequestTransientFormData CRON job: %o', error); + } + + try { + await FeeRecordCorrectionRequestTransientFormDataRepo.deleteByLastUpdatedOlderThanOneDayAgo(); + } catch (error) { + console.error('Error deleting old transient record correction request form data - deleteCorrectionRequestTransientFormData CRON job: %o', error); + } +}; + +export const deleteCorrectionAndCorrectionRequestTransientFormDataJob: CronSchedulerJob = { + cronExpression: asString(RECORD_CORRECTION_TRANSIENT_FORM_DATA_DELETE_SCHEDULE, 'RECORD_CORRECTION_TRANSIENT_FORM_DATA_DELETE_SCHEDULE'), + description: 'Deletes record correction and record correction request transient form data older than 1 day', + task: deleteCorrectionAndCorrectionRequestTransientFormData, +}; diff --git a/dtfs-central-api/src/cron-scheduler-jobs/delete-correction-request-transient-form-data/index.test.ts b/dtfs-central-api/src/cron-scheduler-jobs/delete-correction-request-transient-form-data/index.test.ts deleted file mode 100644 index 629cdb99dd..0000000000 --- a/dtfs-central-api/src/cron-scheduler-jobs/delete-correction-request-transient-form-data/index.test.ts +++ /dev/null @@ -1,92 +0,0 @@ -import { LessThan } from 'typeorm'; -import { deleteCorrectionRequestTransientFormData, deleteCorrectionRequestTransientFormDataJob } from '.'; -import { FeeRecordCorrectionRequestTransientFormDataRepo } from '../../repositories/fee-record-correction-request-transient-form-data-repo/fee-record-correction-request-transient-form-data.repo'; - -describe('delete-record-correction-request-transient-form-data', () => { - jest.mock('typeorm', () => ({ - LessThan: jest.fn(), - })); - - const mockDelete = jest.fn(); - console.error = jest.fn(); - - beforeAll(() => { - jest.useFakeTimers(); - }); - - afterAll(() => { - jest.useRealTimers(); - }); - - describe('deleteRecordCorrectionRequestTransientFormData', () => { - beforeEach(() => { - jest.resetAllMocks(); - FeeRecordCorrectionRequestTransientFormDataRepo.delete = mockDelete; - jest.useFakeTimers().setSystemTime(new Date('2025-01-02 12:10:00')); - }); - - it('should delete records older than one day', async () => { - await deleteCorrectionRequestTransientFormData(); - - expect(mockDelete).toHaveBeenCalledTimes(1); - - expect(mockDelete).toHaveBeenCalledWith({ - lastUpdatedAt: LessThan(new Date('2025-01-01:12:10:00')), - }); - }); - - it('should delete records older than one day if it is the first day of the month', async () => { - jest.useFakeTimers().setSystemTime(new Date('2025-01-01 12:10:00')); - - await deleteCorrectionRequestTransientFormData(); - - expect(mockDelete).toHaveBeenCalledTimes(1); - - expect(mockDelete).toHaveBeenCalledWith({ - lastUpdatedAt: LessThan(new Date('2024-12-31:12:10:00')), - }); - }); - - it('should throw an error if deletion fails', async () => { - const errorMessage = 'This is an error'; - const error = new Error(errorMessage); - jest.mocked(mockDelete).mockRejectedValue(error); - - await deleteCorrectionRequestTransientFormData(); - - expect(console.error).toHaveBeenCalledTimes(1); - expect(console.error).toHaveBeenCalledWith( - 'Error deleting old transient record correction requests - deleteCorrectionRequestTransientFormDataJob CRON job: %o', - error, - ); - }); - }); - - describe('deleteRecordCorrectionRequestTransientFormDataJob', () => { - beforeEach(() => { - jest.resetAllMocks(); - FeeRecordCorrectionRequestTransientFormDataRepo.delete = mockDelete; - jest.useFakeTimers().setSystemTime(new Date('2025-01-02 12:10:00')); - }); - - it('should be scheduled to run', () => { - expect(deleteCorrectionRequestTransientFormDataJob.cronExpression).toEqual(process.env.RECORD_CORRECTION_TRANSIENT_FORM_DATA_DELETE_SCHEDULE); - }); - - it('should have the correct description', () => { - expect(deleteCorrectionRequestTransientFormDataJob.description).toEqual('Delete record correction transient form data older than 1 day'); - }); - - it('should call FeeRecordCorrectionRequestTransientFormDataRepo.delete', async () => { - // Act - await deleteCorrectionRequestTransientFormDataJob.task('manual'); - - // Assert - expect(mockDelete).toHaveBeenCalledTimes(1); - - expect(mockDelete).toHaveBeenCalledWith({ - lastUpdatedAt: LessThan(new Date('2025-01-01:12:10:00')), - }); - }); - }); -}); diff --git a/dtfs-central-api/src/cron-scheduler-jobs/delete-correction-request-transient-form-data/index.ts b/dtfs-central-api/src/cron-scheduler-jobs/delete-correction-request-transient-form-data/index.ts deleted file mode 100644 index 6eaf3234b6..0000000000 --- a/dtfs-central-api/src/cron-scheduler-jobs/delete-correction-request-transient-form-data/index.ts +++ /dev/null @@ -1,23 +0,0 @@ -import { asString, CronSchedulerJob } from '@ukef/dtfs2-common'; -import { FeeRecordCorrectionRequestTransientFormDataRepo } from '../../repositories/fee-record-correction-request-transient-form-data-repo'; - -const { RECORD_CORRECTION_TRANSIENT_FORM_DATA_DELETE_SCHEDULE } = process.env; - -/** - * Deletes record correction request transient form data more than 1 day old - */ -export const deleteCorrectionRequestTransientFormData = async (): Promise => { - try { - console.info('Getting and deleting old transient record correction requests - deleteCorrectionRequestTransientFormDataJob CRON job'); - - await FeeRecordCorrectionRequestTransientFormDataRepo.deleteByLastUpdatedOlderThanOneDayAgo(); - } catch (error) { - console.error('Error deleting old transient record correction requests - deleteCorrectionRequestTransientFormDataJob CRON job: %o', error); - } -}; - -export const deleteCorrectionRequestTransientFormDataJob: CronSchedulerJob = { - cronExpression: asString(RECORD_CORRECTION_TRANSIENT_FORM_DATA_DELETE_SCHEDULE, 'RECORD_CORRECTION_TRANSIENT_FORM_DATA_DELETE_SCHEDULE'), - description: 'Delete record correction transient form data older than 1 day', - task: deleteCorrectionRequestTransientFormData, -}; diff --git a/dtfs-central-api/src/cron-scheduler-jobs/index.ts b/dtfs-central-api/src/cron-scheduler-jobs/index.ts index c6d9de4e43..07c5c95d52 100644 --- a/dtfs-central-api/src/cron-scheduler-jobs/index.ts +++ b/dtfs-central-api/src/cron-scheduler-jobs/index.ts @@ -2,11 +2,11 @@ import { CronSchedulerJob } from '@ukef/dtfs2-common'; import { createUtilisationReportForBanksJob } from './create-utilisation-reports'; import { deleteCompleteAcbsDurableFunctionLogsJob } from './delete-acbs-durable-function-logs'; import { cancelDealJob } from './deal-cancellation/cancel-deal-job'; -import { deleteCorrectionRequestTransientFormDataJob } from './delete-correction-request-transient-form-data'; +import { deleteCorrectionAndCorrectionRequestTransientFormDataJob } from './delete-correction-and-correction-request-transient-form-data'; export const cronSchedulerJobs: CronSchedulerJob[] = [ createUtilisationReportForBanksJob, deleteCompleteAcbsDurableFunctionLogsJob, cancelDealJob, - deleteCorrectionRequestTransientFormDataJob, + deleteCorrectionAndCorrectionRequestTransientFormDataJob, ]; diff --git a/dtfs-central-api/src/repositories/fee-record-correction-transient-form-data-repo/fee-record-correction-transient-form-data.repo.ts b/dtfs-central-api/src/repositories/fee-record-correction-transient-form-data-repo/fee-record-correction-transient-form-data.repo.ts index 58b6768674..ba75a5b7be 100644 --- a/dtfs-central-api/src/repositories/fee-record-correction-transient-form-data-repo/fee-record-correction-transient-form-data.repo.ts +++ b/dtfs-central-api/src/repositories/fee-record-correction-transient-form-data-repo/fee-record-correction-transient-form-data.repo.ts @@ -1,6 +1,6 @@ import { SqlDbDataSource } from '@ukef/dtfs2-common/sql-db-connection'; import { FeeRecordCorrectionTransientFormDataEntity } from '@ukef/dtfs2-common'; -import { EntityManager } from 'typeorm'; +import { EntityManager, LessThan } from 'typeorm'; /** * Repository for managing fee record correction transient form data. @@ -33,6 +33,18 @@ export const FeeRecordCorrectionTransientFormDataRepo = SqlDbDataSource.getRepos }); }, + /** + * Deletes transient fee record correction data that was last updated more than one day ago. + */ + async deleteByLastUpdatedOlderThanOneDayAgo(): Promise { + const today = new Date(); + const oneDayAgo = today.setDate(today.getDate() - 1); + + await this.delete({ + lastUpdatedAt: LessThan(new Date(oneDayAgo)), + }); + }, + withTransaction(transactionEntityManager: EntityManager) { const transactionRepository = transactionEntityManager.getRepository(FeeRecordCorrectionTransientFormDataEntity); From d8eb9fd2d070b0a4ed7f6464e1c041e63fed7673 Mon Sep 17 00:00:00 2001 From: Matt <173997080+sw-mattw@users.noreply.github.com> Date: Mon, 3 Feb 2025 13:26:38 +0000 Subject: [PATCH 2/3] feat(FN-3737): simplify naming of deletion job function --- .../index.test.ts | 70 +++++++++++++++---- .../index.ts | 6 +- .../src/cron-scheduler-jobs/index.ts | 4 +- 3 files changed, 60 insertions(+), 20 deletions(-) diff --git a/dtfs-central-api/src/cron-scheduler-jobs/delete-correction-and-correction-request-transient-form-data/index.test.ts b/dtfs-central-api/src/cron-scheduler-jobs/delete-correction-and-correction-request-transient-form-data/index.test.ts index 7a9634b76e..ce415c09d1 100644 --- a/dtfs-central-api/src/cron-scheduler-jobs/delete-correction-and-correction-request-transient-form-data/index.test.ts +++ b/dtfs-central-api/src/cron-scheduler-jobs/delete-correction-and-correction-request-transient-form-data/index.test.ts @@ -1,5 +1,5 @@ import { LessThan } from 'typeorm'; -import { deleteCorrectionAndCorrectionRequestTransientFormData, deleteCorrectionAndCorrectionRequestTransientFormDataJob } from '.'; +import { deleteAllOldCorrectionTransientFormData, deleteAllOldCorrectionTransientFormDataJob } from '.'; import { FeeRecordCorrectionRequestTransientFormDataRepo } from '../../repositories/fee-record-correction-request-transient-form-data-repo/fee-record-correction-request-transient-form-data.repo'; import { FeeRecordCorrectionTransientFormDataRepo } from '../../repositories/fee-record-correction-transient-form-data-repo'; @@ -21,7 +21,7 @@ describe('delete-correction-and-correction-request-transient-form-data', () => { jest.useRealTimers(); }); - describe('deleteCorrectionAndCorrectionRequestTransientFormData', () => { + describe('deleteAllOldCorrectionTransientFormData', () => { beforeEach(() => { jest.useFakeTimers().setSystemTime(new Date('2025-01-02 12:10:00')); @@ -33,9 +33,9 @@ describe('delete-correction-and-correction-request-transient-form-data', () => { jest.resetAllMocks(); }); - it('should delete records older than one day', async () => { + it('should delete "correction transient data" records older than one day', async () => { // Act - await deleteCorrectionAndCorrectionRequestTransientFormData(); + await deleteAllOldCorrectionTransientFormData(); // Assert const expectedDeletionCallArgs = { @@ -44,6 +44,48 @@ describe('delete-correction-and-correction-request-transient-form-data', () => { expect(mockCorrectionDelete).toHaveBeenCalledTimes(1); expect(mockCorrectionDelete).toHaveBeenCalledWith(expectedDeletionCallArgs); + }); + + it('should delete "correction request transient data" records older than one day', async () => { + // Act + await deleteAllOldCorrectionTransientFormData(); + + // Assert + const expectedDeletionCallArgs = { + lastUpdatedAt: LessThan(new Date('2025-01-01:12:10:00')), + }; + + expect(mockCorrectionRequestDelete).toHaveBeenCalledTimes(1); + expect(mockCorrectionRequestDelete).toHaveBeenCalledWith(expectedDeletionCallArgs); + }); + + it('should delete "correction transient data" records older than one day if it is the first day of the month', async () => { + // Arrange + jest.useFakeTimers().setSystemTime(new Date('2025-01-01 12:10:00')); + + // Act + await deleteAllOldCorrectionTransientFormData(); + + // Assert + const expectedDeletionCallArgs = { + lastUpdatedAt: LessThan(new Date('2024-12-31:12:10:00')), + }; + + expect(mockCorrectionDelete).toHaveBeenCalledTimes(1); + expect(mockCorrectionDelete).toHaveBeenCalledWith(expectedDeletionCallArgs); + }); + + it('should delete "correction request transient data" records older than one day if it is the first day of the month', async () => { + // Arrange + jest.useFakeTimers().setSystemTime(new Date('2025-01-01 12:10:00')); + + // Act + await deleteAllOldCorrectionTransientFormData(); + + // Assert + const expectedDeletionCallArgs = { + lastUpdatedAt: LessThan(new Date('2024-12-31:12:10:00')), + }; expect(mockCorrectionRequestDelete).toHaveBeenCalledTimes(1); expect(mockCorrectionRequestDelete).toHaveBeenCalledWith(expectedDeletionCallArgs); @@ -54,7 +96,7 @@ describe('delete-correction-and-correction-request-transient-form-data', () => { jest.useFakeTimers().setSystemTime(new Date('2025-01-01 12:10:00')); // Act - await deleteCorrectionAndCorrectionRequestTransientFormData(); + await deleteAllOldCorrectionTransientFormData(); // Assert const expectedDeletionCallArgs = { @@ -77,7 +119,7 @@ describe('delete-correction-and-correction-request-transient-form-data', () => { jest.mocked(mockCorrectionDelete).mockRejectedValue(error); // Act - await deleteCorrectionAndCorrectionRequestTransientFormData(); + await deleteAllOldCorrectionTransientFormData(); // Assert expect(mockCorrectionDelete).toHaveBeenCalledTimes(1); @@ -91,7 +133,7 @@ describe('delete-correction-and-correction-request-transient-form-data', () => { it('should still call record correction request transient data deletion', async () => { // Act - await deleteCorrectionAndCorrectionRequestTransientFormData(); + await deleteAllOldCorrectionTransientFormData(); // Assert expect(mockCorrectionRequestDelete).toHaveBeenCalledTimes(1); @@ -107,7 +149,7 @@ describe('delete-correction-and-correction-request-transient-form-data', () => { jest.mocked(mockCorrectionRequestDelete).mockRejectedValue(error); // Act - await deleteCorrectionAndCorrectionRequestTransientFormData(); + await deleteAllOldCorrectionTransientFormData(); // Assert expect(mockCorrectionRequestDelete).toHaveBeenCalledTimes(1); @@ -121,7 +163,7 @@ describe('delete-correction-and-correction-request-transient-form-data', () => { it('should still call record correction transient data deletion', async () => { // Act - await deleteCorrectionAndCorrectionRequestTransientFormData(); + await deleteAllOldCorrectionTransientFormData(); // Assert expect(mockCorrectionDelete).toHaveBeenCalledTimes(1); @@ -143,21 +185,19 @@ describe('delete-correction-and-correction-request-transient-form-data', () => { it('should be scheduled to run', () => { // Assert - expect(deleteCorrectionAndCorrectionRequestTransientFormDataJob.cronExpression).toEqual( - process.env.RECORD_CORRECTION_TRANSIENT_FORM_DATA_DELETE_SCHEDULE, - ); + expect(deleteAllOldCorrectionTransientFormDataJob.cronExpression).toEqual(process.env.RECORD_CORRECTION_TRANSIENT_FORM_DATA_DELETE_SCHEDULE); }); it('should have the correct description', () => { // Assert - expect(deleteCorrectionAndCorrectionRequestTransientFormDataJob.description).toEqual( + expect(deleteAllOldCorrectionTransientFormDataJob.description).toEqual( 'Deletes record correction and record correction request transient form data older than 1 day', ); }); it('should call FeeRecordCorrectionTransientFormDataRepo.delete', async () => { // Act - await deleteCorrectionAndCorrectionRequestTransientFormDataJob.task('manual'); + await deleteAllOldCorrectionTransientFormDataJob.task('manual'); // Assert expect(mockCorrectionDelete).toHaveBeenCalledTimes(1); @@ -169,7 +209,7 @@ describe('delete-correction-and-correction-request-transient-form-data', () => { it('should call FeeRecordCorrectionRequestTransientFormDataRepo.delete', async () => { // Act - await deleteCorrectionAndCorrectionRequestTransientFormDataJob.task('manual'); + await deleteAllOldCorrectionTransientFormDataJob.task('manual'); // Assert expect(mockCorrectionRequestDelete).toHaveBeenCalledTimes(1); diff --git a/dtfs-central-api/src/cron-scheduler-jobs/delete-correction-and-correction-request-transient-form-data/index.ts b/dtfs-central-api/src/cron-scheduler-jobs/delete-correction-and-correction-request-transient-form-data/index.ts index d199178d40..6318693e37 100644 --- a/dtfs-central-api/src/cron-scheduler-jobs/delete-correction-and-correction-request-transient-form-data/index.ts +++ b/dtfs-central-api/src/cron-scheduler-jobs/delete-correction-and-correction-request-transient-form-data/index.ts @@ -7,7 +7,7 @@ const { RECORD_CORRECTION_TRANSIENT_FORM_DATA_DELETE_SCHEDULE } = process.env; /** * Deletes record correction and correction request transient form data more than 1 day old. */ -export const deleteCorrectionAndCorrectionRequestTransientFormData = async (): Promise => { +export const deleteAllOldCorrectionTransientFormData = async (): Promise => { console.info('Deleting old transient record corrections and correction requests - deleteCorrectionRequestTransientFormData CRON job'); try { @@ -23,8 +23,8 @@ export const deleteCorrectionAndCorrectionRequestTransientFormData = async (): P } }; -export const deleteCorrectionAndCorrectionRequestTransientFormDataJob: CronSchedulerJob = { +export const deleteAllOldCorrectionTransientFormDataJob: CronSchedulerJob = { cronExpression: asString(RECORD_CORRECTION_TRANSIENT_FORM_DATA_DELETE_SCHEDULE, 'RECORD_CORRECTION_TRANSIENT_FORM_DATA_DELETE_SCHEDULE'), description: 'Deletes record correction and record correction request transient form data older than 1 day', - task: deleteCorrectionAndCorrectionRequestTransientFormData, + task: deleteAllOldCorrectionTransientFormData, }; diff --git a/dtfs-central-api/src/cron-scheduler-jobs/index.ts b/dtfs-central-api/src/cron-scheduler-jobs/index.ts index 07c5c95d52..1b4660ae25 100644 --- a/dtfs-central-api/src/cron-scheduler-jobs/index.ts +++ b/dtfs-central-api/src/cron-scheduler-jobs/index.ts @@ -2,11 +2,11 @@ import { CronSchedulerJob } from '@ukef/dtfs2-common'; import { createUtilisationReportForBanksJob } from './create-utilisation-reports'; import { deleteCompleteAcbsDurableFunctionLogsJob } from './delete-acbs-durable-function-logs'; import { cancelDealJob } from './deal-cancellation/cancel-deal-job'; -import { deleteCorrectionAndCorrectionRequestTransientFormDataJob } from './delete-correction-and-correction-request-transient-form-data'; +import { deleteAllOldCorrectionTransientFormDataJob } from './delete-correction-and-correction-request-transient-form-data'; export const cronSchedulerJobs: CronSchedulerJob[] = [ createUtilisationReportForBanksJob, deleteCompleteAcbsDurableFunctionLogsJob, cancelDealJob, - deleteCorrectionAndCorrectionRequestTransientFormDataJob, + deleteAllOldCorrectionTransientFormDataJob, ]; From 2a4efed92983f25e2d9b900b75cc71104dcf410b Mon Sep 17 00:00:00 2001 From: Matt <173997080+sw-mattw@users.noreply.github.com> Date: Mon, 3 Feb 2025 14:14:49 +0000 Subject: [PATCH 3/3] feat(FN-3737): remove redundant test --- .../index.test.ts | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/dtfs-central-api/src/cron-scheduler-jobs/delete-correction-and-correction-request-transient-form-data/index.test.ts b/dtfs-central-api/src/cron-scheduler-jobs/delete-correction-and-correction-request-transient-form-data/index.test.ts index ce415c09d1..2a589caa0f 100644 --- a/dtfs-central-api/src/cron-scheduler-jobs/delete-correction-and-correction-request-transient-form-data/index.test.ts +++ b/dtfs-central-api/src/cron-scheduler-jobs/delete-correction-and-correction-request-transient-form-data/index.test.ts @@ -91,25 +91,6 @@ describe('delete-correction-and-correction-request-transient-form-data', () => { expect(mockCorrectionRequestDelete).toHaveBeenCalledWith(expectedDeletionCallArgs); }); - it('should delete records older than one day if it is the first day of the month', async () => { - // Arrange - jest.useFakeTimers().setSystemTime(new Date('2025-01-01 12:10:00')); - - // Act - await deleteAllOldCorrectionTransientFormData(); - - // Assert - const expectedDeletionCallArgs = { - lastUpdatedAt: LessThan(new Date('2024-12-31:12:10:00')), - }; - - expect(mockCorrectionDelete).toHaveBeenCalledTimes(1); - expect(mockCorrectionDelete).toHaveBeenCalledWith(expectedDeletionCallArgs); - - expect(mockCorrectionRequestDelete).toHaveBeenCalledTimes(1); - expect(mockCorrectionRequestDelete).toHaveBeenCalledWith(expectedDeletionCallArgs); - }); - describe('when record correction transient data deletion fails', () => { it('should throw an error', async () => { // Arrange