Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1777 - Process MSFAA Cancellation Notification e2e tests #2069

Merged
merged 4 commits into from
Jul 4, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,14 @@ import {
saveFakeApplicationDisbursements,
saveFakeStudent,
createFakeMSFAANumber,
MSFAA_FULL_TIME_RECEIVE_FILE_WITH_SINGLE_CANCELLATION_RECORD,
} from "@sims/test-utils";
import { THROW_AWAY_MSFAA_NUMBER } from "./msfaa-helper";
import {
ApplicationStatus,
DisbursementScheduleStatus,
OfferingIntensity,
NotificationMessageType,
} from "@sims/sims-db";
import * as Client from "ssh2-sftp-client";
import { Job } from "bull";
Expand Down Expand Up @@ -63,11 +65,18 @@ describe(
{ cancelledDate: IsNull() },
{ cancelledDate: getISODateOnlyString(new Date()) },
);
// Ensuring that any previous runs of this test or any other test do not have the same Msfaa id as the one in the re-activation file.
// Ensuring that any previous runs of this test or any other test do not have the same MSFAA number as the one used below.
await db.msfaaNumber.update(
{ msfaaNumber: FULL_TIME_SAMPLE_MSFAA_NUMBER },
{
msfaaNumber: FULL_TIME_SAMPLE_MSFAA_NUMBER,
},
{ msfaaNumber: THROW_AWAY_MSFAA_NUMBER },
);
// Update the date sent for the notifications to current date where the date sent is null.
await db.notification.update(
{ dateSent: IsNull() },
{ dateSent: new Date() },
);
});

it("Should reactivate a cancelled MSFAA when the same MSFAA is received in the response file and re-associate this reactivated MSFAA with all pending disbursements.", async () => {
Expand Down Expand Up @@ -229,5 +238,82 @@ describe(
currentMSFAA.id,
);
});

it("Should cancel a pending MSFAA record and save a cancellation notification when an MSFAA cancellation record is received in the response file.", async () => {
// Arrange
// Create a MSFAA record in pending state with the same MSFAA number as in the msfaa-full-time-receive-file-with-single-cancellation-record.dat
const student = await saveFakeStudent(db.dataSource);
const studentUserId = student.user.id;
const notificationMessageType = NotificationMessageType.MSFAACancellation;
const pendingMSFAARecord = await db.msfaaNumber.save(
createFakeMSFAANumber(
{ student },
{
msfaaInitialValues: {
msfaaNumber: FULL_TIME_SAMPLE_MSFAA_NUMBER,
offeringIntensity: OfferingIntensity.fullTime,
},
},
),
);
// Queued job.
const job = createMock<Job<void>>();
mockDownloadFiles(sftpClientMock, [
MSFAA_FULL_TIME_RECEIVE_FILE_WITH_SINGLE_CANCELLATION_RECORD,
]);
// Act
const processResult = await processor.processMSFAA(job);
const cancelledMSFAARecord = await db.msfaaNumber.findOne({
select: {
cancelledDate: true,
newIssuingProvince: true,
},
where: {
id: pendingMSFAARecord.id,
},
});
const notification = await db.notification.findOne({
select: {
id: true,
dateSent: true,
messagePayload: true,
notificationMessage: { templateId: true },
user: { email: true, firstName: true, lastName: true },
},
relations: { notificationMessage: true, user: true },
where: {
notificationMessage: {
id: notificationMessageType,
},
user: {
id: studentUserId,
},
},
});
// Assert
expect(processResult).toStrictEqual([
{
processSummary: [
`Processing file ${MSFAA_FULL_TIME_RECEIVE_FILE_WITH_SINGLE_CANCELLATION_RECORD}.`,
"File contains:",
"Confirmed MSFAA records (type R): 0.",
"Cancelled MSFAA records (type C): 1.",
"Record from line 1, updated as cancelled.",
],
errorsSummary: [],
},
]);
ann-aot marked this conversation as resolved.
Show resolved Hide resolved
expect(cancelledMSFAARecord.cancelledDate).toBe("2021-11-24");
expect(cancelledMSFAARecord.newIssuingProvince).toBe("ON");
expect(notification.dateSent).toBe(null);
andrewsignori-aot marked this conversation as resolved.
Show resolved Hide resolved
expect(notification.messagePayload).toStrictEqual({
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for adding this verification.
@ann-aot @guru-aot @dheepak-aot I believe that we can check the dynamic payload saved also as much as possible as part of the E2Es.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is good

email_address: notification.user.email,
template_id: notification.notificationMessage.templateId,
personalisation: {
lastName: notification.user.lastName,
givenNames: notification.user.firstName,
},
});
});
},
);
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import { THROW_AWAY_MSFAA_NUMBER } from "./msfaa-helper";
import {
ApplicationStatus,
DisbursementScheduleStatus,
NotificationMessageType,
OfferingIntensity,
} from "@sims/sims-db";
import * as Client from "ssh2-sftp-client";
Expand Down Expand Up @@ -74,7 +75,7 @@ describe(
{ cancelledDate: IsNull() },
{ cancelledDate: getISODateOnlyString(new Date()) },
);
// Ensuring that any previous runs of this test or any other test do not have the same Msfaa numbers as the ones used below.
// Ensuring that any previous runs of this test or any other test do not have the same MSFAA numbers as the ones used below.
const MsfaaRecordsToUpdate = [
MSFAA_PART_TIME_MARRIED.msfaaNumber,
MSFAA_PART_TIME_OTHER_COUNTRY.msfaaNumber,
Expand All @@ -87,9 +88,14 @@ describe(
},
{ msfaaNumber: THROW_AWAY_MSFAA_NUMBER },
);
// Update the date sent for the notifications to current date where the date sent is null.
await db.notification.update(
{ dateSent: IsNull() },
{ dateSent: new Date() },
);
});

