Test order links in subscription placement emails

This commit is contained in:
Kristina Lim
2018-08-30 02:48:06 +08:00
parent a9c8c033c7
commit dc4037474d

View File

@@ -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 /<a #{order_link_href} #{order_link_style}>make changes<\/a>/
expect(body).to_not match /<a #{order_link_href} #{order_link_style}>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 /<a #{order_link_href} #{order_link_style}>make changes<\/a>/
expect(body).to match /<a #{order_link_href} #{order_link_style}>view details of this order<\/a>/
end
end
end
end