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

mailer_helper update #11665

Merged
merged 3 commits into from
Dec 19, 2024
Merged

mailer_helper update #11665

merged 3 commits into from
Dec 19, 2024

Conversation

matthinz
Copy link
Member

@matthinz matthinz commented Dec 18, 2024

🛠 Summary of changes

mailer_helper.rb provides the expect_delivered_email helper, which we use in our specs to assert that an email was sent.

This PR:

  1. Adds the inverse expect_email_not_delivered
  2. Adds a spec to capture the expected behavior
  3. Updates some places where body matching was previously incorrectly passing

@matthinz matthinz marked this pull request as ready for review December 18, 2024 18:16
@@ -38,7 +38,9 @@
expect_delivered_email(
to: [user.confirmed_email_addresses.first.email],
subject: t('user_mailer.account_verified.subject', app_name: APP_NAME),
body: ['<table class="button expanded large radius">', 'localhost:3000'],
body: [
'http://www.example.com/redirect/return_to_sp/account_verified_cta',
Copy link
Member Author

Choose a reason for hiding this comment

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

Turns out body: is only comparing against the plaintext version of the email, so checking for HTML here fails.

Previously, we weren't correctly processing these body checks, so this was erroneously passing prior to this PR

Copy link
Member

Choose a reason for hiding this comment

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

I sometimes wonder how many tests erroneously pass and conceal bugs. 😬 Glad you found this.

# @param [String,nil] to If provided, the email address the message must've been sent to
# @param [String,nil] subject If provided, the subject the email must've had
# @param [String[],nil] Array of substrings that must appear in body.
def expect_email_not_delivered(to: nil, subject: nil, body: nil)
Copy link
Member Author

Choose a reason for hiding this comment

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

TBH I would like to rework this as an Rspec matcher, something like

expect { some_code }.to have_delivered_email(...)

But I needed to limit scope a little here

Copy link
Member

Choose a reason for hiding this comment

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

I agree with you on both counts—that would be nice, but this is a good step forward for now.

@matthinz matthinz requested a review from a team December 18, 2024 18:19
- Slightly improve error output
- Capture behavior in a dedicated spec

[skip changelog]
Assert that a certain email was not sent.
These specs weren't actually testing the thing we thought they were, since the text_part of the email did not contain HTML.
@matthinz matthinz force-pushed the matthinz/mailer-helper-update branch from 7329299 to 3dffdd8 Compare December 18, 2024 18:25
@matthinz matthinz requested a review from a team December 18, 2024 18:33
Copy link
Member

@n1zyy n1zyy left a comment

Choose a reason for hiding this comment

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

Nice!

@@ -38,7 +38,9 @@
expect_delivered_email(
to: [user.confirmed_email_addresses.first.email],
subject: t('user_mailer.account_verified.subject', app_name: APP_NAME),
body: ['<table class="button expanded large radius">', 'localhost:3000'],
body: [
'http://www.example.com/redirect/return_to_sp/account_verified_cta',
Copy link
Member

Choose a reason for hiding this comment

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

I sometimes wonder how many tests erroneously pass and conceal bugs. 😬 Glad you found this.

# @param [String,nil] to If provided, the email address the message must've been sent to
# @param [String,nil] subject If provided, the subject the email must've had
# @param [String[],nil] Array of substrings that must appear in body.
def expect_email_not_delivered(to: nil, subject: nil, body: nil)
Copy link
Member

Choose a reason for hiding this comment

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

I agree with you on both counts—that would be nice, but this is a good step forward for now.

@matthinz matthinz merged commit c6b8ff8 into main Dec 19, 2024
2 checks passed
@matthinz matthinz deleted the matthinz/mailer-helper-update branch December 19, 2024 17:12
matthinz added a commit that referenced this pull request Dec 19, 2024
* Rework mailer_helper and add spec

- Slightly improve error output
- Capture behavior in a dedicated spec

[skip changelog]

* Add expect_email_not_delivered helper

Assert that a certain email was not sent.

* Update alert_user_about_account_verified_spec

These specs weren't actually testing the thing we thought they were, since the text_part of the email did not contain HTML.
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.

2 participants