2019-07-30 21:29:24 +00:00
# frozen_string_literal: true
2020-06-12 20:03:43 +00:00
# License: AGPL-3.0-or-later WITH WTO-AP-3.0-or-later
# Full license explanation at https://github.com/houdiniproject/houdini/blob/master/LICENSE
2019-07-30 21:29:24 +00:00
require 'rails_helper'
2018-03-25 17:30:42 +00:00
2019-07-30 21:29:24 +00:00
RSpec . describe AdminMailer , type : :mailer do
describe 'notify_failed_gift' do
2020-04-16 20:50:03 +00:00
let! ( :np ) { force_create ( :nm_justice , name : 'nonprofit' , email : 'blah' , timezone : 'UTC' ) }
2019-07-30 21:29:24 +00:00
let! ( :s ) { force_create ( :supporter , email : 'supporter.email@mail.teha' ) }
let! ( :oldcard ) { force_create ( :card ) }
let! ( :donation ) { force_create ( :donation , nonprofit_id : np . id , supporter_id : s . id , card_id : oldcard . id , amount : 999 ) }
let! ( :charge ) { create ( :charge , donation : donation , nonprofit : np , amount : 100 , created_at : Time . now ) }
let ( :campaign ) { force_create ( :campaign , nonprofit : np ) }
2020-05-20 22:05:06 +00:00
let! ( :campaign_gift_option_with_desc ) { force_create ( :campaign_gift_option , description : 'desc' , amount_one_time : 999 , campaign : campaign ) }
2019-07-30 21:29:24 +00:00
let! ( :campaign_gift_option ) { force_create ( :campaign_gift_option , campaign : campaign ) }
2018-03-25 17:30:42 +00:00
let ( :mail ) { AdminMailer . notify_failed_gift ( donation , campaign_gift_option ) }
2019-07-30 21:29:24 +00:00
let ( :mail_with_desc ) { AdminMailer . notify_failed_gift ( donation , campaign_gift_option_with_desc ) }
2018-03-25 17:30:42 +00:00
2019-07-30 21:29:24 +00:00
it 'renders the headers for mail without desc' do
2018-03-25 17:30:42 +00:00
expect ( mail . subject ) . to eq ( " Tried to associate donation #{ donation . id } with campaign gift option #{ campaign_gift_option . id } which is out of stock " )
2021-04-19 23:25:46 +00:00
expect ( mail . to ) . to eq ( [ Houdini . hoster . support_email ] )
expect ( mail . from ) . to eq ( [ Houdini . hoster . support_email ] )
2018-03-25 17:30:42 +00:00
end
2019-07-30 21:29:24 +00:00
it 'renders the body without desc' do
expect ( mail . body . encoded ) . to_not include ( '<td>desc</td>' )
2018-03-25 17:30:42 +00:00
end
2019-07-30 21:29:24 +00:00
it 'renders the headers on mail with desc' do
2018-03-25 17:30:42 +00:00
expect ( mail_with_desc . subject ) . to eq ( " Tried to associate donation #{ donation . id } with campaign gift option #{ campaign_gift_option_with_desc . id } which is out of stock " )
2021-04-19 23:25:46 +00:00
expect ( mail_with_desc . to ) . to eq ( [ Houdini . hoster . support_email ] )
expect ( mail_with_desc . from ) . to eq ( [ Houdini . hoster . support_email ] )
2018-03-25 17:30:42 +00:00
end
2019-07-30 21:29:24 +00:00
it 'renders the body with desc' do
expect ( mail . body . encoded ) . to include ( '<td>Description:</td>' )
2018-03-25 17:30:42 +00:00
end
end
end