diff --git a/spec/mailers/subscription_mailer_spec.rb b/spec/mailers/subscription_mailer_spec.rb index cca7e5258d..662317ad6e 100644 --- a/spec/mailers/subscription_mailer_spec.rb +++ b/spec/mailers/subscription_mailer_spec.rb @@ -6,7 +6,9 @@ describe SubscriptionMailer do let!(:mail_method) { create(:mail_method, preferred_mails_from: 'spree@example.com') } describe "order placement" do - let(:subscription) { create(:subscription, with_items: true) } + let(:shop) { create(:enterprise) } + let(:customer) { create(:customer, enterprise: shop) } + let(:subscription) { create(:subscription, shop: shop, customer: customer, with_items: true) } let(:proxy_order) { create(:proxy_order, subscription: subscription) } let!(:order) { proxy_order.initialise_order! } @@ -24,7 +26,6 @@ describe SubscriptionMailer do body = SubscriptionMailer.deliveries.last.body.encoded expect(body).to include "This order was automatically created for you." expect(body).to include "Unfortunately, not all products that you requested were available." - expect(body).to include "href=\"#{spree.order_url(order)}\"" end end @@ -39,7 +40,36 @@ describe SubscriptionMailer do body = SubscriptionMailer.deliveries.last.body.encoded expect(body).to include "This order was automatically created for you." expect(body).to_not include "Unfortunately, not all products that you requested were available." - expect(body).to include "href=\"#{spree.order_url(order)}\"" + end + end + + describe "linking to order page" do + let(:order_link_href) { "href=\"#{spree.order_url(order)}\"" } + let(:order_link_style) { "style='[^']+'" } + + let(:shop) { create(:enterprise, allow_order_changes: true) } + + let(:email) { SubscriptionMailer.deliveries.last } + let(:body) { email.body.encoded } + + before do + SubscriptionMailer.placement_email(order, {}).deliver + end + + let(:customer) { create(:customer, enterprise: shop) } + + it "provides link to make changes" do + expect(body).to match /make changes<\/a>/ + expect(body).to_not match /view details of this order<\/a>/ + end + + context "when the distributor does not allow changes to the order" do + let(:shop) { create(:enterprise, allow_order_changes: false) } + + it "provides link to view details" do + expect(body).to_not match /make changes<\/a>/ + expect(body).to match /view details of this order<\/a>/ + end end end end