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
This commit is contained in:
Konrad
2025-05-25 18:43:15 +02:00
parent ab6a49e568
commit 183cbecef6

View File

@@ -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