Skip to content

SSF-188 Automated Order Lifecycle Emails#162

Open
Juwang110 wants to merge 14 commits intomainfrom
jw/ssf-188-automated-order-lifecycle-emails
Open

SSF-188 Automated Order Lifecycle Emails#162
Juwang110 wants to merge 14 commits intomainfrom
jw/ssf-188-automated-order-lifecycle-emails

Conversation

@Juwang110
Copy link
Copy Markdown

ℹ️ Issue

Closes https://vidushimisra.atlassian.net/jira/software/projects/SSF/boards/1?jql=assignee%20%3D%20712020%3A10ef9ad9-e290-4bbd-8c4b-cb215e8d449a&selectedIssue=SSF-188

📝 Description

Email templates for:

  • Pantry’s Food Request has a matched order
  • FM’s donation has been matched to an order

✔️ Verification

BEFORE TESTING: Add 2 new environment variables:

AWS_SES_SENDER_EMAIL (set this to one of your emails, this will be the address that sends the emails for you to verify)
SEND_AUTOMATED_EMAILS (switch this to true to turn on Cognito account creation and email sending permissions)
Add your email that you put in the AWS_SES_SENDER_EMAIL into the following AWS SES Identities: https://us-east-2.console.aws.amazon.com/ses/home?region=us-east-2#/identities

Tested each workflow to ensure the proper sender, subject, message, attachments were all there.

Same testing as #127

I verified it worked via new tests and testing email functionality with postman.

🏕️ (Optional) Future Work / Notes

N/A

Copy link
Copy Markdown
Collaborator

@sam-schu sam-schu left a comment

Choose a reason for hiding this comment

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

For sending the emails:

  1. For consistency with our other emails, can we send the emails outside of the transaction, so the order is still created even if an email fails to send? (We do plan to add better handling for failed emails across the board)
  2. Can we try sending both emails, even if one fails?

Comment thread apps/backend/src/emails/emailTemplates.ts Outdated
@Juwang110 Juwang110 requested a review from sam-schu April 29, 2026 17:24
Copy link
Copy Markdown
Collaborator

@sam-schu sam-schu left a comment

Choose a reason for hiding this comment

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

Confirmed the emails are properly sent! A few comments on the contents:

  • Can we link the text "log into the platform" rather than including the link at the end of the email?
  • Can we turn the coordinator email into a link?
  • For the manufacturer email, can we make sure the different address lines appear on different lines in the email body, and add a comma between city and state?
814 Cedar Hollow Way
[Unit 1]
Madison, WI 53711
[US]

@Juwang110 Juwang110 requested a review from sam-schu May 4, 2026 19:44
transactionManager,
);

const associatedDonationIdsSet =
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Correct me if Im wrong, but I think the associatedDonationIdSet can just be found from the earlier donationItems in this function, since that is used from the itemAllocations that get created right before this.

<p>
Good news! Your recent food request through Securing Safe Food has been successfully matched to an order and is now moving forward toward delivery.
</p>
<p>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

I think we need to pull the <ul> element outside of the <p> element (same with the fmDonationMatchedOrder below)

Array.from(associatedDonationIdsSet),
transactionManager,
if (emailErrors.length > 0) {
this.logger.warn(
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

For consistency right now, perhaps we should do what all other email errors are doing, which is an InternalServerErrorException instead?

donationItemIds,
);
try {
const pantryAddress = [
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

2 things:

Should this not be the shipping address information instead, if it exists and is different from the mailing address? I'd assume the food, if it has a different address, should be getting shipped there.
Rather than this filter with a Boolean, since not everything needs a
element, can we just make it into:
const pantryAddress = ${request.pantry.mailingAddressLine1}
${request.pantry.mailingAddressCity}, ${request.pantry.mailingAddressState} ${request.pantry.mailingAddressZip}${request.pantry.mailingAddressCountry ?
${request.pantry.mailingAddressCountry} : ''};
This should have the address on one line, city, state, and zip on another, and country on a separate line if provided.

});

const pantry = request!.pantry;
const pantryAddress = [
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

We will need to make the same change here as in the order.service file


// Testing emails section

const assignee = await usersRepo.findOne({ where: { id: userId } });
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can we cast each of these to a User, Request, and FoodManufacturer so we dont need to keep using ! below?

[manufacturer!.foodManufacturerRepresentative.email],
fmSubject,
fmBodyHtml,
);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can we also add 2 more tests? One where either or of the pantry email and manufacturer email fails (you choose) and one where they both fail? For both of these, we should make sure that the order is still created.

[manufacturer!.foodManufacturerRepresentative.email],
fmSubject,
fmBodyHtml,
);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can we also add tests for the allocations being created, and the donation service doing proper matching? We don't need to test the actual output, but rather just make sure that the functions are called once each and with the proper parameters that we expect them to be.

[manufacturer!.foodManufacturerRepresentative.email],
fmSubject,
fmBodyHtml,
);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Sorry for so many additional tests requests. Can we also test for transaction doing a rollback for all changes if an error occurs on allocation creation (and that the order is not actually created in this case)?

await requestRepo.save(request);

validCreateOrderDto.foodRequestId = 2;
await expect(
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Can we combine these into one expect for a full BadRequestException with the right error message?

@dburkhart07 dburkhart07 removed the request for review from swarkewalia May 5, 2026 05:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants