Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion app/mailers/request_mailer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,10 @@ def request_cancel_partner_notification(request_id:)
end
@formatted_requested_items.sort_by! { |rt| rt[:name] }

recipients = [@partner.email, @request.requester.email].uniq

mail(
to: @partner.email,
to: recipients,
subject: "Your essentials request (##{@request.id}) has been canceled."
)
end
Expand Down
39 changes: 26 additions & 13 deletions spec/mailers/request_mailer_spec.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,35 @@
RSpec.describe RequestMailer, type: :mailer do
describe "#request_cancel_partner_notification" do
subject { described_class.request_cancel_partner_notification(request_id: request.id) }
let(:request) { create(:request) }

it "renders the body with correct text with partner information" do
html = html_body(subject)
expect(html).to include("Hello there, <strong>#{request.partner.name}</strong>")
expect(html).to include("One of your essentials requests (##{request.id}) have been canceled.")
text = text_body(subject)
expect(text).to include("Hello there, #{request.partner.name}")
expect(text).to include("One of your essentials requests (##{request.id}) have been canceled.")
let(:partner) { create(:partner, email: "partner@example.com") }

context "when the request was sent by a partner user" do
let(:partner_user) { create(:partner_user, email: "requester@example.com", partner: partner) }
let(:request) { create(:request, partner: partner, partner_user: partner_user) }

it "renders the body with correct text with partner information" do
html = html_body(subject)
expect(html).to include("Hello there, <strong>#{request.partner.name}</strong>")
expect(html).to include("One of your essentials requests (##{request.id}) have been canceled.")
text = text_body(subject)
expect(text).to include("Hello there, #{request.partner.name}")
expect(text).to include("One of your essentials requests (##{request.id}) have been canceled.")
end

it "is sent to both the partner and the request sender with the correct subject line" do
expect(subject.to).to match_array(["partner@example.com", "requester@example.com"])
expect(subject.from).to eq(['no-reply@humanessentials.app'])
expect(subject.subject).to eq("Your essentials request (##{request.id}) has been canceled.")
end
end

it "should be sent to the partner main email with the correct subject line" do
expect(subject.to).to eq([request.partner.email])
expect(subject.from).to eq(['no-reply@humanessentials.app'])
expect(subject.subject).to eq("Your essentials request (##{request.id}) has been canceled.")
context "when the request has no partner user" do
let(:request) { create(:request, partner: partner, partner_user: nil) }

it "is sent only to the partner main email" do
expect(subject.to).to eq(["partner@example.com"])
end
end
end
end

Loading