2019-07-30 21:29:24 +00:00
# frozen_string_literal: true
2018-03-25 16:15:39 +00:00
# License: AGPL-3.0-or-later WITH Web-Template-Output-Additional-Permission-3.0-or-later
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
let! ( :np ) { force_create ( :nonprofit , name : 'nonprofit' , email : 'blah' , timezone : 'UTC' ) }
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 ) }
let! ( :campaign_gift_option_with_desc ) { force_create ( :campaign_gift_option , description : 'desc' , amount_one_time : ` ` , campaign : campaign ) }
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 " )
2019-07-30 21:29:24 +00:00
expect ( mail . to ) . to eq ( [ 'support@commitchange.com' ] )
expect ( mail . from ) . to eq ( [ 'support@commitchange.com' ] )
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 " )
2019-07-30 21:29:24 +00:00
expect ( mail_with_desc . to ) . to eq ( [ 'support@commitchange.com' ] )
expect ( mail_with_desc . from ) . to eq ( [ 'support@commitchange.com' ] )
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