Use AdminFailedGiftJob

This commit is contained in:
Eric Schultz 2019-11-07 15:35:22 -06:00
parent ef9c4776fa
commit 34e67f5577
3 changed files with 22 additions and 27 deletions

View file

@ -86,7 +86,7 @@ class Event < ApplicationRecord
after_create do
user = profile.user
Role.create(name: :event_editor, user_id: user.id, host: self)
EventMailer.delay.creation_followup(self)
EventCreateJob.perform_later self
self
end

View file

@ -38,12 +38,12 @@ module CreateCampaignGift
if !donation.recurring_donation.nil? && (!campaign_gift_option.amount_recurring.nil? && campaign_gift_option.amount_recurring > 0)
# it's a recurring_donation. Is it enough? for the gift level?
unless donation.recurring_donation.amount == campaign_gift_option.amount_recurring
AdminMailer.delay.notify_failed_gift(donation, campaign_gift_option)
AdminFailedGiftJob.perform_later(donation, campaign_gift_option)
raise ParamValidation::ValidationError.new("#{params[:campaign_gift_option_id]} gift options requires a recurring donation of #{campaign_gift_option.amount_recurring} for donation #{donation.id}", key: :campaign_gift_option_id)
end
else
unless donation.amount == campaign_gift_option.amount_one_time
AdminMailer.delay.notify_failed_gift(donation, campaign_gift_option)
AdminFailedGiftJob.perform_later(donation, campaign_gift_option)
raise ParamValidation::ValidationError.new("#{params[:campaign_gift_option_id]} gift options requires a donation of #{campaign_gift_option.amount_one_time} for donation #{donation.id}", key: :campaign_gift_option_id)
end
end
@ -56,7 +56,7 @@ module CreateCampaignGift
return gift
end
end
AdminMailer.delay.notify_failed_gift(donation, campaign_gift_option)
AdminFailedGiftJob.perform_later(donation, campaign_gift_option)
raise ParamValidation::ValidationError.new("#{params[:campaign_gift_option_id]} has no more inventory", key: :campaign_gift_option_id)
end

View file

@ -78,53 +78,48 @@ describe CreateCampaignGift do
end
it 'rejects associations when the donation amount is too low' do
adm = double(AdminMailer)
donation = force_create(:donation, campaign: campaign, amount: 299)
campaign_gift_option = force_create(:campaign_gift_option, campaign: campaign, amount_one_time: 300, name: 'name')
expect(adm).to receive(:notify_failed_gift).with(donation, campaign_gift_option)
expect(AdminMailer).to receive(:delay).and_return(adm)
expect { CreateCampaignGift.create(donation_id: donation.id, campaign_gift_option_id: campaign_gift_option.id) }.to raise_error { |error|
expect(error).to be_a(ParamValidation::ValidationError)
expect_validation_errors(error.data, key: :campaign_gift_option_id)
expect(error.message).to eq "#{campaign_gift_option.id} gift options requires a donation of 300 for donation #{donation.id}"
}
expect {
expect { CreateCampaignGift.create(donation_id: donation.id, campaign_gift_option_id: campaign_gift_option.id) }.to raise_error { |error|
expect(error).to be_a(ParamValidation::ValidationError)
expect_validation_errors(error.data, key: :campaign_gift_option_id)
expect(error.message).to eq "#{campaign_gift_option.id} gift options requires a donation of 300 for donation #{donation.id}"
}
}.to have_enqueued_job(AdminFailedGiftJob).with(donation,campaign_gift_option)
end
it 'rejects associations when the recurring donation amount is too low' do
adm = double(AdminMailer)
donation = force_create(:donation, campaign: campaign, amount: 299, recurring: true)
rd = force_create(:recurring_donation, amount: 299, donation: donation)
campaign_gift_option = force_create(:campaign_gift_option, campaign: campaign, amount_recurring: 300, name: 'name')
expect(adm).to receive(:notify_failed_gift).with(donation, campaign_gift_option)
expect(AdminMailer).to receive(:delay).and_return(adm)
expect { CreateCampaignGift.create(donation_id: donation.id, campaign_gift_option_id: campaign_gift_option.id) }.to raise_error { |error|
expect {
expect { CreateCampaignGift.create(donation_id: donation.id, campaign_gift_option_id: campaign_gift_option.id) }.to raise_error { |error|
expect(error).to be_a(ParamValidation::ValidationError)
expect_validation_errors(error.data, key: :campaign_gift_option_id)
expect(error.message).to eq "#{campaign_gift_option.id} gift options requires a recurring donation of 300 for donation #{donation.id}"
}
}.to have_enqueued_job(AdminFailedGiftJob).with(donation,campaign_gift_option)
end
it 'rejects association when the there are no gifts available' do
adm = double(AdminMailer)
donation = force_create(:donation, campaign: campaign, amount: 300, recurring: true)
rd = force_create(:recurring_donation, amount: 300, donation: donation)
campaign_gift_option = force_create(:campaign_gift_option, campaign: campaign, amount_recurring: 300, quantity: 1)
expect(adm).to receive(:notify_failed_gift).with(donation, campaign_gift_option)
expect(AdminMailer).to receive(:delay).and_return(adm)
campaign_gift = force_create(:campaign_gift, campaign_gift_option: campaign_gift_option)
expect { CreateCampaignGift.create(donation_id: donation.id, campaign_gift_option_id: campaign_gift_option.id) }.to raise_error { |error|
expect(error).to be_a(ParamValidation::ValidationError)
expect_validation_errors(error.data, [{ key: :campaign_gift_option_id }])
expect(error.message).to eq "#{campaign_gift_option.id} has no more inventory"
expect(CampaignGift.count).to eq 1
}
expect {
expect { CreateCampaignGift.create(donation_id: donation.id, campaign_gift_option_id: campaign_gift_option.id) }.to raise_error { |error|
expect(error).to be_a(ParamValidation::ValidationError)
expect_validation_errors(error.data, [{ key: :campaign_gift_option_id }])
expect(error.message).to eq "#{campaign_gift_option.id} has no more inventory"
expect(CampaignGift.count).to eq 1
}
}.to have_enqueued_job(AdminFailedGiftJob).with(donation,campaign_gift_option)
end
end
end