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

Improve types around nodemailer (take 2) #15638

Merged
merged 11 commits into from
Feb 27, 2025

Conversation

samwho
Copy link
Collaborator

@samwho samwho commented Feb 26, 2025

Reverts the initial revert at #15637

I've pointed out in a comment where the bug from the first attempt was. I've substantially extended the testing around email sending in packages/worker. Instead of doing it half with Jest mocks and half by firing off real emails to seamus99@ethereal.email, it now spins up an SMTP server in the tests using https://github.com/maildev/maildev and sends off real emails, then retrieves them through maildev's API. This results in much better test realism, and better assertions on the results of the tests.

Feature branch env

Feature Branch Link

Copy link

qa-wolf bot commented Feb 26, 2025

QA Wolf here! As you write new code it's important that your test coverage is keeping up.
Click here to request test coverage for this PR!

@github-actions github-actions bot added firestorm Data/Infra/Revenue Team size/s labels Feb 26, 2025
@github-actions github-actions bot added size/m and removed size/s labels Feb 26, 2025
@samwho samwho changed the title Revert "Revert "Improve types around nodemailer"" Improve types around nodemailer (take 2) Feb 26, 2025
@samwho samwho added the feature-branch Release this PR code into a feature branch label Feb 26, 2025
@github-actions github-actions bot added size/l and removed size/m labels Feb 26, 2025
email: string
userId: string
userId?: string
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Automations don't send this, it has always been optional.

Comment on lines +20 to +21
cc?: string
bcc?: string
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

These were just flatly wrong, assuming an oversight in the original TS conversion.

Comment on lines +29 to +32
user = await db.tryGet<User>(userId)
if (!user) {
ctx.throw(404, "User not found.")
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This is where the original bug was. I had this if (!user) check outside of the if (userId) block, meaning whenever a userId wasn't specified (e.g. in automations), it would always return a 404.

This was an oversight on my part that we had no tests to catch. I've added tests that catch this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've folded all of the tests from realEmail.spec.ts into this file, and this file now uses maildev to send real emails to a local server.

I've wrapped most of the maildev functionality because it was callback based, not async/await. Also the @types/maildev package is quite sketchy and wrong in places, so I've done some manual typing of it.

@samwho samwho marked this pull request as ready for review February 27, 2025 11:40
@samwho samwho requested a review from a team as a code owner February 27, 2025 11:40
@samwho samwho requested review from adrinr and removed request for a team February 27, 2025 11:40
Copy link
Collaborator

@mike12345567 mike12345567 left a comment

Choose a reason for hiding this comment

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

LGTM - great to get an iCal invite test case together as well, this is a much better method of testing this, avoids the multitude of issues we've ran into with Ethereal being unavailable etc as well as giving us a lot more options in terms of how we test email.

@samwho samwho enabled auto-merge February 27, 2025 14:42
@samwho samwho merged commit 7831355 into master Feb 27, 2025
21 checks passed
@samwho samwho deleted the revert-15637-revert-15612-smtp-types branch February 27, 2025 14:52
@github-actions github-actions bot locked and limited conversation to collaborators Feb 27, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-branch Release this PR code into a feature branch firestorm Data/Infra/Revenue Team size/l
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants