From 183cbecef6fffb1cb1137529e83b44f33bf80219 Mon Sep 17 00:00:00 2001 From: Konrad Date: Sun, 25 May 2025 18:43:15 +0200 Subject: [PATCH] Update shipment mailer specs to check that customer facing emails are white labelled (there are no shop facing emails here) Make use of the newly separated shared_examples --- spec/mailers/shipment_mailer_spec.rb | 29 +++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/spec/mailers/shipment_mailer_spec.rb b/spec/mailers/shipment_mailer_spec.rb index bf234ce496..c1942b722f 100644 --- a/spec/mailers/shipment_mailer_spec.rb +++ b/spec/mailers/shipment_mailer_spec.rb @@ -3,8 +3,9 @@ require 'spec_helper' RSpec.describe Spree::ShipmentMailer do + let(:order) { build(:order_with_distributor) } + let(:shipment) do - order = build(:order_with_distributor) product = build(:product, name: %{The "BEST" product}) variant = build(:variant, product:) line_item = build(:line_item, variant:, order:, quantity: 1, price: 5) @@ -13,18 +14,26 @@ RSpec.describe Spree::ShipmentMailer do allow(shipment).to receive_messages(tracking_url: "TRACK_ME") shipment end + + let(:shipment_email) { described_class.shipped_email(shipment, delivery: true) } + let(:picked_up_email) { described_class.shipped_email(shipment, delivery: false) } let(:distributor) { shipment.order.distributor } context ":from not set explicitly" do it "falls back to spree config" do - message = Spree::ShipmentMailer.shipped_email(shipment, delivery: true) - expect(message.from).to eq [Spree::Config[:mails_from]] + expect(shipment_email.from).to eq [Spree::Config[:mails_from]] end end + context "white labelling" do + it_behaves_like 'email with inactive white labelling', :shipment_email + it_behaves_like 'customer facing email with active white labelling', :shipment_email + it_behaves_like 'email with inactive white labelling', :picked_up_email + it_behaves_like 'customer facing email with active white labelling', :picked_up_email + end + # Regression test for #2196 it "doesn't include out of stock in the email body" do - shipment_email = Spree::ShipmentMailer.shipped_email(shipment, delivery: true) expect(shipment_email.body).not_to include(%{Out of Stock}) end @@ -36,33 +45,27 @@ RSpec.describe Spree::ShipmentMailer do end it "includes the distributor's name in the subject" do - shipment_email = Spree::ShipmentMailer.shipped_email(shipment, delivery: true) expect(shipment_email.subject).to include("#{distributor.name} Shipment Notification") end it "includes the distributor's name in the body" do - shipment_email = Spree::ShipmentMailer.shipped_email(shipment, delivery: true) expect(shipment_email.body).to include("Your order from #{distributor.name} has been shipped") end it "picked_up email includes different text in body" do text = "Your order from #{distributor.name} has been picked-up" - picked_up_email = Spree::ShipmentMailer.shipped_email(shipment, delivery: false) expect(picked_up_email.body).to include(text) end it "picked_up email has different subject" do - shipment_email = Spree::ShipmentMailer.shipped_email(shipment, delivery: false) - expect(shipment_email.subject).to include("#{distributor.name} Pick up Notification") + expect(picked_up_email.subject).to include("#{distributor.name} Pick up Notification") end it "picked_up email has as the reply to email as the distributor" do - shipment_email = Spree::ShipmentMailer.shipped_email(shipment, delivery: false) - expect(shipment_email.reply_to).to eq([distributor.contact.email]) + expect(picked_up_email.reply_to).to eq([distributor.contact.email]) end - it "shipment_email email has as the reply to email as the distributor" do - shipment_email = Spree::ShipmentMailer.shipped_email(shipment, delivery: true) + it "shipment_email has as the reply to email as the distributor" do expect(shipment_email.reply_to).to eq([distributor.contact.email]) end end