-
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.
Add order for in product order notification
- Loading branch information
Showing
4 changed files
with
81 additions
and
71 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
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 |
---|---|---|
|
@@ -8,43 +8,81 @@ | |
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 | ||
|
||
|
@@ -65,6 +103,8 @@ | |
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 | ||
|
@@ -78,55 +118,16 @@ | |
.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*") } | ||
it { expect(email.html_part.to_s).to include("*NOTE CONTENT*") } | ||
end | ||
end | ||
end | ||
|
||
context "order for" do | ||
let(:order_for_field) { "Order For" } | ||
let(:recipient) { "[email protected]" } | ||
|
||
context "order created by admin" do | ||
let(:admin) { create(:user, :administrator) } | ||
|
||
before do | ||
order.update_attribute(:created_by_user, admin) | ||
described_class.order_notification(order, recipient).deliver_now | ||
end | ||
|
||
shared_examples "includes involved users info" do |part| | ||
let(:mail_content) { email.send(part).to_s } | ||
|
||
it "includes created by and order for in #{part}" do | ||
expect(mail_content).to include(order_for_field) | ||
expect(mail_content).to include(order.user.full_name) | ||
expect(mail_content).to include(order.user.email) | ||
expect(mail_content).to include(order.created_by_user.email) | ||
expect(mail_content).to include(order.created_by_user.full_name) | ||
end | ||
end | ||
|
||
include_examples "includes involved users info", :html_part | ||
include_examples "includes involved users info", :text_part | ||
end | ||
|
||
context "order created by user" do | ||
before do | ||
order.update_attribute(:user, order.created_by_user) | ||
described_class.order_notification(order, recipient).deliver_now | ||
end | ||
|
||
it "does not include order for" do | ||
expect(email.html_part.to_s).to_not include(order_for_field) | ||
end | ||
|
||
it "does not include order for" do | ||
expect(email.text_part.to_s).to_not include(order_for_field) | ||
end | ||
end | ||
end | ||
end |