diff --git a/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/application-changes-report-integration/_tests_/application-changes-report-integration.scheduler.e2e-spec.ts b/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/application-changes-report-integration/_tests_/application-changes-report-integration.scheduler.e2e-spec.ts index 7ddce83bc9..e45f0f85e5 100644 --- a/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/application-changes-report-integration/_tests_/application-changes-report-integration.scheduler.e2e-spec.ts +++ b/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/application-changes-report-integration/_tests_/application-changes-report-integration.scheduler.e2e-spec.ts @@ -39,6 +39,8 @@ import { ApplicationChangesReportHeaders, APPLICATION_CHANGES_DATE_TIME_FORMAT, } from "@sims/integrations/esdc-integration"; +import MockDate from "mockdate"; +import * as dayjs from "dayjs"; describe( describeProcessorRootTest(QueueNames.ApplicationChangesReportIntegration), @@ -49,6 +51,7 @@ describe( let sftpClientMock: DeepMocked; let auditUser: User; let sharedStudent: Student; + let expectedFileName: string; beforeAll(async () => { const { nestApplication, dataSource, sshClientMock } = @@ -70,6 +73,10 @@ describe( }, { previousDateChangedReportedAssessment: { id: null } }, ); + // Mock the current date. + const now = new Date(); + MockDate.set(now); + expectedFileName = `DPBC.EDU.APPCHANGES.${formatFileNameDate(now)}.csv`; }); it("Should generate application changes report and update the reported date when there is one or more application changes which are not reported.", async () => { @@ -89,16 +96,14 @@ describe( const mockedJob = mockBullJob(); // Act - const processingResult = await processor.processApplicationChanges( - mockedJob.job, - ); + const result = await processor.processQueue(mockedJob.job); + // Assert // Assert process result. - expect(processingResult).toContain("Process finalized with success."); - expect(processingResult).toContain("Applications reported: 2"); - expect( - mockedJob.containLogMessages(["Found 2 application changes."]), - ).toBe(true); + expect(result).toStrictEqual([ + "Applications reported: 2", + `Uploaded file name: ${expectedFileName}`, + ]); const uploadedFile = getUploadedFile(sftpClientMock); const expectedFirstRecord = getExpectedApplicationChangesCSVRecord( firstApplication, @@ -176,16 +181,13 @@ describe( const mockedJob = mockBullJob(); // Act - const processingResult = await processor.processApplicationChanges( - mockedJob.job, - ); + const result = await processor.processQueue(mockedJob.job); // Assert // Assert process result. - expect(processingResult).toContain("Process finalized with success."); - expect(processingResult).toContain("Applications reported: 1"); - expect( - mockedJob.containLogMessages(["Found 1 application changes."]), - ).toBe(true); + expect(result).toStrictEqual([ + "Applications reported: 1", + `Uploaded file name: ${expectedFileName}`, + ]); const uploadedFile = getUploadedFile(sftpClientMock); const expectedFirstRecord = getExpectedApplicationChangesCSVRecord( application, @@ -226,16 +228,19 @@ describe( const mockedJob = mockBullJob(); // Act - const processingResult = await processor.processApplicationChanges( - mockedJob.job, - ); + const result = await processor.processQueue(mockedJob.job); + // Assert // Assert process result. - expect(processingResult).toContain("Process finalized with success."); - expect(processingResult).toContain("Applications reported: 0"); + expect(result).toStrictEqual([ + "Applications reported: 0", + `Uploaded file name: ${expectedFileName}`, + ]); expect( mockedJob.containLogMessages([ + "Retrieving all application changes which were not reported already.", "Found 0 application changes.", + `Application changes report with file name ${expectedFileName} has been uploaded successfully.`, "Report date update not required as no application changes are reported.", ]), ).toBe(true); @@ -397,5 +402,14 @@ describe( newOffering.studyEndDate, ].join(","); } + + /** + * Format date to be used in file name. + * @param date date. + * @returns file name date format. + */ + function formatFileNameDate(date: Date): string { + return dayjs(date).format("YYYY-MM-DD_HH.mm.ss"); + } }, ); diff --git a/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/application-changes-report-integration/application-changes-report-integration.scheduler.ts b/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/application-changes-report-integration/application-changes-report-integration.scheduler.ts index 5f09581111..0f906cfdb6 100644 --- a/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/application-changes-report-integration/application-changes-report-integration.scheduler.ts +++ b/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/application-changes-report-integration/application-changes-report-integration.scheduler.ts @@ -1,4 +1,4 @@ -import { InjectQueue, Process, Processor } from "@nestjs/bull"; +import { InjectQueue, Processor } from "@nestjs/bull"; import { QueueService } from "@sims/services/queue"; import { Job, Queue } from "bull"; import { BaseScheduler } from "../../base-scheduler"; @@ -7,10 +7,6 @@ import { LoggerService, ProcessSummary, } from "@sims/utilities/logger"; -import { - getSuccessMessageWithAttentionCheck, - logProcessSummaryToJobLogger, -} from "../../../../utilities"; import { QueueNames } from "@sims/utilities"; import { ApplicationChangesReportProcessingService } from "@sims/integrations/esdc-integration"; @@ -25,65 +21,36 @@ export class ApplicationChangesReportIntegrationScheduler extends BaseScheduler< super(schedulerQueue, queueService); } - /** - * To be removed once the method {@link process} is implemented. - * This method "hides" the {@link Process} decorator from the base class. - */ - async processQueue(): Promise { - throw new Error("Method not implemented."); - } - - /** - * When implemented in a derived class, process the queue job. - * To be implemented. - */ - protected async process(): Promise { - throw new Error("Method not implemented."); - } - /** * Generate application changes report for the applications which has at least one e-Cert sent * and the application study dates have changed after the first e-Cert * or after the last time the application was reported for study dates change * through application changes report. Once generated upload the report to the ESDC directory * in SFTP server. - * @param job job. + * @param _job process job. + * @param processSummary process summary for logging. * @returns process summary. */ - @Process() - async processApplicationChanges(job: Job): Promise { - const processSummary = new ProcessSummary(); - - try { - processSummary.info( - `Processing application changes report integration job. Job id: ${job.id} and Job name: ${job.name}.`, - ); - const integrationProcessSummary = new ProcessSummary(); - processSummary.children(integrationProcessSummary); - const { applicationsReported, uploadedFileName } = - await this.applicationChangesReportProcessingService.processApplicationChanges( - integrationProcessSummary, - ); - return getSuccessMessageWithAttentionCheck( - [ - "Process finalized with success.", - `Applications reported: ${applicationsReported}`, - `Uploaded file name: ${uploadedFileName}`, - ], + protected async process( + _job: Job, + processSummary: ProcessSummary, + ): Promise { + const { applicationsReported, uploadedFileName } = + await this.applicationChangesReportProcessingService.processApplicationChanges( processSummary, ); - } catch (error: unknown) { - // Translate to friendly error message. - const errorMessage = - "Unexpected error while executing the job to process application changes."; - processSummary.error(errorMessage, error); - throw new Error(errorMessage, { cause: error }); - } finally { - this.logger.logProcessSummary(processSummary); - await logProcessSummaryToJobLogger(processSummary, job); - } + return [ + `Applications reported: ${applicationsReported}`, + `Uploaded file name: ${uploadedFileName}`, + ]; } + /** + * Setting the logger here allows the correct context to be set + * during the property injection. + * Even if the logger is not used, it is required to be set, to + * allow the base classes to write logs using the correct context. + */ @InjectLogger() logger: LoggerService; }