-
Notifications
You must be signed in to change notification settings - Fork 519
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
AO3-6764 Add kudo mailer preview #4875
Merged
brianjaustin
merged 6 commits into
otwcode:master
from
Bilka2:AO3-6764-kudo-mailer-preview
Aug 15, 2024
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
676f8cc
AO3-6764 Add kudo mailer preview
Bilka2 82a1efa
AO3-6764 Update kudo mailer i18n keys
Bilka2 d2e4b06
AO3-6764 Normalize locale file
Bilka2 8214473
AO3-6764 Convert locale preference rollout test to cucumber test
Bilka2 cc07668
Merge branch 'master' into AO3-6764-kudo-mailer-preview
Bilka2 5360659
AO3-6764 Minor fixes
Bilka2 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,6 +168,32 @@ Feature: Kudos | |
And the email should not contain "0 guests" | ||
And the email should not contain "translation missing" | ||
|
||
Scenario: Translated kudos email | ||
|
||
Given a locale with translated emails | ||
And the user "myname1" enables translated emails | ||
And all emails have been delivered | ||
And the kudos queue is cleared | ||
And I am logged in as "myname2" | ||
And I leave kudos on "Awesome Story" | ||
When kudos are sent | ||
Then 1 email should be delivered to "[email protected]" | ||
And the email should have "Translated subject" in the subject | ||
And the email to "myname1" should contain "myname2" | ||
And the email to "myname1" should contain "Awesome Story" | ||
And the email to "myname1" should be translated | ||
# AO3-6042: Emails should not obey user's locale preference when locales are deactivated | ||
When the locale preference feature flag is disabled for user "myname1" | ||
And all emails have been delivered | ||
And I am logged in as "myname3" | ||
And I leave kudos on "Awesome Story" | ||
And kudos are sent | ||
Then 1 email should be delivered to "[email protected]" | ||
And the email should have "You've got kudos!" in the subject | ||
And the email to "myname1" should contain "myname3" | ||
And the email to "myname1" should contain "Awesome Story" | ||
And the email to "myname1" should be non-translated | ||
|
||
Scenario: Blocked users should not see a kudos button on their blocker's works | ||
Given the work "Aftermath" by "creator" | ||
And the user "creator" has blocked the user "pest" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,70 @@ | ||
Given /^(?:a clear email queue|no emails have been sent|the email queue is clear)$/ do | ||
Given "the email queue is clear" do | ||
reset_mailer | ||
end | ||
|
||
Then /^"([^\"]*)" should be emailed$/ do |user| | ||
Given "a locale with translated emails" do | ||
FactoryBot.create(:locale, iso: "new") | ||
# The footer keys are used in all emails | ||
I18n.backend.store_translations(:new, { mailer: { general: { footer: { general: { about: { html: "Translated footer", text: "Translated footer" } } } } } }) | ||
I18n.backend.store_translations(:new, { kudo_mailer: { batch_kudo_notification: { subject: "Translated subject" } } }) | ||
end | ||
|
||
Given "the user {string} enables translated emails" do |user| | ||
user = User.find_by(login: user) | ||
$rollout.activate_user(:set_locale_preference, user) | ||
user.preference.update!(locale: Locale.find_by(iso: "new")) | ||
end | ||
|
||
Given "the locale preference feature flag is disabled for user {string}" do |user| | ||
user = User.find_by(login: user) | ||
$rollout.deactivate_user(:set_locale_preference, user) | ||
end | ||
|
||
Then "the email to {string} should be translated" do |user| | ||
step(%{the email to "#{user}" should contain "Translated footer"}) | ||
step(%{the email to "#{user}" should not contain "fan-run and fan-supported archive"}) # untranslated English text | ||
step(%{the email to "#{user}" should not contain "translation missing"}) # missing translations in the target language fall back to English | ||
end | ||
|
||
Then "the email to {string} should be non-translated" do |user| | ||
step(%{the email to "#{user}" should not contain "Translated footer"}) | ||
step(%{the email to "#{user}" should contain "fan-run and fan-supported archive"}) | ||
step(%{the email to "#{user}" should not contain "translation missing"}) | ||
end | ||
|
||
Then "{string} should be emailed" do |user| | ||
@user = User.find_by(login: user) | ||
emails("to: \"#{email_for(@user.email)}\"").size.should > 0 | ||
expect(emails("to: \"#{email_for(@user.email)}\"")).not_to be_empty | ||
end | ||
|
||
Then /^"([^\"]*)" should not be emailed$/ do |user| | ||
Then "{string} should not be emailed" do |user| | ||
@user = User.find_by(login: user) | ||
emails("to: \"#{email_for(@user.email)}\"").size.should == 0 | ||
expect(emails("to: \"#{email_for(@user.email)}\"")).to be_empty | ||
end | ||
|
||
Then /^the email to "([^\"]*)" should contain "([^\"]*)"$/ do |user, text| | ||
Then "the email to {string} should contain {string}" do |user, text| | ||
@user = User.find_by(login: user) | ||
email = emails("to: \"#{email_for(@user.email)}\"").first | ||
if email.multipart? | ||
email.text_part.body.should =~ /#{text}/ | ||
email.html_part.body.should =~ /#{text}/ | ||
expect(email.text_part.body).to match(text) | ||
expect(email.html_part.body).to match(text) | ||
else | ||
email.body.should =~ /#{text}/ | ||
expect(email.body).to match(text) | ||
end | ||
end | ||
|
||
Then /^the email to "([^\"]*)" should not contain "([^\"]*)"$/ do |user, text| | ||
Then "the email to {string} should not contain {string}" do |user, text| | ||
@user = User.find_by(login: user) | ||
email = emails("to: \"#{email_for(@user.email)}\"").first | ||
if email.multipart? | ||
email.text_part.body.should_not =~ /#{text}/ | ||
email.html_part.body.should_not =~ /#{text}/ | ||
expect(email.text_part.body).not_to match(text) | ||
expect(email.html_part.body).not_to match(text) | ||
else | ||
email.body.should_not =~ /#{text}/ | ||
expect(email.body).not_to match(text) | ||
end | ||
end | ||
|
||
Then(/^"([^\"]*)" should receive (\d+) emails?$/) do |user, count| | ||
Then "{string} should receive {int} email(s)" do |user, count| | ||
@user = User.find_by(login: user) | ||
emails("to: \"#{email_for(@user.email)}\"").size.should == count.to_i | ||
expect(emails("to: \"#{email_for(@user.email)}\"").size).to eq(count.to_i) | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
class KudoMailerPreview < ApplicationMailerPreview | ||
# Sends a kudos notification | ||
def batch_kudo_notification | ||
user = create(:user) | ||
work = create(:work) | ||
guest_count = params[:guest_count] || 1 | ||
user_count = params[:user_count].to_i || 1 | ||
names = Array.new(user_count) { "User#{Faker::Alphanumeric.alpha(number: 8)}" } | ||
hash = { "Work_#{work.id}": { guest_count:, names: } } | ||
Check warning on line 9 in test/mailers/previews/kudo_mailer_preview.rb GitHub Actions / Rubocop
|
||
KudoMailer.batch_kudo_notification(user.id, hash.to_json) | ||
end | ||
end |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This syntax is new to Ruby 3.1 and the rubocop annotation is a false positive. Adding a space would make a different cop complain. This cop accepts the formatting starting with rubocop 1.24.0, we are on 1.22.3.