-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#162477] Add "Order for" in purchase email (#4817)
* Add order for in order receipt and product order emails
- Loading branch information
Showing
7 changed files
with
98 additions
and
36 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
app/views/purchase_notifier/product_order_notification.text.haml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,46 +5,84 @@ | |
RSpec.describe PurchaseNotifier do | ||
let(:email) { ActionMailer::Base.deliveries.last } | ||
let(:facility) { create(:setup_facility) } | ||
let(:order) { create(:purchased_order, product: product) } | ||
let(:product) { create(:setup_instrument, facility: facility) } | ||
let(:order) { create(:purchased_order, product:) } | ||
let(:product) { create(:setup_instrument, facility:) } | ||
let(:user) { order.user } | ||
let(:other_user) { create(:user) } | ||
|
||
describe ".order_notification" do | ||
before { described_class.order_notification(order, recipient).deliver_now } | ||
|
||
let(:deliver_mail) { described_class.order_notification(order, recipient).deliver_now } | ||
let(:recipient) { "[email protected]" } | ||
|
||
it "generates an order notification", :aggregate_failures do | ||
expect(email.to).to eq [recipient] | ||
expect(email.subject).to include("Order Notification") | ||
expect(email.html_part.to_s).to match(/Ordered By.+#{user.full_name}/m) | ||
expect(email.reply_to).to eq [order.created_by_user.email] | ||
expect(email.text_part.to_s).to include("Ordered By: #{user.full_name}") | ||
expect(email.html_part.to_s).to match(/Payment Source.+#{order.account}/m) | ||
expect(email.text_part.to_s).to include("Payment Source: #{order.account}") | ||
expect(email.html_part.to_s).not_to include("Thank you for your order") | ||
expect(email.text_part.to_s).not_to include("Thank you for your order") | ||
context "when created by order user" do | ||
before { deliver_mail } | ||
|
||
it "generates an order notification", :aggregate_failures do | ||
expect(email.to).to eq [recipient] | ||
expect(email.subject).to include("Order Notification") | ||
expect(email.html_part.to_s).to match(/Ordered By.+#{user.full_name}/m) | ||
expect(email.reply_to).to eq [order.created_by_user.email] | ||
expect(email.text_part.to_s).to include("Ordered By: #{user.full_name}") | ||
expect(email.html_part.to_s).to match(/Payment Source.+#{order.account}/m) | ||
expect(email.text_part.to_s).to include("Payment Source: #{order.account}") | ||
expect(email.html_part.to_s).not_to include("Thank you for your order") | ||
expect(email.text_part.to_s).not_to include("Thank you for your order") | ||
expect(email.html_part.to_s).to_not include("Order For") | ||
expect(email.text_part.to_s).to_not include("Order For") | ||
end | ||
end | ||
|
||
context "when created on behalf of user" do | ||
before do | ||
order.update_attribute(:created_by_user, other_user) | ||
deliver_mail | ||
end | ||
|
||
it "does include order for" do | ||
expect(email.html_part.to_s).to include("Order For") | ||
expect(email.text_part.to_s).to include("Order For") | ||
end | ||
end | ||
end | ||
|
||
describe ".product_order_notification" do | ||
before { described_class.product_order_notification(order_detail, recipient).deliver_now } | ||
|
||
let(:order_detail) { order.order_details.first } | ||
let(:recipient) { "[email protected]" } | ||
|
||
it "generates a product order notification", :aggregate_failures do | ||
expect(email.to).to eq [recipient] | ||
expect(email.subject).to include("#{product} Order Notification") | ||
expect(email.html_part.to_s).to include(order_detail.to_s) | ||
expect(email.text_part.to_s).to include(order_detail.to_s) | ||
expect(email.html_part.to_s).to match(/Ordered By.+#{user.full_name}/m) | ||
expect(email.text_part.to_s).to include("Ordered By: #{user.full_name}") | ||
expect(email.reply_to).to eq [order.created_by_user.email] | ||
expect(email.html_part.to_s).to match(/Payment Source.+#{order.account}/m) | ||
expect(email.text_part.to_s).to include("Payment Source: #{order.account}") | ||
expect(email.html_part.to_s).not_to include("Thank you for your order") | ||
expect(email.text_part.to_s).not_to include("Thank you for your order") | ||
let(:deliver_mail) do | ||
described_class.product_order_notification(order_detail, recipient).deliver_now | ||
end | ||
|
||
context "when created by order user" do | ||
before { deliver_mail } | ||
|
||
it "generates a product order notification", :aggregate_failures do | ||
expect(email.to).to eq [recipient] | ||
expect(email.subject).to include("#{product} Order Notification") | ||
expect(email.html_part.to_s).to include(order_detail.to_s) | ||
expect(email.text_part.to_s).to include(order_detail.to_s) | ||
expect(email.html_part.to_s).to match(/Ordered By.+#{user.full_name}/m) | ||
expect(email.text_part.to_s).to include("Ordered By: #{user.full_name}") | ||
expect(email.reply_to).to eq [order.created_by_user.email] | ||
expect(email.html_part.to_s).to match(/Payment Source.+#{order.account}/m) | ||
expect(email.text_part.to_s).to include("Payment Source: #{order.account}") | ||
expect(email.html_part.to_s).not_to include("Thank you for your order") | ||
expect(email.text_part.to_s).not_to include("Thank you for your order") | ||
expect(email.html_part.to_s).to_not include("Order For") | ||
expect(email.text_part.to_s).to_not include("Order For") | ||
end | ||
end | ||
|
||
context "when created on behalf of user" do | ||
before do | ||
order.update_attribute(:created_by_user, other_user) | ||
deliver_mail | ||
end | ||
|
||
it "does include order for" do | ||
expect(email.html_part.to_s).to include("Order For") | ||
expect(email.text_part.to_s).to include("Order For") | ||
end | ||
end | ||
end | ||
|
||
|
@@ -53,7 +91,7 @@ | |
|
||
before(:each) do | ||
order.order_details.first.update_attribute(:note, note) if note.present? | ||
described_class.order_receipt(order: order, user: user).deliver_now | ||
described_class.order_receipt(order:, user:).deliver_now | ||
end | ||
|
||
it "generates a receipt", :aggregate_failures do | ||
|
@@ -65,11 +103,13 @@ | |
expect(email.text_part.to_s).to include("Payment Source: #{order.account}") | ||
expect(email.html_part.to_s).to include("Thank you for your order") | ||
expect(email.text_part.to_s).to include("Thank you for your order") | ||
expect(email.html_part.to_s).to_not include("Order For") | ||
expect(email.text_part.to_s).to_not include("Order For") | ||
end | ||
|
||
context "when ordered on behalf of another user" do | ||
let(:administrator) { create(:user, :administrator) } | ||
let(:order) { create(:purchased_order, product: product, created_by: administrator.id) } | ||
let(:order) { create(:purchased_order, product:, created_by: administrator.id) } | ||
|
||
it "mentions who placed the order in the receipt", :aggregate_failures do | ||
expect(email.html_part.to_s) | ||
|
@@ -78,6 +118,11 @@ | |
.to include("Ordered By: #{administrator.full_name}") | ||
end | ||
|
||
it "does include order for" do | ||
expect(email.html_part.to_s).to include("Order For") | ||
expect(email.text_part.to_s).to include("Order For") | ||
end | ||
|
||
context "with a note" do | ||
let(:note) { "*NOTE CONTENT*" } | ||
it { expect(email.text_part.to_s).to include("*NOTE CONTENT*") } | ||
|