Skip to content

Commit

Permalink
Merge pull request #1001 from bcgov/feature/ALCS-1039-2
Browse files Browse the repository at this point in the history
Only set ALC Response Sent status if Noti Email Sends
  • Loading branch information
dhaselhan authored Sep 22, 2023
2 parents 29713b4 + a43bb62 commit c8a309a
Show file tree
Hide file tree
Showing 10 changed files with 132 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<!-- Row shown when there is no matching data. -->
<tr class="mat-row" *matNoDataRow>
<td class="mat-cell" colspan="7">No Applications Created</td>
<td class="no-data" colspan="7">No Applications Created</td>
</tr>

<ng-container matColumnDef="fileNumber">
Expand Down
8 changes: 8 additions & 0 deletions portal-frontend/src/app/features/home/home.component.scss
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@
}
}

:host::ng-deep {
.no-data {
color: colors.$grey;
text-align: center;
padding: rem(8);
}
}

.header-row {
.learn-more-wrapper {
margin-top: rem(24);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<!-- Row shown when there is no matching data. -->
<tr class="mat-row" *matNoDataRow>
<td class="mat-cell" style='text-align: center' colspan="7">No NOIs Created</td>
<td class="no-data" colspan="7">No NOIs Created</td>
</tr>

<ng-container matColumnDef="fileNumber">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<!-- Row shown when there is no matching data. -->
<tr class="mat-row" *matNoDataRow>
<td class="mat-cell" style="text-align: center" colspan="7">No Notifications Created</td>
<td class="no-data" colspan="7">No Notifications Created</td>
</tr>

<ng-container matColumnDef="fileNumber">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@ import { createMock, DeepMocked } from '@golevelup/nestjs-testing';
import { Test, TestingModule } from '@nestjs/testing';
import { getRepositoryToken } from '@nestjs/typeorm';
import { Repository } from 'typeorm';
import { LocalGovernment } from '../../alcs/local-government/local-government.entity';
import { LocalGovernmentService } from '../../alcs/local-government/local-government.service';
import { NoticeOfIntentType } from '../../alcs/notice-of-intent/notice-of-intent-type/notice-of-intent-type.entity';
import { NotificationDocument } from '../../alcs/notification/notification-document/notification-document.entity';
import { NotificationDocumentService } from '../../alcs/notification/notification-document/notification-document.service';
import { NOTIFICATION_STATUS } from '../../alcs/notification/notification-submission-status/notification-status.dto';
import { NotificationSubmissionToSubmissionStatus } from '../../alcs/notification/notification-submission-status/notification-status.entity';
import { NotificationSubmissionStatusService } from '../../alcs/notification/notification-submission-status/notification-submission-status.service';
import { Notification } from '../../alcs/notification/notification.entity';
Expand All @@ -19,6 +22,7 @@ import { User } from '../../user/user.entity';
import { ValidatedNotificationSubmission } from './notification-submission-validator.service';
import { NotificationSubmission } from './notification-submission.entity';
import { NotificationSubmissionService } from './notification-submission.service';
import { Document } from '../../document/document.entity';

describe('NotificationSubmissionService', () => {
let service: NotificationSubmissionService;
Expand Down Expand Up @@ -304,4 +308,89 @@ describe('NotificationSubmissionService', () => {
expect(res).toBe(uuid);
expect(mockRepository.findOne).toHaveBeenCalledTimes(1);
});

it('should change the status when sending the email was successfull', async () => {
const uuid = 'uuid';
const noiSubmission = new NotificationSubmission({
uuid,
localGovernmentUuid: 'uuid',
contactEmail: 'contact@contact',
});
const document = new NotificationDocument({
document: new Document(),
});

mockLGService.getByUuid.mockResolvedValue(
new LocalGovernment({
emails: ['gov@gov'],
}),
);
mockNotificationService.getByFileNumber.mockResolvedValue(
new Notification(),
);
mockEmailService.sendEmail.mockResolvedValue(true);
mockDocumentService.attachDocumentAsBuffer.mockResolvedValue(
new NotificationDocument(),
);
mockStatusService.setStatusDate.mockResolvedValue(
new NotificationSubmissionToSubmissionStatus(),
);

await service.sendAndRecordLTSAPackage(noiSubmission, document, new User());

expect(mockLGService.getByUuid).toHaveBeenCalledTimes(1);
expect(mockNotificationService.getByFileNumber).toHaveBeenCalledTimes(1);
expect(mockEmailService.sendEmail).toHaveBeenCalledTimes(1);
expect(mockEmailService.sendEmail).toHaveBeenCalledWith(
expect.objectContaining({
to: ['contact@contact'],
cc: ['gov@gov'],
}),
);

expect(mockDocumentService.attachDocumentAsBuffer).toHaveBeenCalledTimes(1);
expect(mockStatusService.setStatusDate).toHaveBeenCalledTimes(1);
expect(mockStatusService.setStatusDate).toHaveBeenCalledWith(
uuid,
NOTIFICATION_STATUS.ALC_RESPONSE_SENT,
undefined,
);
});

it('should not change the status if the email fails', async () => {
const uuid = 'uuid';
const noiSubmission = new NotificationSubmission({
uuid,
localGovernmentUuid: 'uuid',
contactEmail: 'contact@contact',
});
const document = new NotificationDocument({
document: new Document(),
});

mockLGService.getByUuid.mockResolvedValue(
new LocalGovernment({
emails: ['gov@gov'],
}),
);
mockNotificationService.getByFileNumber.mockResolvedValue(
new Notification(),
);
mockEmailService.sendEmail.mockResolvedValue(false);

await service.sendAndRecordLTSAPackage(noiSubmission, document, new User());

expect(mockLGService.getByUuid).toHaveBeenCalledTimes(1);
expect(mockNotificationService.getByFileNumber).toHaveBeenCalledTimes(1);
expect(mockEmailService.sendEmail).toHaveBeenCalledTimes(1);
expect(mockEmailService.sendEmail).toHaveBeenCalledWith(
expect.objectContaining({
to: ['contact@contact'],
cc: ['gov@gov'],
}),
);

expect(mockDocumentService.attachDocumentAsBuffer).toHaveBeenCalledTimes(0);
expect(mockStatusService.setStatusDate).toHaveBeenCalledTimes(0);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -380,9 +380,8 @@ export class NotificationSubmissionService {
statusCode: NOTIFICATION_STATUS,
effectiveDate?: Date | null,
) {
const submission = await this.loadBarebonesSubmission(uuid);
await this.notificationSubmissionStatusService.setStatusDate(
submission.uuid,
uuid,
statusCode,
effectiveDate,
);
Expand Down Expand Up @@ -411,7 +410,7 @@ export class NotificationSubmissionService {
) {
const templateData = await this.generateSrwEmailData(submission, document);

await this.emailService.sendEmail({
const didSend = await this.emailService.sendEmail({
to: [templateData.to],
body: templateData.html,
subject: `Agricultural Land Commission SRW${submission.fileNumber} (${submission.applicant})`,
Expand All @@ -421,24 +420,29 @@ export class NotificationSubmissionService {
attachments: [document.document],
});

const fileBuffer = Buffer.from(templateData.html);
await this.notificationDocumentService.attachDocumentAsBuffer({
file: Buffer.from(templateData.html),
fileName: `SRW${submission.fileNumber}_ALC_Email_Response.html`,
source: DOCUMENT_SOURCE.ALC,
user,
system: DOCUMENT_SYSTEM.ALCS,
documentType: DOCUMENT_TYPE.ACKNOWLEDGEMENT_LETTER,
fileNumber: submission.fileNumber,
fileSize: fileBuffer.length,
mimeType: 'text/html',
visibilityFlags: [VISIBILITY_FLAG.APPLICANT, VISIBILITY_FLAG.GOVERNMENT],
});
if (didSend) {
const fileBuffer = Buffer.from(templateData.html);
await this.notificationDocumentService.attachDocumentAsBuffer({
file: Buffer.from(templateData.html),
fileName: `SRW${submission.fileNumber}_ALC_Email_Response.html`,
source: DOCUMENT_SOURCE.ALC,
user,
system: DOCUMENT_SYSTEM.ALCS,
documentType: DOCUMENT_TYPE.ACKNOWLEDGEMENT_LETTER,
fileNumber: submission.fileNumber,
fileSize: fileBuffer.length,
mimeType: 'text/html',
visibilityFlags: [
VISIBILITY_FLAG.APPLICANT,
VISIBILITY_FLAG.GOVERNMENT,
],
});

await this.updateStatus(
submission.uuid,
NOTIFICATION_STATUS.ALC_RESPONSE_SENT,
);
await this.updateStatus(
submission.uuid,
NOTIFICATION_STATUS.ALC_RESPONSE_SENT,
);
}
}

private async generateSrwEmailData(
Expand Down Expand Up @@ -471,15 +475,11 @@ export class NotificationSubmissionService {
}
}

const parentId = await this.notificationService.getUuid(
submission.fileNumber,
);

return {
html: emailTemplate.html,
cc: ccEmails,
to: submission.contactEmail!,
parentId,
parentId: notification.uuid,
};
}
}
5 changes: 4 additions & 1 deletion services/apps/alcs/src/providers/email/email.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ export class EmailService {
),
);
this.logger.debug({ to, from, subject }, `Email sent`);
this.repository.save(
await this.repository.save(
new EmailStatus({
recipients: [...to, ...cc, ...bcc].join(', '),
status: 'success',
Expand All @@ -174,6 +174,7 @@ export class EmailService {
triggerStatus,
}),
);
return true;
} catch (e) {
this.logger.error(e, 'Failed to Send Email');

Expand All @@ -192,6 +193,8 @@ export class EmailService {
triggerStatus,
}),
);

return false;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ describe('StatusEmailService', () => {

service = module.get<StatusEmailService>(StatusEmailService);

mockEmailService.sendEmail.mockResolvedValue();
mockEmailService.sendEmail.mockResolvedValue(true);
});

it('should be defined', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe('SchedulerConsumerService', () => {
ApplicationExpiryConsumer,
);

mockEmailService.sendEmail.mockResolvedValue();
mockEmailService.sendEmail.mockResolvedValue(true);
});

it('should be defined', () => {
Expand Down
2 changes: 1 addition & 1 deletion services/apps/alcs/src/user/user.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ describe('UserService', () => {
mockUserRepository.find.mockResolvedValue([mockUser]);
mockUserRepository.softRemove.mockResolvedValue(mockUser);

emailServiceMock.sendEmail.mockResolvedValue();
emailServiceMock.sendEmail.mockResolvedValue(true);
});

it('should return the users from the repository', async () => {
Expand Down

0 comments on commit c8a309a

Please sign in to comment.