-
Notifications
You must be signed in to change notification settings - Fork 491
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
Changes from 3 commits
676f8cc
82a1efa
d2e4b06
8214473
cc07668
5360659
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,6 +168,21 @@ 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 "You've got kudos!" 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 | ||
|
||
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" | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,59 @@ | ||
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 | ||
language = Language.find_or_create_by(short: "new", name: "New") | ||
Locale.create(iso: "new", name: "New", language: language, email_enabled: true) | ||
# These keys are used in every email | ||
I18n.backend.store_translations(:new, { mailer: { general: { footer: { general: { about: { html: "Translated footer", text: "Translated footer" } } } } } }) | ||
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 | ||
|
||
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 "{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)}\"").size).to be_positive | ||
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 |
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
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
KudoMailer.batch_kudo_notification(user.id, hash.to_json) | ||
end | ||
end |
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 is a completely new language and locale to prevent the existing translations from interfering with the tests. Otherwise a test might break when a Phrase export changes a translation.