Skip to content

Commit

Permalink
Merge pull request #1636 from bcgov/feature/ALCS-1878
Browse files Browse the repository at this point in the history
Always send emails for applications when submitting to LG
  • Loading branch information
dhaselhan authored Apr 30, 2024
2 parents bdae64e + ea8adfa commit 41e9533
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -610,56 +610,6 @@ describe('ApplicationSubmissionController', () => {
});
});

it('should only send status email for first time non-TUR applications', async () => {
const mockFileId = 'file-id';
mockAppSubmissionService.submitToLg.mockResolvedValue(
new ApplicationSubmissionToSubmissionStatus(),
);
const mockOwner = new ApplicationOwner({ uuid: primaryContactOwnerUuid });
const mockApplicationSubmission = new ApplicationSubmission({
typeCode: 'NOT-TURP',
owners: [mockOwner],
primaryContactOwnerUuid,
localGovernmentUuid,
submissionStatuses: [
new ApplicationSubmissionToSubmissionStatus({
statusTypeCode: SUBMISSION_STATUS.INCOMPLETE,
submissionUuid: 'fake',
effectiveDate: new Date(),
}),
],
});
mockAppSubmissionService.verifyAccessByUuid.mockResolvedValue(
mockApplicationSubmission,
);
mockAppValidationService.validateSubmission.mockResolvedValue({
submission: mockApplicationSubmission as ValidatedApplicationSubmission,
errors: [],
});
mockStatusEmailService.sendApplicationStatusEmail.mockResolvedValue();

const mockGovernment = new LocalGovernment({ uuid: localGovernmentUuid });
mockStatusEmailService.getApplicationEmailData.mockResolvedValue({
applicationSubmission: mockApplicationSubmission,
primaryContact: mockOwner,
submissionGovernment: mockGovernment,
});

await controller.submitAsApplicant(mockFileId, {
user: {
entity: new User(),
},
});

expect(mockAppSubmissionService.verifyAccessByUuid).toHaveBeenCalledTimes(
1,
);
expect(mockAppSubmissionService.submitToLg).toHaveBeenCalledTimes(1);
expect(
mockStatusEmailService.sendApplicationStatusEmail,
).toHaveBeenCalledTimes(0);
});

it('should throw an exception if application fails validation', async () => {
const mockFileId = 'file-id';
const mockApplicationSubmission = new ApplicationSubmission({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import {
} from '../../../../../libs/common/src/exceptions/base.exception';
import { generateCANCApplicationHtml } from '../../../../../templates/emails/cancelled';
import {
generateSUBGTurApplicantHtml,
generateSUBGNoReviewGovernmentTemplateEmail,
generateSUBGTurApplicantHtml,
} from '../../../../../templates/emails/submitted-to-alc';
import { generateSUBGCoveApplicantHtml } from '../../../../../templates/emails/submitted-to-alc/cove-applicant.template';
import {
Expand Down Expand Up @@ -288,39 +288,25 @@ export class ApplicationSubmissionController {
);

if (matchingType.requiresGovernmentReview) {
const wasSubmittedToLfng = validatedSubmission.submissionStatuses.find(
(s) =>
[
SUBMISSION_STATUS.SUBMITTED_TO_LG,
SUBMISSION_STATUS.IN_REVIEW_BY_LG,
SUBMISSION_STATUS.WRONG_GOV,
SUBMISSION_STATUS.INCOMPLETE,
].includes(s.statusTypeCode as SUBMISSION_STATUS) &&
!!s.effectiveDate,
);

// Send status emails for first time submissions
if (!wasSubmittedToLfng) {
if (primaryContact) {
await this.statusEmailService.sendApplicationStatusEmail({
generateStatusHtml: generateSUBGApplicantHtml,
status: SUBMISSION_STATUS.SUBMITTED_TO_LG,
applicationSubmission: validatedSubmission,
government: submissionGovernment,
parentType: PARENT_TYPE.APPLICATION,
primaryContact,
});
}
if (primaryContact) {
await this.statusEmailService.sendApplicationStatusEmail({
generateStatusHtml: generateSUBGApplicantHtml,
status: SUBMISSION_STATUS.SUBMITTED_TO_LG,
applicationSubmission: validatedSubmission,
government: submissionGovernment,
parentType: PARENT_TYPE.APPLICATION,
primaryContact,
});
}

if (submissionGovernment) {
await this.statusEmailService.sendApplicationStatusEmail({
generateStatusHtml: generateSUBGGovernmentHtml,
status: SUBMISSION_STATUS.SUBMITTED_TO_LG,
applicationSubmission: validatedSubmission,
government: submissionGovernment,
parentType: PARENT_TYPE.APPLICATION,
});
}
if (submissionGovernment) {
await this.statusEmailService.sendApplicationStatusEmail({
generateStatusHtml: generateSUBGGovernmentHtml,
status: SUBMISSION_STATUS.SUBMITTED_TO_LG,
applicationSubmission: validatedSubmission,
government: submissionGovernment,
parentType: PARENT_TYPE.APPLICATION,
});
}

return await this.applicationSubmissionService.submitToLg(
Expand Down

0 comments on commit 41e9533

Please sign in to comment.