From 3a75c3446ede62c2571ba41a5bdf38c67c1f61db Mon Sep 17 00:00:00 2001 From: Konrad Date: Fri, 11 Jul 2025 10:46:17 +0200 Subject: [PATCH] Update backorder mailer specs to check that these hub facing emails remain unaffected by white labelling (there are no customer facing emails here) Also make use of the newly separated shared_examples --- spec/mailers/backorder_mailer_spec.rb | 29 +++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/spec/mailers/backorder_mailer_spec.rb b/spec/mailers/backorder_mailer_spec.rb index 0073c423ec..4c6858d9a9 100644 --- a/spec/mailers/backorder_mailer_spec.rb +++ b/spec/mailers/backorder_mailer_spec.rb @@ -6,18 +6,30 @@ RSpec.describe BackorderMailer do let(:order) { create(:completed_order_with_totals) } describe "#backorder_failed" do + subject(:mail) { described_class.backorder_failed(order) } + it "notifies the owner" do order.distributor.owner.email = "jane@example.net" BackorderMailer.backorder_failed(order).deliver_now - mail = ActionMailer::Base.deliveries.first - expect(mail.to).to eq ["jane@example.net"] - expect(mail.subject).to eq "An automatic backorder failed" + first_mail = ActionMailer::Base.deliveries.first + expect(first_mail.to).to eq ["jane@example.net"] + expect(first_mail.subject).to eq "An automatic backorder failed" + end + + context "white labelling" do + it_behaves_like 'email with inactive white labelling', :mail + it_behaves_like 'non-customer facing email with active white labelling', :mail end end describe "#backorder_incomplete" do + subject(:mail) { + described_class.backorder_incomplete( + user, distributor, order_cycle, order_id + ) + } let(:user) { build(:user, email: "jane@example.net") } let(:distributor) { build(:enterprise) } let(:order_cycle) { build(:order_cycle) } @@ -26,9 +38,14 @@ RSpec.describe BackorderMailer do it "notifies the owner" do BackorderMailer.backorder_incomplete(user, distributor, order_cycle, order_id).deliver_now - mail = ActionMailer::Base.deliveries.first - expect(mail.to).to eq ["jane@example.net"] - expect(mail.subject).to eq "An automatic backorder failed to complete" + first_mail = ActionMailer::Base.deliveries.first + expect(first_mail.to).to eq ["jane@example.net"] + expect(first_mail.subject).to eq "An automatic backorder failed to complete" + end + + context "white labelling" do + it_behaves_like 'email with inactive white labelling', :mail + it_behaves_like 'non-customer facing email with active white labelling', :mail end end end