Skip to content

Commit

Permalink
resolve comments - site address
Browse files Browse the repository at this point in the history
  • Loading branch information
lewischen-aot committed Nov 12, 2024
1 parent 95859cf commit 537d7ad
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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.
Expand All @@ -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: {
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import * as faker from "faker";
*/
export function createFakeCASSupplierResponse(options?: {
initialValues: {
status?: CASSupplierRecordStatus;
siteStatus?: CASSupplierRecordStatus;
postalCode?: string;
};
}): CASSupplierResponse {
Expand All @@ -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",
Expand All @@ -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",
},
Expand Down

0 comments on commit 537d7ad

Please sign in to comment.