Open Source Platform for DTC, B2B Commerce, Marketplaces & Omnichannel. REST APIs, TypeScript SDKs, and production-ready Next.js storefront. Self-host it. Own your data. No vendor lock-in. Zero platform fees.
Ruby b2b-commercee-commerceecommerceecommerce-apiecommerce-frameworkecommerce-platformheadlessheadless-commerceheadless-ecommercemarketplacemulti-tenantmulti-vendormulti-vendor-ecommerceopen-sourcespree-commerce
Rewrote shipment mailer spec to use actual objects and data
Damian Legawiec691b59bd96fd
diff --git a/emails/spec/mailers/spree/shipment_mailer_spec.rb b/emails/spec/mailers/spree/shipment_mailer_spec.rbindex d388b59825..1837218773 100644--- a/emails/spec/mailers/spree/shipment_mailer_spec.rb+++ b/emails/spec/mailers/spree/shipment_mailer_spec.rb@@ -7,36 +7,28 @@ describe Spree::ShipmentMailer, type: :mailer dolet!(:store) { create(:store) }- let(:order) { stub_model(Spree::Order, number: 'R12345', store: store, email: '[email protected]') }- let(:shipping_method) { stub_model(Spree::ShippingMethod, name: 'USPS') }- let(:product) { stub_model(Spree::Product, name: %{The "BEST" product}, sku: 'SKU0001') }- let(:variant) { stub_model(Spree::Variant, product: product) }- let(:line_item) { stub_model(Spree::LineItem, variant: variant, order: order, quantity: 1, price: 5) }- let(:shipment) do- shipment = stub_model(Spree::Shipment)- allow(shipment).to receive_messages(line_items: [line_item], order: order)- allow(shipment).to receive_messages(tracking_url: 'http://track.com/me')- allow(shipment).to receive_messages(shipping_method: shipping_method)- shipment- end+ let(:order) { create(:shipped_order, store: store, email: '[email protected]', user: nil) }+ let(:shipment) { order.shipments.first }+ let(:shipping_method) { shipment.shipping_method }++ before { shipping_method.update(tracking_url: 'http://example.com/tracking') }context ':from not set explicitly' doit 'falls back to spree config' do- message = Spree::ShipmentMailer.shipped_email(shipment)+ message = described_class.shipped_email(shipment)expect(message.from).to eq([store.mail_from_address])endend# Regression test for #2196it "doesn't include out of stock in the email body" do- shipment_email = Spree::ShipmentMailer.shipped_email(shipment)+ shipment_email = described_class.shipped_email(shipment)expect(shipment_email.body).not_to include(%q{Out of Stock})endit 'shipment_email accepts an shipment id as an alternative to an Shipment object' do- expect(Spree::Shipment).to receive(:find).with(shipment.id).and_return(shipment)expect do- Spree::ShipmentMailer.shipped_email(shipment.id).body+ described_class.shipped_email(shipment.id).bodyend.not_to raise_errorend@@ -55,7 +47,7 @@ describe Spree::ShipmentMailer, type: :mailer doendspecify do- shipped_email = Spree::ShipmentMailer.shipped_email(shipment)+ shipped_email = described_class.shipped_email(shipment)expect(shipped_email).to have_body_text('Caro Cliente,')endend@@ -63,7 +55,7 @@ describe Spree::ShipmentMailer, type: :mailer doendcontext 'shipped_email' do- let(:shipped_email) { Spree::ShipmentMailer.shipped_email(shipment) }+ let(:shipped_email) { described_class.shipped_email(shipment) }specify doexpect(shipped_email).to have_body_text(order.number)@@ -77,16 +69,8 @@ describe Spree::ShipmentMailer, type: :mailer doexpect(shipped_email).to have_body_text("href=\"#{shipment.tracking_url}\"")end- specify do- expect(shipped_email).to have_body_text('Dear Customer')- end-- context 'when order has customer\'s name' do- before { allow(order).to receive(:name).and_return('Test User') }-- specify 'shows order\'s user name in email body' do- expect(shipped_email).to have_body_text('Dear Test User')- end+ specify 'shows order\'s user name in email body' do+ expect(shipped_email).to have_body_text("Dear #{order.name}")endend