Skip to content

Commit

Permalink
AO3-6042 Move test to user mailer
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilka2 committed Jan 7, 2024
1 parent a12dcd6 commit 0f9fafb
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 55 deletions.
55 changes: 0 additions & 55 deletions spec/mailers/kudo_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,59 +42,4 @@
end
end
end

describe "obeys the set locale preference feature flag" do
let(:user) { create(:user) }
let(:work) { create(:work, authors: [user.default_pseud]) }
let(:kudos_json) do
hash = {}
hash["#{work.class.name}_#{work.id}"] = { guest_count: 1, names: [] }
hash.to_json
end
let(:locale) { create(:locale) }

context "when the set locale preference feature flag is on" do
before { $rollout.activate_user(:set_locale_preference, user) }

context "and the user has non-default locale set" do
before { user.preference.update!(preferred_locale: locale.id) }

it "sends a localised email" do
expect(I18n).to receive(:with_locale).with(locale.iso)
expect(KudoMailer.batch_kudo_notification(user.id, kudos_json)).to be_truthy
end
end

context "and the user has the default locale set" do
before { user.preference.update!(preferred_locale: Locale.default.id) }

it "sends an English email" do
expect(I18n).to receive(:with_locale).with("en")
expect(KudoMailer.batch_kudo_notification(user.id, kudos_json)).to be_truthy
end
end
end

context "when the set locale preference feature flag is off" do
before { $rollout.deactivate_user(:set_locale_preference, user) }

context "and the user has non-default locale set" do
before { user.preference.update!(preferred_locale: locale.id) }

it "sends an English email" do
expect(I18n).to receive(:with_locale).with("en")
expect(KudoMailer.batch_kudo_notification(user.id, kudos_json)).to be_truthy
end
end

context "and the user has the default locale set" do
before { user.preference.update!(preferred_locale: Locale.default.id) }

it "sends an English email" do
expect(I18n).to receive(:with_locale).with("en")
expect(KudoMailer.batch_kudo_notification(user.id, kudos_json)).to be_truthy
end
end
end
end
end
50 changes: 50 additions & 0 deletions spec/mailers/user_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1200,4 +1200,54 @@
it_behaves_like "an email with a deleted work with draft chapters attached"
end
end

describe "obeys the set locale preference feature flag" do
let(:user) { create(:user) }
let(:work) { create(:work, authors: [user.default_pseud]) }
let(:locale) { create(:locale) }

context "when the set locale preference feature flag is on" do
before { $rollout.activate_user(:set_locale_preference, user) }

context "and the user has non-default locale set" do
before { user.preference.update!(preferred_locale: locale.id) }

it "sends a localised email" do
expect(I18n).to receive(:with_locale).with(locale.iso)
expect(UserMailer.admin_hidden_work_notification(work.id, user.id)).to be_truthy
end
end

context "and the user has the default locale set" do
before { user.preference.update!(preferred_locale: Locale.default.id) }

it "sends an English email" do
expect(I18n).to receive(:with_locale).with("en")
expect(UserMailer.admin_hidden_work_notification(work.id, user.id)).to be_truthy
end
end
end

context "when the set locale preference feature flag is off" do
before { $rollout.deactivate_user(:set_locale_preference, user) }

context "and the user has non-default locale set" do
before { user.preference.update!(preferred_locale: locale.id) }

it "sends an English email" do
expect(I18n).to receive(:with_locale).with("en")
expect(UserMailer.admin_hidden_work_notification(work.id, user.id)).to be_truthy
end
end

context "and the user has the default locale set" do
before { user.preference.update!(preferred_locale: Locale.default.id) }

it "sends an English email" do
expect(I18n).to receive(:with_locale).with("en")
expect(UserMailer.admin_hidden_work_notification(work.id, user.id)).to be_truthy
end
end
end
end
end

0 comments on commit 0f9fafb

Please sign in to comment.