From 537d7adeb9b3ebea2c6d35e3098bf32c49b85305 Mon Sep 17 00:00:00 2001 From: Lewis Chen Date: Tue, 12 Nov 2024 10:19:53 -0800 Subject: [PATCH] resolve comments - site address --- ...supplier-integration.scheduler.e2e-spec.ts | 36 ++++++++++--------- .../mock-utils/cas-response.factory.ts | 6 ++-- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/cas-integration/_tests_/cas-supplier-integration.scheduler.e2e-spec.ts b/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/cas-integration/_tests_/cas-supplier-integration.scheduler.e2e-spec.ts index 818e5d1d74..78b2486878 100644 --- a/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/cas-integration/_tests_/cas-supplier-integration.scheduler.e2e-spec.ts +++ b/sources/packages/backend/apps/queue-consumers/src/processors/schedulers/cas-integration/_tests_/cas-supplier-integration.scheduler.e2e-spec.ts @@ -492,7 +492,7 @@ describe(describeProcessorRootTest(QueueNames.CASSupplierIntegration), () => { ); }); - it("Should create a new site and update the student CAS supplier when an inactive CAS supplier exists with matching addresses.", async () => { + it("Should create a new site and update the student CAS supplier when an active CAS supplier exists with inactive site address.", async () => { // Arrange // Created a student with same address line 1 and postal code from the expected CAS mocked result. // Postal code has a white space that is expected to be removed. @@ -512,27 +512,30 @@ describe(describeProcessorRootTest(QueueNames.CASSupplierIntegration), () => { }); const referenceDate = new Date(); const savedCASSupplier = await saveFakeCASSupplier(db, { student }); + // Configure CAS mock to return a result for the GetSupplier - // with the same supplier number and address line 1 from the - // saved CAS supplier but an inactive status. + // with the same supplier number, address line 1 and postal code + // from the saved CAS supplier but inactive status. casServiceMock.getSupplierInfoFromCAS = jest.fn(() => Promise.resolve( createFakeCASSupplierResponse({ initialValues: { - status: "INACTIVE", // The status is set to "INACTIVE" to mismatch the address. + siteStatus: "INACTIVE", // The status is added to mismatch the address's status. }, }), ), ); + // Configure CAS mock to return a successful result for the CreateSiteForExistingSupplier. - const createSiteForInactiveSupplierResponse = - createFakeCASCreateSupplierAndSiteResponse({ + const createSupplierNoSiteResponse = + createFakeCASSiteForExistingSupplierResponse({ initialValues: { + supplierNumber: savedCASSupplier.supplierNumber, supplierAddress: savedCASSupplier.supplierAddress, }, }); - casServiceMock.createSupplierAndSite = jest.fn(() => - Promise.resolve(createSiteForInactiveSupplierResponse), + casServiceMock.createSiteForExistingSupplier = jest.fn(() => + Promise.resolve(createSupplierNoSiteResponse), ); // Queued job. @@ -549,17 +552,19 @@ describe(describeProcessorRootTest(QueueNames.CASSupplierIntegration), () => { ]); expect( mockedJob.containLogMessages([ + "Executing CAS supplier integration...", "Found 1 records to be updated.", `Processing student CAS supplier ID: ${savedCASSupplier.id}.`, - `CAS evaluation result status: ${CASEvaluationStatus.NotFound}.`, - `No active CAS supplier found. Reason: ${NotFoundReason.NoActiveSupplierFound}.`, - "Created supplier and site on CAS.", + `CAS evaluation result status: ${CASEvaluationStatus.ActiveSupplierFound}.`, + "Active CAS supplier found.", + "Created a new site on CAS.", "Updated CAS supplier and site for the student.", + "CAS supplier integration executed.", ]), ).toBe(true); // Assert the API methods were called. expect(casServiceMock.getSupplierInfoFromCAS).toHaveBeenCalled(); - expect(casServiceMock.createSupplierAndSite).toHaveBeenCalled(); + expect(casServiceMock.createSiteForExistingSupplier).toHaveBeenCalled(); // Assert DB was updated. const updateCASSupplier = await db.casSupplier.findOne({ select: { @@ -582,16 +587,15 @@ describe(describeProcessorRootTest(QueueNames.CASSupplierIntegration), () => { }, }); const [submittedAddress] = - createSiteForInactiveSupplierResponse.submittedData.SupplierAddress; + createSupplierNoSiteResponse.submittedData.SupplierAddress; expect(updateCASSupplier).toEqual({ id: savedCASSupplier.id, - supplierNumber: - createSiteForInactiveSupplierResponse.response.supplierNumber, + supplierNumber: createSupplierNoSiteResponse.response.supplierNumber, status: "ACTIVE", lastUpdated: expect.any(Date), supplierAddress: { supplierSiteCode: - createSiteForInactiveSupplierResponse.response.supplierSiteCode, + createSupplierNoSiteResponse.response.supplierSiteCode, addressLine1: submittedAddress.AddressLine1, city: submittedAddress.City, provinceState: submittedAddress.Province, diff --git a/sources/packages/backend/apps/queue-consumers/test/helpers/mock-utils/cas-response.factory.ts b/sources/packages/backend/apps/queue-consumers/test/helpers/mock-utils/cas-response.factory.ts index e4f0dfd06d..b625057267 100644 --- a/sources/packages/backend/apps/queue-consumers/test/helpers/mock-utils/cas-response.factory.ts +++ b/sources/packages/backend/apps/queue-consumers/test/helpers/mock-utils/cas-response.factory.ts @@ -20,7 +20,7 @@ import * as faker from "faker"; */ export function createFakeCASSupplierResponse(options?: { initialValues: { - status?: CASSupplierRecordStatus; + siteStatus?: CASSupplierRecordStatus; postalCode?: string; }; }): CASSupplierResponse { @@ -33,7 +33,7 @@ export function createFakeCASSupplierResponse(options?: { sin: "000000000", providerid: "CAS_WS_AE_PSFS_SIMS", businessnumber: null, - status: options?.initialValues?.status ?? "ACTIVE", + status: "ACTIVE", supplierprotected: null, standardindustryclassification: null, lastupdated: "2024-05-01 13:55:00", @@ -53,7 +53,7 @@ export function createFakeCASSupplierResponse(options?: { banknumber: null, eftadvicepref: null, providerid: "CAS_WS_AE_PSFS_SIMS", - status: "ACTIVE", + status: options?.initialValues?.siteStatus ?? "ACTIVE", siteprotected: null, lastupdated: "2024-05-01 13:55:04", },