From e6d2d2a2a92c29da774ed21a9fd5a8da522303e8 Mon Sep 17 00:00:00 2001 From: Ashish Date: Mon, 30 Dec 2024 11:08:49 -0800 Subject: [PATCH 01/10] ecert fix --- .../e-cert-integration/e-cert-file-handler.ts | 26 ++----------------- 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/sources/packages/backend/libs/integrations/src/esdc-integration/e-cert-integration/e-cert-file-handler.ts b/sources/packages/backend/libs/integrations/src/esdc-integration/e-cert-integration/e-cert-file-handler.ts index e35c2ebc03..ec0a48388e 100644 --- a/sources/packages/backend/libs/integrations/src/esdc-integration/e-cert-integration/e-cert-file-handler.ts +++ b/sources/packages/backend/libs/integrations/src/esdc-integration/e-cert-integration/e-cert-file-handler.ts @@ -28,14 +28,6 @@ import { ECertGenerationService } from "@sims/integrations/services"; import { ECertResponseRecord } from "./e-cert-files/e-cert-response-record"; import * as path from "path"; -/** - * Used to abort the e-Cert generation process, cancel the current transaction, - * and let the consumer method know that it was aborted because no records are - * present to be processed. - */ -const ECERT_GENERATION_NO_RECORDS_AVAILABLE = - "ECERT_GENERATION_NO_RECORDS_AVAILABLE"; - /** * Error details: error id and block funding info * for each error code. @@ -121,10 +113,7 @@ export abstract class ECertFileHandler extends ESDCFileHandler { ); return uploadResult; } catch (error: unknown) { - if ( - error instanceof CustomNamedError && - error.name === ECERT_GENERATION_NO_RECORDS_AVAILABLE - ) { + if (error instanceof CustomNamedError) { return { generatedFile: "none", uploadedRecords: 0, @@ -144,7 +133,6 @@ export abstract class ECertFileHandler extends ESDCFileHandler { * @param fileCode file code applicable for Part-Time or Full-Time. * @param log cumulative process log. * @returns information of the uploaded e-Cert file. - * @throws CustomNamedError ECERT_GENERATION_NO_RECORDS_AVAILABLE */ private async processECert( sequenceNumber: number, @@ -160,13 +148,6 @@ export abstract class ECertFileHandler extends ESDCFileHandler { offeringIntensity, entityManager, ); - if (!disbursements.length) { - // Throws an exception to cancel the transaction and DB lock started by `consumeNextSequence`. - throw new CustomNamedError( - `There are no records available to generate an e-Cert file for ${offeringIntensity}`, - ECERT_GENERATION_NO_RECORDS_AVAILABLE, - ); - } log.info( `Found ${disbursements.length} ${offeringIntensity} disbursements schedules.`, ); @@ -207,10 +188,7 @@ export abstract class ECertFileHandler extends ESDCFileHandler { uploadedRecords: disbursementRecords.length, }; } catch (error: unknown) { - if ( - error instanceof CustomNamedError && - error.name !== ECERT_GENERATION_NO_RECORDS_AVAILABLE - ) { + if (error instanceof CustomNamedError) { log.error( `Error while uploading content for ${offeringIntensity} e-Cert file: ${parseJSONError( error, From b44b4fab55f2e2b84cefe1717e67c3d3c4d98961 Mon Sep 17 00:00:00 2001 From: Ashish Date: Mon, 30 Dec 2024 12:23:02 -0800 Subject: [PATCH 02/10] update e2e --- ...-process-integration.scheduler.e2e-spec.ts | 32 ++++++++- ...-process-integration.scheduler.e2e-spec.ts | 68 +++++++++++++++++-- 2 files changed, 92 insertions(+), 8 deletions(-) diff --git a/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-full-time-process-integration.scheduler.e2e-spec.ts b/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-full-time-process-integration.scheduler.e2e-spec.ts index 60d4776106..df72e8a2e0 100644 --- a/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-full-time-process-integration.scheduler.e2e-spec.ts +++ b/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-full-time-process-integration.scheduler.e2e-spec.ts @@ -197,6 +197,25 @@ describe( // TODO Add other fields as needed. }); + it("Should generate disbursement file with formatted records when there is no data for the ecert generation.", async () => { + // Queued job. + const { job } = mockBullJob(); + + // Act + const result = await processor.processECert(job); + + // Assert uploaded file. + const uploadedFile = getUploadedFile(sftpClientMock); + const fileDate = dayjs().format("YYYYMMDD"); + const uploadedFileName = `MSFT-Request\\DPBC.EDU.FTECERTS.${fileDate}.001`; + expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); + expect(result).toStrictEqual([ + "Process finalized with success.", + `Generated file: ${uploadedFileName}`, + "Uploaded records: 0", + ]); + }); + it("Should execute overawards deductions and calculate awards effective value", async () => { // Arrange @@ -796,9 +815,13 @@ describe( const result = await processor.processECert(job); // Assert 0 uploaded records. + const uploadedFile = getUploadedFile(sftpClientMock); + const fileDate = dayjs().format("YYYYMMDD"); + const uploadedFileName = `MSFT-Request\\DPBC.EDU.FTECERTS.${fileDate}.001`; + expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); expect(result).toStrictEqual([ "Process finalized with success.", - "Generated file: none", + `Generated file: ${uploadedFileName}`, "Uploaded records: 0", ]); const [disbursement] = @@ -1343,10 +1366,15 @@ describe( // Act const result = await processor.processECert(mockedJob.job); + // Assert uploaded file. + const uploadedFile = getUploadedFile(sftpClientMock); + const fileDate = dayjs().format("YYYYMMDD"); + const uploadedFileName = `MSFT-Request\\DPBC.EDU.FTECERTS.${fileDate}.001`; + expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); // Assert expect(result).toStrictEqual([ "Process finalized with success.", - "Generated file: none", + `Generated file: ${uploadedFileName}`, "Uploaded records: 0", ]); expect( diff --git a/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-part-time-process-integration.scheduler.e2e-spec.ts b/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-part-time-process-integration.scheduler.e2e-spec.ts index f6dddb456a..af8bfde3e8 100644 --- a/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-part-time-process-integration.scheduler.e2e-spec.ts +++ b/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-part-time-process-integration.scheduler.e2e-spec.ts @@ -113,10 +113,16 @@ describe( // Act const result = await processor.processECert(mockedJob.job); + // Assert uploaded file. + const uploadedFile = getUploadedFile(sftpClientMock); + const fileDate = dayjs().format("YYYYMMDD"); + const uploadedFileName = `MSFT-Request\\DPBC.EDU.NEW.PTCERTS.D${fileDate}.001`; + expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); + // Assert expect(result).toStrictEqual([ "Process finalized with success.", - "Generated file: none", + `Generated file: ${uploadedFileName}`, "Uploaded records: 0", ]); expect( @@ -174,10 +180,15 @@ describe( // Act const result = await processor.processECert(mockedJob.job); + // Assert uploaded file. + const uploadedFile = getUploadedFile(sftpClientMock); + const fileDate = dayjs().format("YYYYMMDD"); + const uploadedFileName = `MSFT-Request\\DPBC.EDU.NEW.PTCERTS.D${fileDate}.001`; + expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); // Assert expect(result).toStrictEqual([ "Process finalized with success.", - "Generated file: none", + `Generated file: ${uploadedFileName}`, "Uploaded records: 0", ]); expect( @@ -235,10 +246,16 @@ describe( // Act const result = await processor.processECert(mockedJob.job); + // Assert uploaded file. + const uploadedFile = getUploadedFile(sftpClientMock); + const fileDate = dayjs().format("YYYYMMDD"); + const uploadedFileName = `MSFT-Request\\DPBC.EDU.NEW.PTCERTS.D${fileDate}.001`; + expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); + // Assert expect(result).toStrictEqual([ "Process finalized with success.", - "Generated file: none", + `Generated file: ${uploadedFileName}`, "Uploaded records: 0", ]); const notificationsCount = await db.notification.count({ @@ -265,10 +282,16 @@ describe( // Act const result = await processor.processECert(mockedJob.job); + // Assert uploaded file. + const uploadedFile = getUploadedFile(sftpClientMock); + const fileDate = dayjs().format("YYYYMMDD"); + const uploadedFileName = `MSFT-Request\\DPBC.EDU.NEW.PTCERTS.D${fileDate}.001`; + expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); + // Assert expect(result).toStrictEqual([ "Process finalized with success.", - "Generated file: none", + `Generated file: ${uploadedFileName}`, "Uploaded records: 0", ]); const notificationsCount = await db.notification.count({ @@ -298,10 +321,16 @@ describe( // Act const result = await processor.processECert(mockedJob.job); + // Assert uploaded file. + const uploadedFile = getUploadedFile(sftpClientMock); + const fileDate = dayjs().format("YYYYMMDD"); + const uploadedFileName = `MSFT-Request\\DPBC.EDU.NEW.PTCERTS.D${fileDate}.001`; + expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); + // Assert expect(result).toStrictEqual([ "Process finalized with success.", - "Generated file: none", + `Generated file: ${uploadedFileName}`, "Uploaded records: 0", ]); expect( @@ -414,6 +443,27 @@ describe( expect(scheduleIsSent).toBe(true); }); + it("Should generate disbursement file with formatted records when there is no data for the ecert generation.", async () => { + // Queued job. + const { job } = mockBullJob(); + + // Act + const result = await processor.processECert(job); + + // Assert + + // Assert uploaded file. + const uploadedFile = getUploadedFile(sftpClientMock); + const fileDate = dayjs().format("YYYYMMDD"); + const uploadedFileName = `MSFT-Request\\DPBC.EDU.NEW.PTCERTS.D${fileDate}.001`; + expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); + expect(result).toStrictEqual([ + "Process finalized with success.", + `Generated file: ${uploadedFileName}`, + "Uploaded records: 0", + ]); + }); + it("Should create an e-Cert with valid student profile data when the student has necessary profile data and gender defined as 'Prefer not to answer'.", async () => { // Arrange // Student with valid SIN. @@ -800,10 +850,16 @@ describe( // Act const result = await processor.processECert(job); + // Assert uploaded file. + const uploadedFile = getUploadedFile(sftpClientMock); + const fileDate = dayjs().format("YYYYMMDD"); + const uploadedFileName = `MSFT-Request\\DPBC.EDU.NEW.PTCERTS.D${fileDate}.001`; + expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); + // Assert expect(result).toStrictEqual([ "Process finalized with success.", - "Generated file: none", + `Generated file: ${uploadedFileName}`, "Uploaded records: 0", ]); const [disbursement] = From 4f4e299522ae82d8319efa1765ee4297dafdee7c Mon Sep 17 00:00:00 2001 From: Ashish Date: Mon, 30 Dec 2024 11:08:49 -0800 Subject: [PATCH 03/10] ecert fix --- .../e-cert-integration/e-cert-file-handler.ts | 26 ++----------------- 1 file changed, 2 insertions(+), 24 deletions(-) diff --git a/sources/packages/backend/libs/integrations/src/esdc-integration/e-cert-integration/e-cert-file-handler.ts b/sources/packages/backend/libs/integrations/src/esdc-integration/e-cert-integration/e-cert-file-handler.ts index e35c2ebc03..ec0a48388e 100644 --- a/sources/packages/backend/libs/integrations/src/esdc-integration/e-cert-integration/e-cert-file-handler.ts +++ b/sources/packages/backend/libs/integrations/src/esdc-integration/e-cert-integration/e-cert-file-handler.ts @@ -28,14 +28,6 @@ import { ECertGenerationService } from "@sims/integrations/services"; import { ECertResponseRecord } from "./e-cert-files/e-cert-response-record"; import * as path from "path"; -/** - * Used to abort the e-Cert generation process, cancel the current transaction, - * and let the consumer method know that it was aborted because no records are - * present to be processed. - */ -const ECERT_GENERATION_NO_RECORDS_AVAILABLE = - "ECERT_GENERATION_NO_RECORDS_AVAILABLE"; - /** * Error details: error id and block funding info * for each error code. @@ -121,10 +113,7 @@ export abstract class ECertFileHandler extends ESDCFileHandler { ); return uploadResult; } catch (error: unknown) { - if ( - error instanceof CustomNamedError && - error.name === ECERT_GENERATION_NO_RECORDS_AVAILABLE - ) { + if (error instanceof CustomNamedError) { return { generatedFile: "none", uploadedRecords: 0, @@ -144,7 +133,6 @@ export abstract class ECertFileHandler extends ESDCFileHandler { * @param fileCode file code applicable for Part-Time or Full-Time. * @param log cumulative process log. * @returns information of the uploaded e-Cert file. - * @throws CustomNamedError ECERT_GENERATION_NO_RECORDS_AVAILABLE */ private async processECert( sequenceNumber: number, @@ -160,13 +148,6 @@ export abstract class ECertFileHandler extends ESDCFileHandler { offeringIntensity, entityManager, ); - if (!disbursements.length) { - // Throws an exception to cancel the transaction and DB lock started by `consumeNextSequence`. - throw new CustomNamedError( - `There are no records available to generate an e-Cert file for ${offeringIntensity}`, - ECERT_GENERATION_NO_RECORDS_AVAILABLE, - ); - } log.info( `Found ${disbursements.length} ${offeringIntensity} disbursements schedules.`, ); @@ -207,10 +188,7 @@ export abstract class ECertFileHandler extends ESDCFileHandler { uploadedRecords: disbursementRecords.length, }; } catch (error: unknown) { - if ( - error instanceof CustomNamedError && - error.name !== ECERT_GENERATION_NO_RECORDS_AVAILABLE - ) { + if (error instanceof CustomNamedError) { log.error( `Error while uploading content for ${offeringIntensity} e-Cert file: ${parseJSONError( error, From b1981df13b3d1b3dc22fc895c1a77ebffbd6bd3c Mon Sep 17 00:00:00 2001 From: Ashish Date: Mon, 30 Dec 2024 12:23:02 -0800 Subject: [PATCH 04/10] update e2e --- ...-process-integration.scheduler.e2e-spec.ts | 34 ++++++++- ...-process-integration.scheduler.e2e-spec.ts | 74 +++++++++++++++++-- 2 files changed, 100 insertions(+), 8 deletions(-) diff --git a/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-full-time-process-integration.scheduler.e2e-spec.ts b/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-full-time-process-integration.scheduler.e2e-spec.ts index 21ecac1d9a..0293a1fd50 100644 --- a/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-full-time-process-integration.scheduler.e2e-spec.ts +++ b/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-full-time-process-integration.scheduler.e2e-spec.ts @@ -196,6 +196,25 @@ describe( // TODO Add other fields as needed. }); + it("Should generate disbursement file with formatted records when there is no data for the ecert generation.", async () => { + // Queued job. + const { job } = mockBullJob(); + + // Act + const result = await processor.processECert(job); + + // Assert uploaded file. + const uploadedFile = getUploadedFile(sftpClientMock); + const fileDate = dayjs().format("YYYYMMDD"); + const uploadedFileName = `MSFT-Request\\DPBC.EDU.FTECERTS.${fileDate}.001`; + expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); + expect(result).toStrictEqual([ + "Process finalized with success.", + `Generated file: ${uploadedFileName}`, + "Uploaded records: 0", + ]); + }); + it("Should execute overawards deductions and calculate awards effective value", async () => { // Arrange @@ -792,8 +811,13 @@ describe( const result = await processor.processQueue(job); // Assert 0 uploaded records. + const uploadedFile = getUploadedFile(sftpClientMock); + const fileDate = dayjs().format("YYYYMMDD"); + const uploadedFileName = `MSFT-Request\\DPBC.EDU.FTECERTS.${fileDate}.001`; + expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); expect(result).toStrictEqual([ - "Generated file: none", + "Process finalized with success.", + `Generated file: ${uploadedFileName}`, "Uploaded records: 0", ]); const [disbursement] = @@ -1336,9 +1360,15 @@ describe( // Act const result = await processor.processQueue(mockedJob.job); + // Assert uploaded file. + const uploadedFile = getUploadedFile(sftpClientMock); + const fileDate = dayjs().format("YYYYMMDD"); + const uploadedFileName = `MSFT-Request\\DPBC.EDU.FTECERTS.${fileDate}.001`; + expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); // Assert expect(result).toStrictEqual([ - "Generated file: none", + "Process finalized with success.", + `Generated file: ${uploadedFileName}`, "Uploaded records: 0", ]); expect( diff --git a/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-part-time-process-integration.scheduler.e2e-spec.ts b/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-part-time-process-integration.scheduler.e2e-spec.ts index df98383e4b..8ef90ba524 100644 --- a/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-part-time-process-integration.scheduler.e2e-spec.ts +++ b/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-part-time-process-integration.scheduler.e2e-spec.ts @@ -113,9 +113,16 @@ describe( // Act const result = await processor.processQueue(mockedJob.job); + // Assert uploaded file. + const uploadedFile = getUploadedFile(sftpClientMock); + const fileDate = dayjs().format("YYYYMMDD"); + const uploadedFileName = `MSFT-Request\\DPBC.EDU.NEW.PTCERTS.D${fileDate}.001`; + expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); + // Assert expect(result).toStrictEqual([ - "Generated file: none", + "Process finalized with success.", + `Generated file: ${uploadedFileName}`, "Uploaded records: 0", ]); expect( @@ -173,9 +180,15 @@ describe( // Act const result = await processor.processQueue(mockedJob.job); + // Assert uploaded file. + const uploadedFile = getUploadedFile(sftpClientMock); + const fileDate = dayjs().format("YYYYMMDD"); + const uploadedFileName = `MSFT-Request\\DPBC.EDU.NEW.PTCERTS.D${fileDate}.001`; + expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); // Assert expect(result).toStrictEqual([ - "Generated file: none", + "Process finalized with success.", + `Generated file: ${uploadedFileName}`, "Uploaded records: 0", ]); expect( @@ -233,9 +246,16 @@ describe( // Act const result = await processor.processQueue(mockedJob.job); + // Assert uploaded file. + const uploadedFile = getUploadedFile(sftpClientMock); + const fileDate = dayjs().format("YYYYMMDD"); + const uploadedFileName = `MSFT-Request\\DPBC.EDU.NEW.PTCERTS.D${fileDate}.001`; + expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); + // Assert expect(result).toStrictEqual([ - "Generated file: none", + "Process finalized with success.", + `Generated file: ${uploadedFileName}`, "Uploaded records: 0", ]); const notificationsCount = await db.notification.count({ @@ -262,9 +282,16 @@ describe( // Act const result = await processor.processQueue(mockedJob.job); + // Assert uploaded file. + const uploadedFile = getUploadedFile(sftpClientMock); + const fileDate = dayjs().format("YYYYMMDD"); + const uploadedFileName = `MSFT-Request\\DPBC.EDU.NEW.PTCERTS.D${fileDate}.001`; + expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); + // Assert expect(result).toStrictEqual([ - "Generated file: none", + "Process finalized with success.", + `Generated file: ${uploadedFileName}`, "Uploaded records: 0", ]); const notificationsCount = await db.notification.count({ @@ -294,9 +321,16 @@ describe( // Act const result = await processor.processQueue(mockedJob.job); + // Assert uploaded file. + const uploadedFile = getUploadedFile(sftpClientMock); + const fileDate = dayjs().format("YYYYMMDD"); + const uploadedFileName = `MSFT-Request\\DPBC.EDU.NEW.PTCERTS.D${fileDate}.001`; + expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); + // Assert expect(result).toStrictEqual([ - "Generated file: none", + "Process finalized with success.", + `Generated file: ${uploadedFileName}`, "Uploaded records: 0", ]); expect( @@ -408,6 +442,27 @@ describe( expect(scheduleIsSent).toBe(true); }); + it("Should generate disbursement file with formatted records when there is no data for the ecert generation.", async () => { + // Queued job. + const { job } = mockBullJob(); + + // Act + const result = await processor.processECert(job); + + // Assert + + // Assert uploaded file. + const uploadedFile = getUploadedFile(sftpClientMock); + const fileDate = dayjs().format("YYYYMMDD"); + const uploadedFileName = `MSFT-Request\\DPBC.EDU.NEW.PTCERTS.D${fileDate}.001`; + expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); + expect(result).toStrictEqual([ + "Process finalized with success.", + `Generated file: ${uploadedFileName}`, + "Uploaded records: 0", + ]); + }); + it("Should create an e-Cert with valid student profile data when the student has necessary profile data and gender defined as 'Prefer not to answer'.", async () => { // Arrange // Student with valid SIN. @@ -792,9 +847,16 @@ describe( // Act const result = await processor.processQueue(job); + // Assert uploaded file. + const uploadedFile = getUploadedFile(sftpClientMock); + const fileDate = dayjs().format("YYYYMMDD"); + const uploadedFileName = `MSFT-Request\\DPBC.EDU.NEW.PTCERTS.D${fileDate}.001`; + expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); + // Assert expect(result).toStrictEqual([ - "Generated file: none", + "Process finalized with success.", + `Generated file: ${uploadedFileName}`, "Uploaded records: 0", ]); const [disbursement] = From 25e445b18ed837646e80985bbe174c6812ff9c01 Mon Sep 17 00:00:00 2001 From: Ashish Date: Mon, 30 Dec 2024 12:33:04 -0800 Subject: [PATCH 05/10] remove extra --- ...-process-integration.scheduler.e2e-spec.ts | 24 ------------------- 1 file changed, 24 deletions(-) diff --git a/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-part-time-process-integration.scheduler.e2e-spec.ts b/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-part-time-process-integration.scheduler.e2e-spec.ts index 2e3a9d823a..f91d1c0479 100644 --- a/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-part-time-process-integration.scheduler.e2e-spec.ts +++ b/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-part-time-process-integration.scheduler.e2e-spec.ts @@ -119,12 +119,6 @@ describe( const uploadedFileName = `MSFT-Request\\DPBC.EDU.NEW.PTCERTS.D${fileDate}.001`; expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); - // Assert uploaded file. - const uploadedFile = getUploadedFile(sftpClientMock); - const fileDate = dayjs().format("YYYYMMDD"); - const uploadedFileName = `MSFT-Request\\DPBC.EDU.NEW.PTCERTS.D${fileDate}.001`; - expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); - // Assert expect(result).toStrictEqual([ "Process finalized with success.", @@ -258,12 +252,6 @@ describe( const uploadedFileName = `MSFT-Request\\DPBC.EDU.NEW.PTCERTS.D${fileDate}.001`; expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); - // Assert uploaded file. - const uploadedFile = getUploadedFile(sftpClientMock); - const fileDate = dayjs().format("YYYYMMDD"); - const uploadedFileName = `MSFT-Request\\DPBC.EDU.NEW.PTCERTS.D${fileDate}.001`; - expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); - // Assert expect(result).toStrictEqual([ "Process finalized with success.", @@ -300,12 +288,6 @@ describe( const uploadedFileName = `MSFT-Request\\DPBC.EDU.NEW.PTCERTS.D${fileDate}.001`; expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); - // Assert uploaded file. - const uploadedFile = getUploadedFile(sftpClientMock); - const fileDate = dayjs().format("YYYYMMDD"); - const uploadedFileName = `MSFT-Request\\DPBC.EDU.NEW.PTCERTS.D${fileDate}.001`; - expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); - // Assert expect(result).toStrictEqual([ "Process finalized with success.", @@ -877,12 +859,6 @@ describe( const uploadedFileName = `MSFT-Request\\DPBC.EDU.NEW.PTCERTS.D${fileDate}.001`; expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); - // Assert uploaded file. - const uploadedFile = getUploadedFile(sftpClientMock); - const fileDate = dayjs().format("YYYYMMDD"); - const uploadedFileName = `MSFT-Request\\DPBC.EDU.NEW.PTCERTS.D${fileDate}.001`; - expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); - // Assert expect(result).toStrictEqual([ "Process finalized with success.", From f75dba56dbf78b6ff7c33346fdf523736689f6ca Mon Sep 17 00:00:00 2001 From: Ashish Date: Mon, 30 Dec 2024 12:36:06 -0800 Subject: [PATCH 06/10] fix formatting --- ...rt-full-time-process-integration.scheduler.e2e-spec.ts | 6 ++---- ...rt-part-time-process-integration.scheduler.e2e-spec.ts | 8 +------- 2 files changed, 3 insertions(+), 11 deletions(-) diff --git a/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-full-time-process-integration.scheduler.e2e-spec.ts b/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-full-time-process-integration.scheduler.e2e-spec.ts index 0293a1fd50..62c571bb9e 100644 --- a/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-full-time-process-integration.scheduler.e2e-spec.ts +++ b/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-full-time-process-integration.scheduler.e2e-spec.ts @@ -201,7 +201,7 @@ describe( const { job } = mockBullJob(); // Act - const result = await processor.processECert(job); + const result = await processor.processQueue(job); // Assert uploaded file. const uploadedFile = getUploadedFile(sftpClientMock); @@ -285,8 +285,6 @@ describe( // Act const result = await processor.processQueue(job); - // Assert - // Assert uploaded file. const uploadedFile = getUploadedFile(sftpClientMock); const fileDate = dayjs().format("YYYYMMDD"); @@ -810,7 +808,7 @@ describe( // Act const result = await processor.processQueue(job); - // Assert 0 uploaded records. + // Assert uploaded file. const uploadedFile = getUploadedFile(sftpClientMock); const fileDate = dayjs().format("YYYYMMDD"); const uploadedFileName = `MSFT-Request\\DPBC.EDU.FTECERTS.${fileDate}.001`; diff --git a/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-part-time-process-integration.scheduler.e2e-spec.ts b/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-part-time-process-integration.scheduler.e2e-spec.ts index f91d1c0479..edc402483f 100644 --- a/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-part-time-process-integration.scheduler.e2e-spec.ts +++ b/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-part-time-process-integration.scheduler.e2e-spec.ts @@ -406,8 +406,6 @@ describe( // Act const result = await processor.processQueue(job); - // Assert - // Assert uploaded file. const uploadedFile = getUploadedFile(sftpClientMock); const fileDate = dayjs().format("YYYYMMDD"); @@ -453,9 +451,7 @@ describe( const { job } = mockBullJob(); // Act - const result = await processor.processECert(job); - - // Assert + const result = await processor.processQueue(job); // Assert uploaded file. const uploadedFile = getUploadedFile(sftpClientMock); @@ -741,8 +737,6 @@ describe( // Act const result = await processor.processQueue(job); - // Assert - // Assert uploaded file. const uploadedFile = getUploadedFile(sftpClientMock); const fileDate = dayjs().format("YYYYMMDD"); From 159501b2312b5943fa97eda8b1c38a7170c2cfa6 Mon Sep 17 00:00:00 2001 From: Ashish Date: Mon, 30 Dec 2024 12:50:39 -0800 Subject: [PATCH 07/10] fix error message --- ...l-time-process-integration.scheduler.e2e-spec.ts | 3 --- ...t-time-process-integration.scheduler.e2e-spec.ts | 13 ------------- 2 files changed, 16 deletions(-) diff --git a/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-full-time-process-integration.scheduler.e2e-spec.ts b/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-full-time-process-integration.scheduler.e2e-spec.ts index 62c571bb9e..4f9fb174ca 100644 --- a/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-full-time-process-integration.scheduler.e2e-spec.ts +++ b/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-full-time-process-integration.scheduler.e2e-spec.ts @@ -209,7 +209,6 @@ describe( const uploadedFileName = `MSFT-Request\\DPBC.EDU.FTECERTS.${fileDate}.001`; expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); expect(result).toStrictEqual([ - "Process finalized with success.", `Generated file: ${uploadedFileName}`, "Uploaded records: 0", ]); @@ -814,7 +813,6 @@ describe( const uploadedFileName = `MSFT-Request\\DPBC.EDU.FTECERTS.${fileDate}.001`; expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); expect(result).toStrictEqual([ - "Process finalized with success.", `Generated file: ${uploadedFileName}`, "Uploaded records: 0", ]); @@ -1365,7 +1363,6 @@ describe( expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); // Assert expect(result).toStrictEqual([ - "Process finalized with success.", `Generated file: ${uploadedFileName}`, "Uploaded records: 0", ]); diff --git a/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-part-time-process-integration.scheduler.e2e-spec.ts b/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-part-time-process-integration.scheduler.e2e-spec.ts index edc402483f..36279a33d5 100644 --- a/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-part-time-process-integration.scheduler.e2e-spec.ts +++ b/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-part-time-process-integration.scheduler.e2e-spec.ts @@ -121,7 +121,6 @@ describe( // Assert expect(result).toStrictEqual([ - "Process finalized with success.", `Generated file: ${uploadedFileName}`, "Uploaded records: 0", ]); @@ -187,7 +186,6 @@ describe( expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); // Assert expect(result).toStrictEqual([ - "Process finalized with success.", `Generated file: ${uploadedFileName}`, "Uploaded records: 0", ]); @@ -254,7 +252,6 @@ describe( // Assert expect(result).toStrictEqual([ - "Process finalized with success.", `Generated file: ${uploadedFileName}`, "Uploaded records: 0", ]); @@ -290,7 +287,6 @@ describe( // Assert expect(result).toStrictEqual([ - "Process finalized with success.", `Generated file: ${uploadedFileName}`, "Uploaded records: 0", ]); @@ -327,15 +323,8 @@ describe( const uploadedFileName = `MSFT-Request\\DPBC.EDU.NEW.PTCERTS.D${fileDate}.001`; expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); - // Assert uploaded file. - const uploadedFile = getUploadedFile(sftpClientMock); - const fileDate = dayjs().format("YYYYMMDD"); - const uploadedFileName = `MSFT-Request\\DPBC.EDU.NEW.PTCERTS.D${fileDate}.001`; - expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); - // Assert expect(result).toStrictEqual([ - "Process finalized with success.", `Generated file: ${uploadedFileName}`, "Uploaded records: 0", ]); @@ -459,7 +448,6 @@ describe( const uploadedFileName = `MSFT-Request\\DPBC.EDU.NEW.PTCERTS.D${fileDate}.001`; expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); expect(result).toStrictEqual([ - "Process finalized with success.", `Generated file: ${uploadedFileName}`, "Uploaded records: 0", ]); @@ -855,7 +843,6 @@ describe( // Assert expect(result).toStrictEqual([ - "Process finalized with success.", `Generated file: ${uploadedFileName}`, "Uploaded records: 0", ]); From d36add81b4371d5a264911acdc0faf51402f609a Mon Sep 17 00:00:00 2001 From: Ashish Date: Mon, 30 Dec 2024 15:15:27 -0800 Subject: [PATCH 08/10] fix E2E optimization --- ...-process-integration.scheduler.e2e-spec.ts | 49 +++++++++---------- ...-process-integration.scheduler.e2e-spec.ts | 49 ++++++++++--------- 2 files changed, 50 insertions(+), 48 deletions(-) diff --git a/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-full-time-process-integration.scheduler.e2e-spec.ts b/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-full-time-process-integration.scheduler.e2e-spec.ts index 4f9fb174ca..2e703ac4db 100644 --- a/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-full-time-process-integration.scheduler.e2e-spec.ts +++ b/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-full-time-process-integration.scheduler.e2e-spec.ts @@ -106,6 +106,13 @@ describe( ); }); + // Helper function to get the uploaded file name. + function getUploadedFileName() { + const fileDate = dayjs().format("YYYYMMDD"); + const uploadedFileName = `MSFT-Request\\DPBC.EDU.FTECERTS.${fileDate}.001`; + return uploadedFileName; + } + it("Should generate disbursement file with formatted records when there is data for the ecert generation.", async () => { // Arrange const student = await saveFakeStudent( @@ -174,8 +181,7 @@ describe( // Assert uploaded file. const uploadedFile = getUploadedFile(sftpClientMock); - const fileDate = dayjs().format("YYYYMMDD"); - const uploadedFileName = `MSFT-Request\\DPBC.EDU.FTECERTS.${fileDate}.001`; + const uploadedFileName = getUploadedFileName(); expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); expect(result).toStrictEqual([ `Generated file: ${uploadedFileName}`, @@ -196,7 +202,7 @@ describe( // TODO Add other fields as needed. }); - it("Should generate disbursement file with formatted records when there is no data for the ecert generation.", async () => { + it("Should generate an e-cert file with only header and footer when there is no disbursement to be sent.", async () => { // Queued job. const { job } = mockBullJob(); @@ -205,13 +211,19 @@ describe( // Assert uploaded file. const uploadedFile = getUploadedFile(sftpClientMock); - const fileDate = dayjs().format("YYYYMMDD"); - const uploadedFileName = `MSFT-Request\\DPBC.EDU.FTECERTS.${fileDate}.001`; + const uploadedFileName = getUploadedFileName(); expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); expect(result).toStrictEqual([ `Generated file: ${uploadedFileName}`, "Uploaded records: 0", ]); + + // Assert header and footer. + const [header, footer] = uploadedFile.fileLines; + // Validate header. + expect(header).toContain("100BC NEW ENTITLEMENT"); + // Validate footer. + expect(footer.substring(0, 3)).toBe("999"); }); it("Should execute overawards deductions and calculate awards effective value", async () => { @@ -286,8 +298,7 @@ describe( // Assert uploaded file. const uploadedFile = getUploadedFile(sftpClientMock); - const fileDate = dayjs().format("YYYYMMDD"); - const uploadedFileName = `MSFT-Request\\DPBC.EDU.FTECERTS.${fileDate}.001`; + const uploadedFileName = getUploadedFileName(); expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); expect(result).toStrictEqual([ `Generated file: ${uploadedFileName}`, @@ -527,12 +538,8 @@ describe( // Assert uploaded file. const uploadedFile = getUploadedFile(sftpClientMock); - const fileDate = dayjs().format("YYYYMMDD"); - expect(uploadedFile.remoteFilePath).toBe( - `MSFT-Request\\DPBC.EDU.FTECERTS.${fileDate}.001`, - ); expect(uploadedFile.fileLines).toHaveLength(5); - const uploadedFileName = `MSFT-Request\\DPBC.EDU.FTECERTS.${fileDate}.001`; + const uploadedFileName = getUploadedFileName(); expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); expect(result).toStrictEqual([ `Generated file: ${uploadedFileName}`, @@ -714,12 +721,8 @@ describe( // Assert uploaded file. const uploadedFile = getUploadedFile(sftpClientMock); - const fileDate = dayjs().format("YYYYMMDD"); - expect(uploadedFile.remoteFilePath).toBe( - `MSFT-Request\\DPBC.EDU.FTECERTS.${fileDate}.001`, - ); + const uploadedFileName = getUploadedFileName(); expect(uploadedFile.fileLines).toHaveLength(3); - const uploadedFileName = `MSFT-Request\\DPBC.EDU.FTECERTS.${fileDate}.001`; expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); expect(result).toStrictEqual([ `Generated file: ${uploadedFileName}`, @@ -809,8 +812,7 @@ describe( // Assert uploaded file. const uploadedFile = getUploadedFile(sftpClientMock); - const fileDate = dayjs().format("YYYYMMDD"); - const uploadedFileName = `MSFT-Request\\DPBC.EDU.FTECERTS.${fileDate}.001`; + const uploadedFileName = getUploadedFileName(); expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); expect(result).toStrictEqual([ `Generated file: ${uploadedFileName}`, @@ -884,8 +886,7 @@ describe( // Assert uploaded file. const uploadedFile = getUploadedFile(sftpClientMock); - const fileDate = dayjs().format("YYYYMMDD"); - const uploadedFileName = `MSFT-Request\\DPBC.EDU.FTECERTS.${fileDate}.001`; + const uploadedFileName = getUploadedFileName(); expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); expect(result).toStrictEqual([ `Generated file: ${uploadedFileName}`, @@ -953,8 +954,7 @@ describe( // Assert uploaded file. const uploadedFile = getUploadedFile(sftpClientMock); - const fileDate = dayjs().format("YYYYMMDD"); - const uploadedFileName = `MSFT-Request\\DPBC.EDU.FTECERTS.${fileDate}.001`; + const uploadedFileName = getUploadedFileName(); expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); expect(result).toStrictEqual([ `Generated file: ${uploadedFileName}`, @@ -1358,8 +1358,7 @@ describe( // Assert uploaded file. const uploadedFile = getUploadedFile(sftpClientMock); - const fileDate = dayjs().format("YYYYMMDD"); - const uploadedFileName = `MSFT-Request\\DPBC.EDU.FTECERTS.${fileDate}.001`; + const uploadedFileName = getUploadedFileName(); expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); // Assert expect(result).toStrictEqual([ diff --git a/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-part-time-process-integration.scheduler.e2e-spec.ts b/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-part-time-process-integration.scheduler.e2e-spec.ts index 36279a33d5..e08e2242a0 100644 --- a/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-part-time-process-integration.scheduler.e2e-spec.ts +++ b/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-part-time-process-integration.scheduler.e2e-spec.ts @@ -102,6 +102,13 @@ describe( ); }); + // Helper function to get the uploaded file name. + function getUploadedFileName() { + const fileDate = dayjs().format("YYYYMMDD"); + const uploadedFileName = `MSFT-Request\\DPBC.EDU.NEW.PTCERTS.D${fileDate}.001`; + return uploadedFileName; + } + it("Should create a notification for the ministry and student for a blocked disbursement when there are no previously existing notifications for the disbursement.", async () => { // Arrange const { student, disbursement } = await createBlockedDisbursementTestData( @@ -115,8 +122,7 @@ describe( // Assert uploaded file. const uploadedFile = getUploadedFile(sftpClientMock); - const fileDate = dayjs().format("YYYYMMDD"); - const uploadedFileName = `MSFT-Request\\DPBC.EDU.NEW.PTCERTS.D${fileDate}.001`; + const uploadedFileName = getUploadedFileName(); expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); // Assert @@ -181,8 +187,7 @@ describe( // Assert uploaded file. const uploadedFile = getUploadedFile(sftpClientMock); - const fileDate = dayjs().format("YYYYMMDD"); - const uploadedFileName = `MSFT-Request\\DPBC.EDU.NEW.PTCERTS.D${fileDate}.001`; + const uploadedFileName = getUploadedFileName(); expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); // Assert expect(result).toStrictEqual([ @@ -246,8 +251,7 @@ describe( // Assert uploaded file. const uploadedFile = getUploadedFile(sftpClientMock); - const fileDate = dayjs().format("YYYYMMDD"); - const uploadedFileName = `MSFT-Request\\DPBC.EDU.NEW.PTCERTS.D${fileDate}.001`; + const uploadedFileName = getUploadedFileName(); expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); // Assert @@ -281,8 +285,7 @@ describe( // Assert uploaded file. const uploadedFile = getUploadedFile(sftpClientMock); - const fileDate = dayjs().format("YYYYMMDD"); - const uploadedFileName = `MSFT-Request\\DPBC.EDU.NEW.PTCERTS.D${fileDate}.001`; + const uploadedFileName = getUploadedFileName(); expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); // Assert @@ -319,8 +322,7 @@ describe( // Assert uploaded file. const uploadedFile = getUploadedFile(sftpClientMock); - const fileDate = dayjs().format("YYYYMMDD"); - const uploadedFileName = `MSFT-Request\\DPBC.EDU.NEW.PTCERTS.D${fileDate}.001`; + const uploadedFileName = getUploadedFileName(); expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); // Assert @@ -397,8 +399,7 @@ describe( // Assert uploaded file. const uploadedFile = getUploadedFile(sftpClientMock); - const fileDate = dayjs().format("YYYYMMDD"); - const uploadedFileName = `MSFT-Request\\DPBC.EDU.NEW.PTCERTS.D${fileDate}.001`; + const uploadedFileName = getUploadedFileName(); expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); expect(result).toStrictEqual([ `Generated file: ${uploadedFileName}`, @@ -435,7 +436,7 @@ describe( expect(scheduleIsSent).toBe(true); }); - it("Should generate disbursement file with formatted records when there is no data for the ecert generation.", async () => { + it("Should generate an e-cert file with only header and footer when there is no disbursement to be sent.", async () => { // Queued job. const { job } = mockBullJob(); @@ -444,13 +445,19 @@ describe( // Assert uploaded file. const uploadedFile = getUploadedFile(sftpClientMock); - const fileDate = dayjs().format("YYYYMMDD"); - const uploadedFileName = `MSFT-Request\\DPBC.EDU.NEW.PTCERTS.D${fileDate}.001`; + const uploadedFileName = getUploadedFileName(); expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); expect(result).toStrictEqual([ `Generated file: ${uploadedFileName}`, "Uploaded records: 0", ]); + + // Assert header and footer + const [header, footer] = uploadedFile.fileLines; + // Validate header. + expect(header).toContain("01BC NEW PT ENTITLEMENT"); + // Validate footer. + expect(footer.substring(0, 2)).toBe("99"); }); it("Should create an e-Cert with valid student profile data when the student has necessary profile data and gender defined as 'Prefer not to answer'.", async () => { @@ -597,8 +604,7 @@ describe( // Assert // Assert uploaded file. const uploadedFile = getUploadedFile(sftpClientMock); - const fileDate = dayjs().format("YYYYMMDD"); - const uploadedFileName = `MSFT-Request\\DPBC.EDU.NEW.PTCERTS.D${fileDate}.001`; + const uploadedFileName = getUploadedFileName(); expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); expect(result).toStrictEqual([ `Generated file: ${uploadedFileName}`, @@ -727,8 +733,7 @@ describe( // Assert uploaded file. const uploadedFile = getUploadedFile(sftpClientMock); - const fileDate = dayjs().format("YYYYMMDD"); - const uploadedFileName = `MSFT-Request\\DPBC.EDU.NEW.PTCERTS.D${fileDate}.001`; + const uploadedFileName = getUploadedFileName(); expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); expect(result).toStrictEqual([ `Generated file: ${uploadedFileName}`, @@ -837,8 +842,7 @@ describe( // Assert uploaded file. const uploadedFile = getUploadedFile(sftpClientMock); - const fileDate = dayjs().format("YYYYMMDD"); - const uploadedFileName = `MSFT-Request\\DPBC.EDU.NEW.PTCERTS.D${fileDate}.001`; + const uploadedFileName = getUploadedFileName(); expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); // Assert @@ -955,8 +959,7 @@ describe( // Assert // Assert uploaded file. const uploadedFile = getUploadedFile(sftpClientMock); - const fileDate = dayjs().format("YYYYMMDD"); - const uploadedFileName = `MSFT-Request\\DPBC.EDU.NEW.PTCERTS.D${fileDate}.001`; + const uploadedFileName = getUploadedFileName(); expect(uploadedFile.remoteFilePath).toBe(uploadedFileName); expect(result).toStrictEqual([ `Generated file: ${uploadedFileName}`, From 533c328f06fc083964bc0c04e7c2b8300ee1189f Mon Sep 17 00:00:00 2001 From: Ashish Date: Mon, 30 Dec 2024 15:26:26 -0800 Subject: [PATCH 09/10] update E2e --- ...-process-integration.scheduler.e2e-spec.ts | 14 +- ...-process-integration.scheduler.e2e-spec.ts | 14 +- .../e-cert-integration/e-cert-file-handler.ts | 142 +++++++----------- 3 files changed, 71 insertions(+), 99 deletions(-) diff --git a/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-full-time-process-integration.scheduler.e2e-spec.ts b/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-full-time-process-integration.scheduler.e2e-spec.ts index 2e703ac4db..910b74aa37 100644 --- a/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-full-time-process-integration.scheduler.e2e-spec.ts +++ b/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-full-time-process-integration.scheduler.e2e-spec.ts @@ -106,13 +106,6 @@ describe( ); }); - // Helper function to get the uploaded file name. - function getUploadedFileName() { - const fileDate = dayjs().format("YYYYMMDD"); - const uploadedFileName = `MSFT-Request\\DPBC.EDU.FTECERTS.${fileDate}.001`; - return uploadedFileName; - } - it("Should generate disbursement file with formatted records when there is data for the ecert generation.", async () => { // Arrange const student = await saveFakeStudent( @@ -1405,5 +1398,12 @@ describe( ]); }, ); + + // Helper function to get the uploaded file name. + function getUploadedFileName() { + const fileDate = dayjs().format("YYYYMMDD"); + const uploadedFileName = `MSFT-Request\\DPBC.EDU.FTECERTS.${fileDate}.001`; + return uploadedFileName; + } }, ); diff --git a/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-part-time-process-integration.scheduler.e2e-spec.ts b/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-part-time-process-integration.scheduler.e2e-spec.ts index e08e2242a0..d51c81b86d 100644 --- a/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-part-time-process-integration.scheduler.e2e-spec.ts +++ b/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-part-time-process-integration.scheduler.e2e-spec.ts @@ -102,13 +102,6 @@ describe( ); }); - // Helper function to get the uploaded file name. - function getUploadedFileName() { - const fileDate = dayjs().format("YYYYMMDD"); - const uploadedFileName = `MSFT-Request\\DPBC.EDU.NEW.PTCERTS.D${fileDate}.001`; - return uploadedFileName; - } - it("Should create a notification for the ministry and student for a blocked disbursement when there are no previously existing notifications for the disbursement.", async () => { // Arrange const { student, disbursement } = await createBlockedDisbursementTestData( @@ -1495,5 +1488,12 @@ describe( }), ).toBe(true); }); + + // Helper function to get the uploaded file name. + function getUploadedFileName() { + const fileDate = dayjs().format("YYYYMMDD"); + const uploadedFileName = `MSFT-Request\\DPBC.EDU.NEW.PTCERTS.D${fileDate}.001`; + return uploadedFileName; + } }, ); diff --git a/sources/packages/backend/libs/integrations/src/esdc-integration/e-cert-integration/e-cert-file-handler.ts b/sources/packages/backend/libs/integrations/src/esdc-integration/e-cert-integration/e-cert-file-handler.ts index ec0a48388e..6a8186efaf 100644 --- a/sources/packages/backend/libs/integrations/src/esdc-integration/e-cert-integration/e-cert-file-handler.ts +++ b/sources/packages/backend/libs/integrations/src/esdc-integration/e-cert-integration/e-cert-file-handler.ts @@ -9,12 +9,7 @@ import { ECertFeedbackErrorService, } from "../../services"; import { SequenceControlService, SystemUsersService } from "@sims/services"; -import { - CustomNamedError, - getISODateOnlyString, - parseJSONError, - processInParallel, -} from "@sims/utilities"; +import { getISODateOnlyString, processInParallel } from "@sims/utilities"; import { EntityManager } from "typeorm"; import { ESDCFileHandler } from "../esdc-file-handler"; import { @@ -93,34 +88,25 @@ export abstract class ECertFileHandler extends ESDCFileHandler { log.info( `Retrieving ${offeringIntensity} disbursements to generate the e-Cert file...`, ); - try { - const sequenceGroup = `${sequenceGroupPrefix}_${getISODateOnlyString( - new Date(), - )}`; - let uploadResult: ECertUploadResult; - await this.sequenceService.consumeNextSequence( - sequenceGroup, - async (nextSequenceNumber: number, entityManager: EntityManager) => { - uploadResult = await this.processECert( - nextSequenceNumber, - entityManager, - eCertIntegrationService, - offeringIntensity, - fileCode, - log, - ); - }, - ); - return uploadResult; - } catch (error: unknown) { - if (error instanceof CustomNamedError) { - return { - generatedFile: "none", - uploadedRecords: 0, - }; - } - throw error; - } + + const sequenceGroup = `${sequenceGroupPrefix}_${getISODateOnlyString( + new Date(), + )}`; + let uploadResult: ECertUploadResult; + await this.sequenceService.consumeNextSequence( + sequenceGroup, + async (nextSequenceNumber: number, entityManager: EntityManager) => { + uploadResult = await this.processECert( + nextSequenceNumber, + entityManager, + eCertIntegrationService, + offeringIntensity, + fileCode, + log, + ); + }, + ); + return uploadResult; } /** @@ -142,61 +128,47 @@ export abstract class ECertFileHandler extends ESDCFileHandler { fileCode: string, log: ProcessSummary, ): Promise { - try { - const disbursements = - await this.eCertGenerationService.getReadyToSendDisbursements( - offeringIntensity, - entityManager, - ); - log.info( - `Found ${disbursements.length} ${offeringIntensity} disbursements schedules.`, - ); - const disbursementRecords = disbursements.map((disbursement) => - this.createECertRecord(disbursement), + const disbursements = + await this.eCertGenerationService.getReadyToSendDisbursements( + offeringIntensity, + entityManager, ); + log.info( + `Found ${disbursements.length} ${offeringIntensity} disbursements schedules.`, + ); + const disbursementRecords = disbursements.map((disbursement) => + this.createECertRecord(disbursement), + ); - log.info(`Creating ${offeringIntensity} e-Cert file content...`); - const fileContent = eCertIntegrationService.createRequestContent( - disbursementRecords, - sequenceNumber, - ); + log.info(`Creating ${offeringIntensity} e-Cert file content...`); + const fileContent = eCertIntegrationService.createRequestContent( + disbursementRecords, + sequenceNumber, + ); - // Create the request filename with the file path for the e-Cert File. - const fileInfo = this.createRequestFileName(fileCode, sequenceNumber); - log.info(`Uploading ${offeringIntensity} content...`); - await eCertIntegrationService.uploadContent( - fileContent, - fileInfo.filePath, + // Create the request filename with the file path for the e-Cert File. + const fileInfo = this.createRequestFileName(fileCode, sequenceNumber); + log.info(`Uploading ${offeringIntensity} content...`); + await eCertIntegrationService.uploadContent(fileContent, fileInfo.filePath); + // Mark all disbursements as sent. + const dateSent = new Date(); + const disbursementScheduleRepo = + entityManager.getRepository(DisbursementSchedule); + await processInParallel((disbursement) => { + return disbursementScheduleRepo.update( + { id: disbursement.id }, + { + dateSent, + disbursementScheduleStatus: DisbursementScheduleStatus.Sent, + updatedAt: dateSent, + modifier: this.systemUserService.systemUser, + }, ); - // Mark all disbursements as sent. - const dateSent = new Date(); - const disbursementScheduleRepo = - entityManager.getRepository(DisbursementSchedule); - await processInParallel((disbursement) => { - return disbursementScheduleRepo.update( - { id: disbursement.id }, - { - dateSent, - disbursementScheduleStatus: DisbursementScheduleStatus.Sent, - updatedAt: dateSent, - modifier: this.systemUserService.systemUser, - }, - ); - }, disbursements); - return { - generatedFile: fileInfo.filePath, - uploadedRecords: disbursementRecords.length, - }; - } catch (error: unknown) { - if (error instanceof CustomNamedError) { - log.error( - `Error while uploading content for ${offeringIntensity} e-Cert file: ${parseJSONError( - error, - )}`, - ); - } - throw error; - } + }, disbursements); + return { + generatedFile: fileInfo.filePath, + uploadedRecords: disbursementRecords.length, + }; } /** From b5cdf3f986d98c10ce7bb614c640cd8092094b83 Mon Sep 17 00:00:00 2001 From: Ashish Date: Mon, 30 Dec 2024 16:50:25 -0800 Subject: [PATCH 10/10] comments update --- ...ecert-full-time-process-integration.scheduler.e2e-spec.ts | 5 ++++- ...ecert-part-time-process-integration.scheduler.e2e-spec.ts | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-full-time-process-integration.scheduler.e2e-spec.ts b/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-full-time-process-integration.scheduler.e2e-spec.ts index 910b74aa37..e4bcb6a217 100644 --- a/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-full-time-process-integration.scheduler.e2e-spec.ts +++ b/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-full-time-process-integration.scheduler.e2e-spec.ts @@ -1399,7 +1399,10 @@ describe( }, ); - // Helper function to get the uploaded file name. + /** + * Helper function to get the uploaded file name. + * @returns The uploaded file name + */ function getUploadedFileName() { const fileDate = dayjs().format("YYYYMMDD"); const uploadedFileName = `MSFT-Request\\DPBC.EDU.FTECERTS.${fileDate}.001`; diff --git a/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-part-time-process-integration.scheduler.e2e-spec.ts b/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-part-time-process-integration.scheduler.e2e-spec.ts index d51c81b86d..f435d489bd 100644 --- a/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-part-time-process-integration.scheduler.e2e-spec.ts +++ b/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/esdc-integration/ecert-integration/_tests_/ecert-part-time-process-integration.scheduler.e2e-spec.ts @@ -1489,7 +1489,10 @@ describe( ).toBe(true); }); - // Helper function to get the uploaded file name. + /** + * Helper function to get the uploaded file name. + * @returns The uploaded file name + */ function getUploadedFileName() { const fileDate = dayjs().format("YYYYMMDD"); const uploadedFileName = `MSFT-Request\\DPBC.EDU.NEW.PTCERTS.D${fileDate}.001`;