mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-03 02:21:33 +00:00
Merge pull request #13248 from drummer83/email_whitelabel
White labelling all customer facing emails
This commit is contained in:
@@ -6,6 +6,7 @@ class PaymentMailer < ApplicationMailer
|
||||
def authorize_payment(payment)
|
||||
@payment = payment
|
||||
@order = @payment.order
|
||||
@hide_ofn_navigation = @payment.order.distributor.hide_ofn_navigation
|
||||
I18n.with_locale valid_locale(@order.user) do
|
||||
mail(to: @order.email,
|
||||
subject: default_i18n_subject(distributor: @order.distributor.name),
|
||||
|
||||
@@ -11,6 +11,7 @@ module Spree
|
||||
|
||||
def cancel_email(order_or_order_id, resend = false)
|
||||
@order = find_order(order_or_order_id)
|
||||
@hide_ofn_navigation = @order.distributor.hide_ofn_navigation
|
||||
I18n.with_locale valid_locale(@order.user) do
|
||||
mail(to: @order.email,
|
||||
subject: mail_subject(t('spree.order_mailer.cancel_email.subject'), resend),
|
||||
@@ -51,6 +52,7 @@ module Spree
|
||||
|
||||
def invoice_email(order_or_order_id, options = {})
|
||||
@order = find_order(order_or_order_id)
|
||||
@hide_ofn_navigation = @order.distributor.hide_ofn_navigation
|
||||
current_user = if options[:current_user_id].present?
|
||||
find_user(options[:current_user_id])
|
||||
end
|
||||
|
||||
@@ -4,6 +4,7 @@ module Spree
|
||||
class ShipmentMailer < ApplicationMailer
|
||||
def shipped_email(shipment, delivery:)
|
||||
@shipment = shipment.respond_to?(:id) ? shipment : Spree::Shipment.find(shipment)
|
||||
@hide_ofn_navigation = @shipment.order.distributor.hide_ofn_navigation
|
||||
@delivery = delivery
|
||||
@order = @shipment.order
|
||||
subject = base_subject
|
||||
|
||||
@@ -19,6 +19,7 @@ class SubscriptionMailer < ApplicationMailer
|
||||
@type = 'empty'
|
||||
@changes = changes
|
||||
@order = order
|
||||
@hide_ofn_navigation = @order.distributor.hide_ofn_navigation
|
||||
send_mail(order)
|
||||
end
|
||||
|
||||
@@ -26,11 +27,13 @@ class SubscriptionMailer < ApplicationMailer
|
||||
@type = 'placement'
|
||||
@changes = changes
|
||||
@order = order
|
||||
@hide_ofn_navigation = @order.distributor.hide_ofn_navigation
|
||||
send_mail(order)
|
||||
end
|
||||
|
||||
def failed_payment_email(order)
|
||||
@order = order
|
||||
@hide_ofn_navigation = @order.distributor.hide_ofn_navigation
|
||||
send_mail(order)
|
||||
end
|
||||
|
||||
|
||||
@@ -4,18 +4,30 @@ RSpec.describe BackorderMailer do
|
||||
let(:order) { create(:completed_order_with_totals) }
|
||||
|
||||
describe "#backorder_failed" do
|
||||
subject(:mail) { described_class.backorder_failed(order) }
|
||||
|
||||
it "notifies the owner" do
|
||||
order.distributor.owner.email = "jane@example.net"
|
||||
|
||||
BackorderMailer.backorder_failed(order).deliver_now
|
||||
|
||||
mail = ActionMailer::Base.deliveries.first
|
||||
expect(mail.to).to eq ["jane@example.net"]
|
||||
expect(mail.subject).to eq "An automatic backorder failed"
|
||||
first_mail = ActionMailer::Base.deliveries.first
|
||||
expect(first_mail.to).to eq ["jane@example.net"]
|
||||
expect(first_mail.subject).to eq "An automatic backorder failed"
|
||||
end
|
||||
|
||||
context "white labelling" do
|
||||
it_behaves_like 'email with inactive white labelling', :mail
|
||||
it_behaves_like 'non-customer facing email with active white labelling', :mail
|
||||
end
|
||||
end
|
||||
|
||||
describe "#backorder_incomplete" do
|
||||
subject(:mail) {
|
||||
described_class.backorder_incomplete(
|
||||
user, distributor, order_cycle, order_id
|
||||
)
|
||||
}
|
||||
let(:user) { build(:user, email: "jane@example.net") }
|
||||
let(:distributor) { build(:enterprise) }
|
||||
let(:order_cycle) { build(:order_cycle) }
|
||||
@@ -24,9 +36,14 @@ RSpec.describe BackorderMailer do
|
||||
it "notifies the owner" do
|
||||
BackorderMailer.backorder_incomplete(user, distributor, order_cycle, order_id).deliver_now
|
||||
|
||||
mail = ActionMailer::Base.deliveries.first
|
||||
expect(mail.to).to eq ["jane@example.net"]
|
||||
expect(mail.subject).to eq "An automatic backorder failed to complete"
|
||||
first_mail = ActionMailer::Base.deliveries.first
|
||||
expect(first_mail.to).to eq ["jane@example.net"]
|
||||
expect(first_mail.subject).to eq "An automatic backorder failed to complete"
|
||||
end
|
||||
|
||||
context "white labelling" do
|
||||
it_behaves_like 'email with inactive white labelling', :mail
|
||||
it_behaves_like 'non-customer facing email with active white labelling', :mail
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,9 +2,10 @@
|
||||
|
||||
RSpec.describe EnterpriseMailer do
|
||||
let(:enterprise) { build(:enterprise, name: "Fred's Farm") }
|
||||
let(:order) { build(:order_with_distributor) }
|
||||
|
||||
describe "#welcome" do
|
||||
subject(:mail) { EnterpriseMailer.welcome(enterprise) }
|
||||
subject(:mail) { described_class.welcome(enterprise) }
|
||||
|
||||
it "sends a welcome email when given an enterprise" do
|
||||
expect(mail.subject)
|
||||
@@ -14,10 +15,15 @@ RSpec.describe EnterpriseMailer do
|
||||
it "does not set a reply-to email" do
|
||||
expect(mail.reply_to).to eq nil
|
||||
end
|
||||
|
||||
context "white labelling" do
|
||||
it_behaves_like 'email with inactive white labelling', :mail
|
||||
it_behaves_like 'non-customer facing email with active white labelling', :mail
|
||||
end
|
||||
end
|
||||
|
||||
describe "#manager_invitation" do
|
||||
subject(:mail) { EnterpriseMailer.manager_invitation(enterprise, user) }
|
||||
subject(:mail) { described_class.manager_invitation(enterprise, user) }
|
||||
let(:user) { build(:user) }
|
||||
|
||||
it "should send a manager invitation email when given an enterprise and user" do
|
||||
@@ -27,5 +33,10 @@ RSpec.describe EnterpriseMailer do
|
||||
it "sets a reply-to of the enterprise email" do
|
||||
expect(mail.reply_to).to eq([enterprise.contact.email])
|
||||
end
|
||||
|
||||
context "white labelling" do
|
||||
it_behaves_like 'email with inactive white labelling', :mail
|
||||
it_behaves_like 'non-customer facing email with active white labelling', :mail
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,19 +2,24 @@
|
||||
|
||||
RSpec.describe Spree::OrderMailer do
|
||||
describe '#confirm_email_for_customer' do
|
||||
subject(:email) { described_class.confirm_email_for_customer(order) }
|
||||
subject(:mail) { described_class.confirm_email_for_customer(order) }
|
||||
|
||||
let(:order) { build(:order_with_totals_and_distribution) }
|
||||
|
||||
context "white labelling" do
|
||||
it_behaves_like 'email with inactive white labelling', :mail
|
||||
it_behaves_like 'customer facing email with active white labelling', :mail
|
||||
end
|
||||
|
||||
it 'renders the shared/_payment.html.haml partial' do
|
||||
expect(email.body).to include('Payment summary')
|
||||
expect(mail.body).to include('Payment summary')
|
||||
end
|
||||
|
||||
context 'when the order has outstanding balance' do
|
||||
before { allow(order).to receive(:new_outstanding_balance) { 123 } }
|
||||
|
||||
it 'renders the amount as money' do
|
||||
expect(email.body).to include('$123')
|
||||
expect(mail.body).to include('$123')
|
||||
end
|
||||
end
|
||||
|
||||
@@ -22,18 +27,18 @@ RSpec.describe Spree::OrderMailer do
|
||||
before { allow(order).to receive(:new_outstanding_balance) { 0 } }
|
||||
|
||||
it 'displays the payment status' do
|
||||
expect(email.body).to include('NOT PAID')
|
||||
expect(mail.body).to include('NOT PAID')
|
||||
end
|
||||
end
|
||||
|
||||
context "when :from is not set explicitly" do
|
||||
it "falls back to spree config" do
|
||||
expect(email.from).to eq [Spree::Config[:mails_from]]
|
||||
expect(mail.from).to eq [Spree::Config[:mails_from]]
|
||||
end
|
||||
end
|
||||
|
||||
it "doesn't aggressively escape double quotes body" do
|
||||
expect(email.body).not_to include(""")
|
||||
expect(mail.body).not_to include(""")
|
||||
end
|
||||
|
||||
it "accepts an order id as an alternative to an Order object" do
|
||||
@@ -42,46 +47,37 @@ RSpec.describe Spree::OrderMailer do
|
||||
described_class.confirm_email_for_customer(order.id).deliver_now
|
||||
}.not_to raise_error
|
||||
end
|
||||
|
||||
it "display the OFN header by default" do
|
||||
expect(email.body).to include(ContentConfig.url_for(:logo))
|
||||
end
|
||||
|
||||
context 'when hide OFN navigation is enabled for the distributor of the order' do
|
||||
before do
|
||||
allow(order.distributor).to receive(:hide_ofn_navigation).and_return(true)
|
||||
end
|
||||
|
||||
it 'does not display the OFN navigation' do
|
||||
expect(email.body).not_to include(ContentConfig.url_for(:logo))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#confirm_email_for_shop' do
|
||||
subject(:email) { described_class.confirm_email_for_shop(order) }
|
||||
subject(:mail) { described_class.confirm_email_for_shop(order) }
|
||||
|
||||
let(:order) { build(:order_with_totals_and_distribution) }
|
||||
|
||||
context "white labelling" do
|
||||
it_behaves_like 'email with inactive white labelling', :mail
|
||||
it_behaves_like 'non-customer facing email with active white labelling', :mail
|
||||
end
|
||||
|
||||
it 'renders the shared/_payment.html.haml partial' do
|
||||
expect(email.body).to include('Payment summary')
|
||||
expect(mail.body).to include('Payment summary')
|
||||
end
|
||||
|
||||
it "sets a reply-to of the customer email" do
|
||||
expect(email.reply_to).to eq([order.email])
|
||||
expect(mail.reply_to).to eq([order.email])
|
||||
end
|
||||
|
||||
context 'when the order has outstanding balance' do
|
||||
before { allow(order).to receive(:new_outstanding_balance) { 123 } }
|
||||
|
||||
it 'renders the amount as money' do
|
||||
expect(email.body).to include('$123')
|
||||
expect(mail.body).to include('$123')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when the order has no outstanding balance' do
|
||||
it 'displays the payment status' do
|
||||
expect(email.body).to include('NOT PAID')
|
||||
expect(mail.body).to include('NOT PAID')
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -149,6 +145,11 @@ RSpec.describe Spree::OrderMailer do
|
||||
expect(mail.to).to eq([distributor.contact.email])
|
||||
end
|
||||
|
||||
context "white labelling" do
|
||||
it_behaves_like 'email with inactive white labelling', :mail
|
||||
it_behaves_like 'non-customer facing email with active white labelling', :mail
|
||||
end
|
||||
|
||||
it "includes a link to the cancelled order in admin" do
|
||||
expect(mail.body).to match /#{admin_order_link_href}/
|
||||
end
|
||||
@@ -167,6 +168,11 @@ RSpec.describe Spree::OrderMailer do
|
||||
expect(mail.to).to eq([order.email])
|
||||
end
|
||||
|
||||
context "white labelling" do
|
||||
it_behaves_like 'email with inactive white labelling', :mail
|
||||
it_behaves_like 'customer facing email with active white labelling', :mail
|
||||
end
|
||||
|
||||
it "displays the order number" do
|
||||
expect(mail.body).to include(order.number.to_s)
|
||||
end
|
||||
@@ -176,7 +182,7 @@ RSpec.describe Spree::OrderMailer do
|
||||
end
|
||||
end
|
||||
|
||||
describe "order confimation" do
|
||||
describe "order confirmation" do
|
||||
let(:bill_address) { create(:address) }
|
||||
let(:distributor_address) {
|
||||
create(:address, address1: "distributor address", city: 'The Shire', zipcode: "1234")
|
||||
@@ -242,7 +248,7 @@ RSpec.describe Spree::OrderMailer do
|
||||
end
|
||||
|
||||
describe "#invoice_email" do
|
||||
subject(:email) { described_class.invoice_email(order) }
|
||||
subject(:mail) { described_class.invoice_email(order) }
|
||||
let(:order) { create(:completed_order_with_totals) }
|
||||
let!(:invoice_data_generator){ InvoiceDataGenerator.new(order) }
|
||||
let!(:invoice){
|
||||
@@ -259,17 +265,17 @@ RSpec.describe Spree::OrderMailer do
|
||||
allow(InvoiceRenderer).to receive(:new).and_return(renderer)
|
||||
end
|
||||
context "When invoices feature is not enabled" do
|
||||
it "should call the invoice render with order as argument" do
|
||||
it "should call the invoice renderer with order as argument" do
|
||||
expect(generator).not_to receive(:generate_or_update_latest_invoice)
|
||||
expect(order).not_to receive(:invoices)
|
||||
expect(renderer).to receive(:render_to_string).with(order, nil).and_return("invoice")
|
||||
expect {
|
||||
email.deliver_now
|
||||
mail.deliver_now
|
||||
}.not_to raise_error
|
||||
expect(deliveries.count).to eq(1)
|
||||
expect(deliveries.first.attachments.count).to eq(1)
|
||||
expect(deliveries.first.attachments.first.filename).to eq(attachment_filename)
|
||||
expect(email.reply_to).to eq([order.distributor.contact.email])
|
||||
expect(mail.reply_to).to eq([order.distributor.contact.email])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -278,7 +284,7 @@ RSpec.describe Spree::OrderMailer do
|
||||
expect(generator).to receive(:generate_or_update_latest_invoice)
|
||||
expect(order).to receive(:invoices).and_return([invoice])
|
||||
expect(renderer).to receive(:render_to_string).with(invoice.presenter, nil)
|
||||
email.deliver_now
|
||||
mail.deliver_now
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -11,32 +11,42 @@ RSpec.describe PaymentMailer do
|
||||
let(:order) { create(:completed_order_with_totals) }
|
||||
|
||||
context "authorize payment email" do
|
||||
subject(:email) { described_class.authorize_payment(payment) }
|
||||
subject(:mail) { described_class.authorize_payment(payment) }
|
||||
|
||||
it "includes the distributor's name in the subject" do
|
||||
order.distributor.name = "Fennel Farmer"
|
||||
expect(email.subject).to include("authorize your payment to Fennel Farmer")
|
||||
expect(mail.subject).to include("authorize your payment to Fennel Farmer")
|
||||
end
|
||||
|
||||
it "sets a reply-to of the customer email" do
|
||||
expect(email.reply_to).to eq([order.distributor.contact.email])
|
||||
expect(mail.reply_to).to eq([order.distributor.contact.email])
|
||||
end
|
||||
|
||||
context "white labelling" do
|
||||
it_behaves_like 'email with inactive white labelling', :mail
|
||||
it_behaves_like 'customer facing email with active white labelling', :mail
|
||||
end
|
||||
|
||||
it "includes a link to authorize the payment" do
|
||||
link = "http://test.host/payments/#{payment.id}/authorize"
|
||||
expect(email.body).to have_link link, href: link
|
||||
expect(mail.body).to have_link link, href: link
|
||||
end
|
||||
end
|
||||
|
||||
context "authorization required email" do
|
||||
subject(:email) { described_class.authorization_required(payment) }
|
||||
subject(:mail) { described_class.authorization_required(payment) }
|
||||
|
||||
it "includes the distributor's name in the subject" do
|
||||
expect(email.subject).to include("A payment requires authorization from the customer")
|
||||
expect(mail.subject).to include("A payment requires authorization from the customer")
|
||||
end
|
||||
|
||||
it "sets a reply-to of the customer email" do
|
||||
expect(email.reply_to).to eq([order.email])
|
||||
expect(mail.reply_to).to eq([order.email])
|
||||
end
|
||||
|
||||
context "white labelling" do
|
||||
it_behaves_like 'email with inactive white labelling', :mail
|
||||
it_behaves_like 'non-customer facing email with active white labelling', :mail
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -65,6 +65,11 @@ RSpec.describe ProducerMailer do
|
||||
expect(mail.reply_to).to eq [order_cycle.coordinator.contact.email]
|
||||
end
|
||||
|
||||
context "white labelling" do
|
||||
it_behaves_like 'email with inactive white labelling', :mail
|
||||
it_behaves_like 'non-customer facing email with active white labelling', :mail
|
||||
end
|
||||
|
||||
it "includes the pickup time for each distributor" do
|
||||
expect(mail.body.encoded).to include "#{d1.name} (Tue, 23rd Dec)"
|
||||
end
|
||||
|
||||
@@ -2,25 +2,31 @@
|
||||
|
||||
RSpec.describe ReportMailer do
|
||||
describe "#report_ready" do
|
||||
subject(:email) {
|
||||
subject(:mail) {
|
||||
ReportMailer.with(
|
||||
to: "current_user@example.net",
|
||||
blob:,
|
||||
).report_ready
|
||||
}
|
||||
let(:blob) { ReportBlob.create_locally!("customers.csv", "report content") }
|
||||
let(:order) { build(:order_with_distributor) }
|
||||
|
||||
context "white labelling" do
|
||||
it_behaves_like 'email with inactive white labelling', :mail
|
||||
it_behaves_like 'non-customer facing email with active white labelling', :mail
|
||||
end
|
||||
|
||||
it "notifies about a report" do
|
||||
expect(email.subject).to eq "Report ready"
|
||||
expect(email.body).to have_content "Report ready for download"
|
||||
expect(mail.subject).to eq "Report ready"
|
||||
expect(mail.body).to have_content "Report ready for download"
|
||||
end
|
||||
|
||||
it "notifies the user" do
|
||||
expect(email.to).to eq ["current_user@example.net"]
|
||||
expect(mail.to).to eq ["current_user@example.net"]
|
||||
end
|
||||
|
||||
it "contains a download link" do
|
||||
expect(email.body).to have_link(
|
||||
expect(mail.body).to have_link(
|
||||
"customers.csv",
|
||||
href: %r"^http://test\.host/rails/active_storage/disk/.*/customers\.csv$"
|
||||
)
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
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)
|
||||
@@ -11,18 +12,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
|
||||
|
||||
@@ -34,33 +43,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
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
RSpec.describe SubscriptionMailer do
|
||||
include ActionView::Helpers::SanitizeHelper
|
||||
|
||||
describe '#placement_email' do
|
||||
subject(:email) { SubscriptionMailer.placement_email(order, changes) }
|
||||
describe '#placement_email (customer)' do
|
||||
subject(:mail) { described_class.placement_email(order, changes) }
|
||||
let(:changes) { {} }
|
||||
|
||||
let(:shop) { create(:enterprise) }
|
||||
@@ -13,11 +13,16 @@ RSpec.describe SubscriptionMailer do
|
||||
let(:proxy_order) { create(:proxy_order, subscription:) }
|
||||
let!(:order) { proxy_order.initialise_order! }
|
||||
|
||||
context "white labelling" do
|
||||
it_behaves_like 'email with inactive white labelling', :mail
|
||||
it_behaves_like 'customer facing email with active white labelling', :mail
|
||||
end
|
||||
|
||||
context "when changes have been made to the order" do
|
||||
before { changes[order.line_items.first.id] = 2 }
|
||||
|
||||
it "sends the email, which notifies the customer of changes made" do
|
||||
expect { email.deliver_now }.to change { SubscriptionMailer.deliveries.count }.by(1)
|
||||
expect { mail.deliver_now }.to change { SubscriptionMailer.deliveries.count }.by(1)
|
||||
|
||||
body = SubscriptionMailer.deliveries.last.body.encoded
|
||||
|
||||
@@ -28,7 +33,7 @@ RSpec.describe SubscriptionMailer do
|
||||
|
||||
context "and changes have not been made to the order" do
|
||||
it "sends the email" do
|
||||
expect { email.deliver_now }.to change { SubscriptionMailer.deliveries.count }.by(1)
|
||||
expect { mail.deliver_now }.to change { SubscriptionMailer.deliveries.count }.by(1)
|
||||
|
||||
body = SubscriptionMailer.deliveries.last.body.encoded
|
||||
|
||||
@@ -44,7 +49,7 @@ RSpec.describe SubscriptionMailer do
|
||||
let(:content) { Capybara::Node::Simple.new(body) }
|
||||
let(:body) { SubscriptionMailer.deliveries.last.body.encoded }
|
||||
|
||||
before { email.deliver_now }
|
||||
before { mail.deliver_now }
|
||||
|
||||
context "when the customer has a user account" do
|
||||
let(:customer) { create(:customer, enterprise: shop) }
|
||||
@@ -85,7 +90,7 @@ RSpec.describe SubscriptionMailer do
|
||||
before { allow(order).to receive(:new_outstanding_balance) { 123 } }
|
||||
|
||||
it 'renders the amount as money' do
|
||||
expect(email.body).to include('$123')
|
||||
expect(mail.body).to include('$123')
|
||||
end
|
||||
end
|
||||
|
||||
@@ -93,13 +98,13 @@ RSpec.describe SubscriptionMailer do
|
||||
before { allow(order).to receive(:new_outstanding_balance) { 0 } }
|
||||
|
||||
it 'displays the payment status' do
|
||||
expect(email.body).to include('NOT PAID')
|
||||
expect(mail.body).to include('NOT PAID')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#confirmation_email' do
|
||||
subject(:email) { SubscriptionMailer.confirmation_email(order) }
|
||||
describe '#confirmation_email (customer)' do
|
||||
subject(:mail) { described_class.confirmation_email(order) }
|
||||
|
||||
let(:customer) { create(:customer) }
|
||||
let(:subscription) { create(:subscription, customer:, with_items: true) }
|
||||
@@ -108,14 +113,15 @@ RSpec.describe SubscriptionMailer do
|
||||
let(:user) { order.user }
|
||||
|
||||
it "sends the email" do
|
||||
expect { email.deliver_now }.to change{ SubscriptionMailer.deliveries.count }.by(1)
|
||||
expect { mail.deliver_now }.to change{ SubscriptionMailer.deliveries.count }.by(1)
|
||||
|
||||
body = SubscriptionMailer.deliveries.last.body.encoded
|
||||
expect(body).to include "This order was automatically placed for you"
|
||||
end
|
||||
|
||||
it "display the OFN header by default" do
|
||||
expect(email.body).to include(ContentConfig.url_for(:logo))
|
||||
context "white labelling" do
|
||||
it_behaves_like 'email with inactive white labelling', :mail
|
||||
it_behaves_like 'customer facing email with active white labelling', :mail
|
||||
end
|
||||
|
||||
describe "linking to order page" do
|
||||
@@ -125,7 +131,7 @@ RSpec.describe SubscriptionMailer do
|
||||
let(:customer) { create(:customer) }
|
||||
|
||||
it "provides link to view details" do
|
||||
expect(email.body.encoded).to include(order_url(order))
|
||||
expect(mail.body.encoded).to include(order_url(order))
|
||||
end
|
||||
end
|
||||
|
||||
@@ -133,7 +139,7 @@ RSpec.describe SubscriptionMailer do
|
||||
let(:customer) { create(:customer, user: nil) }
|
||||
|
||||
it "does not provide link" do
|
||||
expect(email.body).not_to match /#{order_link_href}/
|
||||
expect(mail.body).not_to match /#{order_link_href}/
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -142,7 +148,7 @@ RSpec.describe SubscriptionMailer do
|
||||
before { allow(order).to receive(:new_outstanding_balance) { 123 } }
|
||||
|
||||
it 'renders the amount as money' do
|
||||
expect(email.body).to include('$123')
|
||||
expect(mail.body).to include('$123')
|
||||
end
|
||||
end
|
||||
|
||||
@@ -150,40 +156,36 @@ RSpec.describe SubscriptionMailer do
|
||||
before { allow(order).to receive(:new_outstanding_balance) { 0 } }
|
||||
|
||||
it 'displays the payment status' do
|
||||
expect(email.body).to include('NOT PAID')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when hide OFN navigation is enabled for the distributor of the order' do
|
||||
before do
|
||||
allow(order.distributor).to receive(:hide_ofn_navigation).and_return(true)
|
||||
end
|
||||
|
||||
it 'does not display the OFN navigation' do
|
||||
expect(email.body).not_to include(ContentConfig.url_for(:logo))
|
||||
expect(mail.body).to include('NOT PAID')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe "empty order notification" do
|
||||
describe "#empty_order_email (customer)" do
|
||||
subject(:mail) { described_class.empty_email(order, {}) }
|
||||
|
||||
let(:subscription) { create(:subscription, with_items: true) }
|
||||
let(:proxy_order) { create(:proxy_order, subscription:) }
|
||||
let(:distributor) { create(:distributor_enterprise) }
|
||||
let!(:order) { proxy_order.initialise_order! }
|
||||
|
||||
before do
|
||||
expect do
|
||||
SubscriptionMailer.empty_email(order, {}).deliver_now
|
||||
end.to change{ SubscriptionMailer.deliveries.count }.by(1)
|
||||
context "white labelling" do
|
||||
it_behaves_like 'email with inactive white labelling', :mail
|
||||
it_behaves_like 'customer facing email with active white labelling', :mail
|
||||
end
|
||||
|
||||
it "sends the email" do
|
||||
expect { mail.deliver_now }.to change{ SubscriptionMailer.deliveries.count }.by(1)
|
||||
|
||||
body = SubscriptionMailer.deliveries.last.body.encoded
|
||||
expect(body).to include "We tried to place a new order with"
|
||||
expect(body).to include "Unfortunately, none of products that you ordered were available"
|
||||
end
|
||||
end
|
||||
|
||||
describe "failed payment notification" do
|
||||
describe "#failed_payment_email (customer)" do
|
||||
subject(:mail) { described_class.failed_payment_email(order) }
|
||||
|
||||
let(:customer) { create(:customer) }
|
||||
let(:subscription) { create(:subscription, customer:, with_items: true) }
|
||||
let(:proxy_order) { create(:proxy_order, subscription:) }
|
||||
@@ -191,13 +193,16 @@ RSpec.describe SubscriptionMailer do
|
||||
|
||||
before do
|
||||
order.errors.add(:base, "This is a payment failure error")
|
||||
end
|
||||
|
||||
expect do
|
||||
SubscriptionMailer.failed_payment_email(order).deliver_now
|
||||
end.to change{ SubscriptionMailer.deliveries.count }.by(1)
|
||||
context "white labelling" do
|
||||
it_behaves_like 'email with inactive white labelling', :mail
|
||||
it_behaves_like 'customer facing email with active white labelling', :mail
|
||||
end
|
||||
|
||||
it "sends the email" do
|
||||
expect { mail.deliver_now }.to change{ SubscriptionMailer.deliveries.count }.by(1)
|
||||
|
||||
body = strip_tags(SubscriptionMailer.deliveries.last.body.encoded)
|
||||
expect(body).to include 'We tried to process a payment, but had some problems...'
|
||||
email_so_failed_payment_explainer_html = "The payment for your subscription with <strong>%s" \
|
||||
@@ -212,10 +217,8 @@ RSpec.describe SubscriptionMailer do
|
||||
end
|
||||
|
||||
describe "linking to order page" do
|
||||
let(:order_link_href) { "href=\"#{order_url(order)}\"" }
|
||||
|
||||
let(:email) { SubscriptionMailer.deliveries.last }
|
||||
let(:body) { email.body.encoded }
|
||||
let(:order_link_href) { "href=['\"]#{order_url(order)}['\"]" }
|
||||
let(:body) { mail.body.encoded }
|
||||
|
||||
context "when the customer has a user account" do
|
||||
let(:customer) { create(:customer) }
|
||||
@@ -235,28 +238,37 @@ RSpec.describe SubscriptionMailer do
|
||||
end
|
||||
end
|
||||
|
||||
describe "order placement summary" do
|
||||
describe "#order_placement_summary_email (hub)" do
|
||||
subject(:mail) { described_class.placement_summary_email(summary) }
|
||||
|
||||
let!(:shop) { create(:enterprise, :with_logo_image) }
|
||||
let!(:summary) { double(:summary, shop_id: shop.id) }
|
||||
let(:body) { strip_tags(SubscriptionMailer.deliveries.last.body.encoded) }
|
||||
let(:scope) { "subscription_mailer" }
|
||||
let(:order) { build(:order_with_distributor) }
|
||||
|
||||
before do
|
||||
allow(summary).to receive(:unrecorded_ids) { [] }
|
||||
allow(summary).to receive(:subscription_issues) { [] }
|
||||
allow(summary).to receive(:order_count) { 37 }
|
||||
allow(summary).to receive(:issue_count) { 0 }
|
||||
allow(summary).to receive(:issues) { {} }
|
||||
end
|
||||
|
||||
it "renders the shop's logo" do
|
||||
mail.deliver_now
|
||||
expect(SubscriptionMailer.deliveries.last.body).to include "logo.png"
|
||||
end
|
||||
|
||||
context "white labelling" do
|
||||
it_behaves_like 'email with inactive white labelling', :mail
|
||||
it_behaves_like 'non-customer facing email with active white labelling', :mail
|
||||
end
|
||||
|
||||
context "when no issues were encountered while processing subscriptions" do
|
||||
before do
|
||||
allow(summary).to receive(:order_count) { 37 }
|
||||
allow(summary).to receive(:issue_count) { 0 }
|
||||
allow(summary).to receive(:issues) { {} }
|
||||
end
|
||||
|
||||
it "sends the email, which notifies the enterprise that all orders " \
|
||||
"were successfully processed" do
|
||||
SubscriptionMailer.placement_summary_email(summary).deliver_now
|
||||
|
||||
mail.deliver_now
|
||||
expect(body).to include("Below is a summary of the subscription orders " \
|
||||
"that have just been placed for %s." % shop.name)
|
||||
expect(body).to include("A total of %d subscriptions were marked " \
|
||||
@@ -264,11 +276,6 @@ RSpec.describe SubscriptionMailer do
|
||||
expect(body).to include 'All were processed successfully.'
|
||||
expect(body).not_to include 'Details of the issues encountered are provided below.'
|
||||
end
|
||||
|
||||
it "renders the shop's logo" do
|
||||
SubscriptionMailer.placement_summary_email(summary).deliver_now
|
||||
expect(SubscriptionMailer.deliveries.last.body).to include "logo.png"
|
||||
end
|
||||
end
|
||||
|
||||
context "when some issues were encountered while processing subscriptions" do
|
||||
@@ -287,7 +294,7 @@ RSpec.describe SubscriptionMailer do
|
||||
|
||||
context "when no unrecorded issues are present" do
|
||||
it "sends the email, which notifies the enterprise that some issues were encountered" do
|
||||
SubscriptionMailer.placement_summary_email(summary).deliver_now
|
||||
mail.deliver_now
|
||||
expect(body).to include("Below is a summary of the subscription orders " \
|
||||
"that have just been placed for %s." % shop.name)
|
||||
expect(body).to include("A total of %d subscriptions were marked " \
|
||||
@@ -318,7 +325,7 @@ RSpec.describe SubscriptionMailer do
|
||||
|
||||
it "sends the email, which notifies the enterprise that some issues were encountered" do
|
||||
expect(summary).to receive(:orders_affected_by).with(:other) { [order3, order4] }
|
||||
SubscriptionMailer.placement_summary_email(summary).deliver_now
|
||||
mail.deliver_now
|
||||
expect(body).to include("Error Encountered (%d orders)" % 2)
|
||||
expect(body).to include 'Automatic processing of these orders failed due to an error. ' \
|
||||
'The error has been listed where possible.'
|
||||
@@ -344,7 +351,7 @@ RSpec.describe SubscriptionMailer do
|
||||
allow(summary).to receive(:issue_count) { 2 }
|
||||
allow(summary).to receive(:issues) { { changes: { 1 => nil, 2 => nil } } }
|
||||
allow(summary).to receive(:orders_affected_by) { [order1, order2] }
|
||||
SubscriptionMailer.placement_summary_email(summary).deliver_now
|
||||
mail.deliver_now
|
||||
end
|
||||
|
||||
it "sends the email, which notifies the enterprise that some issues were encountered" do
|
||||
@@ -368,24 +375,29 @@ RSpec.describe SubscriptionMailer do
|
||||
end
|
||||
end
|
||||
|
||||
describe "order confirmation summary" do
|
||||
describe "#order_confirmation_summary_email (hub)" do
|
||||
subject(:mail) { SubscriptionMailer.confirmation_summary_email(summary) }
|
||||
let!(:shop) { create(:enterprise) }
|
||||
let!(:summary) { double(:summary, shop_id: shop.id) }
|
||||
let(:body) { strip_tags(SubscriptionMailer.deliveries.last.body.encoded) }
|
||||
let(:scope) { "subscription_mailer" }
|
||||
let(:order) { build(:order_with_distributor) }
|
||||
|
||||
before do
|
||||
allow(summary).to receive(:unrecorded_ids) { [] }
|
||||
allow(summary).to receive(:subscription_issues) { [] }
|
||||
allow(summary).to receive(:order_count) { 37 }
|
||||
allow(summary).to receive(:issue_count) { 0 }
|
||||
allow(summary).to receive(:issues) { {} }
|
||||
end
|
||||
|
||||
context "white labelling" do
|
||||
it_behaves_like 'email with inactive white labelling', :mail
|
||||
it_behaves_like 'non-customer facing email with active white labelling', :mail
|
||||
end
|
||||
|
||||
context "when no issues were encountered while processing subscriptions" do
|
||||
before do
|
||||
allow(summary).to receive(:order_count) { 37 }
|
||||
allow(summary).to receive(:issue_count) { 0 }
|
||||
allow(summary).to receive(:issues) { {} }
|
||||
SubscriptionMailer.confirmation_summary_email(summary).deliver_now
|
||||
end
|
||||
before { mail.deliver_now }
|
||||
|
||||
it "sends the email, which notifies the enterprise " \
|
||||
"that all orders were successfully processed" do
|
||||
@@ -414,7 +426,7 @@ RSpec.describe SubscriptionMailer do
|
||||
|
||||
context "when no unrecorded issues are present" do
|
||||
it "sends the email, which notifies the enterprise that some issues were encountered" do
|
||||
SubscriptionMailer.confirmation_summary_email(summary).deliver_now
|
||||
mail.deliver_now
|
||||
expect(body).to include("Below is a summary of the subscription orders " \
|
||||
"that have just been finalised for %s." % shop.name)
|
||||
expect(body).to include("A total of %d subscriptions were marked " \
|
||||
@@ -445,7 +457,7 @@ RSpec.describe SubscriptionMailer do
|
||||
|
||||
it "sends the email, which notifies the enterprise that some issues were encountered" do
|
||||
expect(summary).to receive(:orders_affected_by).with(:other) { [order3, order4] }
|
||||
SubscriptionMailer.confirmation_summary_email(summary).deliver_now
|
||||
mail.deliver_now
|
||||
expect(body).to include("Failed Payment (%d orders)" % 2)
|
||||
expect(body).to include 'Automatic processing of payment for these orders failed ' \
|
||||
'due to an error. The error has been listed where possible.'
|
||||
@@ -471,7 +483,7 @@ RSpec.describe SubscriptionMailer do
|
||||
allow(summary).to receive(:issue_count) { 2 }
|
||||
allow(summary).to receive(:issues) { { changes: { 1 => nil, 2 => nil } } }
|
||||
allow(summary).to receive(:orders_affected_by) { [order1, order2] }
|
||||
SubscriptionMailer.confirmation_summary_email(summary).deliver_now
|
||||
mail.deliver_now
|
||||
end
|
||||
|
||||
it "sends the email, which notifies the enterprise that some issues were encountered" do
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe Spree::TestMailer do
|
||||
subject(:mail) { described_class.test_email(order) }
|
||||
let(:user) { create(:user) }
|
||||
let(:order) { build(:order_with_distributor) }
|
||||
|
||||
context ":from not set explicitly" do
|
||||
it "falls back to spree config" do
|
||||
@@ -16,4 +18,8 @@ RSpec.describe Spree::TestMailer do
|
||||
Spree::TestMailer.test_email(user.id).deliver_now
|
||||
}.not_to raise_error
|
||||
end
|
||||
|
||||
context "white labelling" do
|
||||
it_behaves_like 'email with inactive white labelling', :mail
|
||||
end
|
||||
end
|
||||
|
||||
@@ -2,14 +2,19 @@
|
||||
|
||||
RSpec.describe Spree::UserMailer do
|
||||
let(:user) { build(:user) }
|
||||
let(:order) { build(:order_with_totals_and_distribution) }
|
||||
|
||||
before { ActionMailer::Base.deliveries.clear }
|
||||
|
||||
describe '#signup_confirmation' do
|
||||
subject(:mail) { Spree::UserMailer.signup_confirmation(user) }
|
||||
|
||||
it "sends email when given a user" do
|
||||
Spree::UserMailer.signup_confirmation(user).deliver_now
|
||||
mail.deliver_now
|
||||
expect(ActionMailer::Base.deliveries.count).to eq(1)
|
||||
end
|
||||
|
||||
describe "user locale" do
|
||||
context "user locale handling" do
|
||||
around do |example|
|
||||
original_default_locale = I18n.default_locale
|
||||
I18n.default_locale = 'pt'
|
||||
@@ -19,16 +24,21 @@ RSpec.describe Spree::UserMailer do
|
||||
|
||||
it "sends email in user locale when user locale is defined" do
|
||||
user.locale = 'es'
|
||||
Spree::UserMailer.signup_confirmation(user).deliver_now
|
||||
mail.deliver_now
|
||||
expect(ActionMailer::Base.deliveries.first.body).to include "Gracias por unirte"
|
||||
end
|
||||
|
||||
it "sends email in default locale when user locale is not available" do
|
||||
user.locale = 'cn'
|
||||
Spree::UserMailer.signup_confirmation(user).deliver_now
|
||||
mail.deliver_now
|
||||
expect(ActionMailer::Base.deliveries.first.body).to include "Obrigada por juntar-se"
|
||||
end
|
||||
end
|
||||
|
||||
context "white labelling" do
|
||||
it_behaves_like 'email with inactive white labelling', :mail
|
||||
it_behaves_like 'non-customer facing email with active white labelling', :mail
|
||||
end
|
||||
end
|
||||
|
||||
describe "#confirmation_instructions" do
|
||||
@@ -42,7 +52,6 @@ RSpec.describe Spree::UserMailer do
|
||||
context 'when the language is English' do
|
||||
it 'sends an email with the translated subject' do
|
||||
mail.deliver_now
|
||||
|
||||
expect(ActionMailer::Base.deliveries.first.subject).to include(
|
||||
"Please confirm your OFN account"
|
||||
)
|
||||
@@ -54,19 +63,28 @@ RSpec.describe Spree::UserMailer do
|
||||
|
||||
it 'sends an email with the translated subject' do
|
||||
mail.deliver_now
|
||||
|
||||
expect(ActionMailer::Base.deliveries.first.subject).to include(
|
||||
"Por favor, confirma tu cuenta de OFN"
|
||||
)
|
||||
end
|
||||
end
|
||||
|
||||
context "white labelling" do
|
||||
it_behaves_like 'email with inactive white labelling', :mail
|
||||
it_behaves_like 'non-customer facing email with active white labelling', :mail
|
||||
end
|
||||
end
|
||||
|
||||
# adapted from https://github.com/spree/spree_auth_devise/blob/70737af/spec/mailers/user_mailer_spec.rb
|
||||
describe '#reset_password_instructions' do
|
||||
describe 'message contents' do
|
||||
subject(:mail) { described_class.reset_password_instructions(user, nil).deliver_now }
|
||||
subject(:mail) { described_class.reset_password_instructions(user, nil).deliver_now }
|
||||
|
||||
context "white labelling" do
|
||||
it_behaves_like 'email with inactive white labelling', :mail
|
||||
it_behaves_like 'non-customer facing email with active white labelling', :mail
|
||||
end
|
||||
|
||||
describe 'message contents' do
|
||||
context 'subject includes' do
|
||||
it 'translated devise instructions' do
|
||||
expect(mail.subject).to include "Reset password instructions"
|
||||
|
||||
31
spec/support/shared_examples/email_header_examples.rb
Normal file
31
spec/support/shared_examples/email_header_examples.rb
Normal file
@@ -0,0 +1,31 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.shared_examples 'email with inactive white labelling' do |mail|
|
||||
it 'always displays the OFN header with logo' do
|
||||
expect(public_send(mail).body).to include(ContentConfig.url_for(:logo))
|
||||
end
|
||||
end
|
||||
|
||||
RSpec.shared_examples 'non-customer facing email with active white labelling' do |mail|
|
||||
context 'when hide OFN navigation is enabled for the distributor of the order' do
|
||||
before do
|
||||
order.distributor.hide_ofn_navigation = true
|
||||
end
|
||||
|
||||
it 'still displays the OFN header with logo' do
|
||||
expect(public_send(mail).body).to include(ContentConfig.url_for(:logo))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
RSpec.shared_examples 'customer facing email with active white labelling' do |mail|
|
||||
context 'when hide OFN navigation is enabled for the distributor of the order' do
|
||||
before do
|
||||
order.distributor.hide_ofn_navigation = true
|
||||
end
|
||||
|
||||
it 'does not display the OFN header and logo' do
|
||||
expect(public_send(mail).body).not_to include(ContentConfig.url_for(:logo))
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user