it("Should process an MSFAA response with confirmations and a cancellation and update all records when the file is received as expected.", async () => {
it("Should process an MSFAA response with confirmations and cancellations, and save a notification message when the file is received as expected.", async () => {
// Arrange
const msfaaInputData = [
MSFAA_PART_TIME_MARRIED,
Expand Down Expand Up @@ -132,12 +138,15 @@ describe(
const msfaaIDs = createdMSFAARecords.map((msfaa) => msfaa.id);
const msfaaUpdatedRecords = await db.msfaaNumber.find({
select: {
id: true,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need id?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @ann-aot . Removed it.

msfaaNumber: true,
dateSigned: true,
serviceProviderReceivedDate: true,
cancelledDate: true,
newIssuingProvince: true,
student: { id: true, user: { id: true } },
},
relations: { student: { user: true } },
where: {
id: In(msfaaIDs),
},
Expand All @@ -157,6 +166,38 @@ describe(
// Validate second confirmed record.
expect(secondSignedMSFAA.dateSigned).toBe("2021-11-22");
expect(secondSignedMSFAA.serviceProviderReceivedDate).toBe("2021-11-23");

// Get the notification using the student and notification message id. Since a fake student is created for every test run, it will ensure uniqueness.
// Expecting one notification for the cancelled MSFAA record.
ann-aot marked this conversation as resolved.
Show resolved Hide resolved
const studentUserId = cancelledMSFAA.student.user.id;
const notificationMessageType = NotificationMessageType.MSFAACancellation;
const notification = await db.notification.findOne({
select: {
id: true,
dateSent: true,
messagePayload: true,
notificationMessage: { templateId: true },
user: { email: true, firstName: true, lastName: true },
},
relations: { notificationMessage: true, user: true },
where: {
notificationMessage: {
id: notificationMessageType,
},
user: {
id: studentUserId,
},
},
});
expect(notification.dateSent).toBe(null);
expect(notification.messagePayload).toStrictEqual({
email_address: notification.user.email,
template_id: notification.notificationMessage.templateId,
personalisation: {
lastName: notification.user.lastName,
givenNames: notification.user.firstName,
},
});
});

it("Should reactivate a cancelled MSFAA when the same MSFAA is received in the response file and re-associate this reactivated MSFAA with all pending disbursements.", async () => {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
100222 MSFAA RECEIVED 202111031617000001
2000000002000222222222C FT ON20211124
999MSFAA RECEIVED 000000001000000222222222
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ export const MSFAA_PART_TIME_RECEIVE_FILE_WITH_REACTIVATION_RECORD =
"msfaa-part-time-receive-file-with-reactivation-record.dat";
export const MSFAA_FULL_TIME_RECEIVE_FILE_WITH_REACTIVATION_RECORD =
"msfaa-full-time-receive-file-with-reactivation-record.dat";
export const MSFAA_FULL_TIME_RECEIVE_FILE_WITH_SINGLE_CANCELLATION_RECORD =
"msfaa-full-time-receive-file-with-single-cancellation-record.dat";

/**
* Represents a mocked uploaded file.
Expand Down