Skip to content

Commit

Permalink
Merge pull request #962 from CommitChange/dedication-contact-on-recei…
Browse files Browse the repository at this point in the history
…pt-email

add dedication contact details to receipt emails
  • Loading branch information
wwahammy authored Dec 13, 2024
2 parents 37000e0 + a7239ff commit 793efdd
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 7 deletions.
22 changes: 21 additions & 1 deletion app/views/donation_mailer/_donation_payment_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,27 @@
<tr>
<td><strong>Dedication</strong></td>
<td> <%= donation.dedication ? Format::Dedication.from_json(donation.dedication) : 'None' %></td>
</tr>
<% @contact = JSON.parse(donation.dedication).dig('contact') %>
<tr>
<td><strong>Acknowledgement Email</strong></td>
<% if @contact&.dig('email') %>
<td><a href="mailto:<%= @contact['email'] %>"><%= @contact['email'] %></a></td>
<% else %>
<td> None </td>
<% end %>
</tr>
<tr>
<td><strong>Acknowledgement Phone</strong></td>
<% if @contact&.dig('phone') %>
<td><a href="tel:<%= @contact['phone'] %>"><%= @contact['phone'] %></a></td>
<% else %>
<td> None </td>
<% end %>
</tr>
<tr>
<td><strong>Acknowledgement Address</strong></td>
<td> <%= @contact&.dig('address') ? @contact['address'] : 'None' %> </td>
</tr>
<% end %>
Expand Down
17 changes: 13 additions & 4 deletions spec/factories/donations.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,20 @@
)]
}
end
end




factory :donation_with_dedication do
dedication { {
contact: {
email: '[email protected]',
phone: '234-343-3234',
address: '123 Four'
},
name: 'our loved one',
note: 'we miss them dearly',
type: 'memory'
}.to_json }
end
end

factory :fv_poverty_donation, class: 'Donation' do
nonprofit {association :fv_poverty}
Expand Down
42 changes: 40 additions & 2 deletions spec/mailers/donation_mailer_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,44 @@
expect(mail.subject).to include supporter.email
end
end


context 'when dedication is not set' do
before(:each) {
expect(QueryUsers).to receive(:nonprofit_user_emails).and_return(['[email protected]'])
}

let(:supporter) { create(:supporter_base)}
let(:donation) { create(:donation_base, supporter: supporter, nonprofit: supporter.nonprofit)}
let(:payment) { create(:payment_base, donation: donation)}

let!(:mail) { DonationMailer.nonprofit_payment_notification(
donation.id,
payment.id
) }

it 'does not include the dedication section' do
expect(mail.body.encoded).to_not include "Acknowledgement Phone"
end
end

context 'when dedication is set' do
before(:each) {
expect(QueryUsers).to receive(:nonprofit_user_emails).and_return(['[email protected]'])
}

let(:supporter) { create(:supporter_base)}
let(:donation) { create(:donation_with_dedication, supporter: supporter, nonprofit: supporter.nonprofit)}
let(:payment) { create(:payment_base, donation: donation)}

let!(:mail) { DonationMailer.nonprofit_payment_notification(
donation.id,
payment.id
) }

it 'does not include the dedication section' do
expect(mail.body.encoded).to include "Acknowledgement Phone"
expect(mail.body.encoded).to include "234-343-3234"
end
end
end
end
end

0 comments on commit 793efdd

Please sign in to comment.