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
|
2018-03-25 17:30:42 +00:00
|
|
|
require 'rails_helper'
|
|
|
|
|
|
|
|
describe InsertDonation do
|
|
|
|
describe '.with_stripe' do
|
2019-07-30 21:29:24 +00:00
|
|
|
before(:each) do
|
2020-06-10 22:31:47 +00:00
|
|
|
Houdini.payment_providers.stripe.connect = true
|
2019-07-30 21:29:24 +00:00
|
|
|
end
|
2020-06-10 22:31:47 +00:00
|
|
|
|
2018-03-25 17:30:42 +00:00
|
|
|
include_context :shared_rd_donation_value_context
|
|
|
|
|
|
|
|
describe 'param validation' do
|
|
|
|
it 'does basic validation' do
|
2019-07-30 21:29:24 +00:00
|
|
|
validation_basic_validation { InsertDonation.with_stripe(designation: 34_124, dedication: 35_141, event_id: 'bad', campaign_id: 'bad') }
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'errors out if token is invalid' do
|
|
|
|
validation_invalid_token { InsertDonation.with_stripe(amount: 1, nonprofit_id: 1, supporter_id: 1, token: fake_uuid) }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'errors out if token is unauthorized' do
|
|
|
|
validation_unauthorized { InsertDonation.with_stripe(amount: charge_amount, nonprofit_id: 1, supporter_id: 1, token: fake_uuid) }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'errors out if token is expired' do
|
|
|
|
validation_expired { InsertDonation.with_stripe(amount: charge_amount, nonprofit_id: 1, supporter_id: 1, token: fake_uuid) }
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'errors during find if' do
|
|
|
|
it 'supporter is invalid' do
|
2019-07-30 21:29:24 +00:00
|
|
|
find_error_supporter { InsertDonation.with_stripe(amount: charge_amount, nonprofit_id: nonprofit.id, supporter_id: 55_555, token: source_token.token) }
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'nonprofit is invalid' do
|
2019-07-30 21:29:24 +00:00
|
|
|
find_error_nonprofit { InsertDonation.with_stripe(amount: charge_amount, nonprofit_id: 55_555, supporter_id: supporter.id, token: source_token.token) }
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'campaign is invalid' do
|
2019-07-30 21:29:24 +00:00
|
|
|
find_error_campaign { InsertDonation.with_stripe(amount: charge_amount, nonprofit_id: nonprofit.id, supporter_id: supporter.id, token: source_token.token, campaign_id: 5555) }
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'event is invalid' do
|
2019-07-30 21:29:24 +00:00
|
|
|
find_error_event { InsertDonation.with_stripe(amount: charge_amount, nonprofit_id: nonprofit.id, supporter_id: supporter.id, token: source_token.token, event_id: 5555) }
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'profile is invalid' do
|
2019-07-30 21:29:24 +00:00
|
|
|
find_error_profile { InsertDonation.with_stripe(amount: charge_amount, nonprofit_id: nonprofit.id, supporter_id: supporter.id, token: source_token.token, profile_id: 5555) }
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'errors during relationship comparison if' do
|
|
|
|
it 'supporter is deleted' do
|
2019-07-30 21:29:24 +00:00
|
|
|
validation_supporter_deleted { InsertDonation.with_stripe(amount: charge_amount, nonprofit_id: nonprofit.id, supporter_id: supporter.id, token: source_token.token) }
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'event is deleted' do
|
|
|
|
validation_event_deleted { InsertDonation.with_stripe(amount: charge_amount, nonprofit_id: nonprofit.id, supporter_id: supporter.id, token: source_token.token, event_id: event.id) }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'campaign is deleted' do
|
|
|
|
validation_campaign_deleted { InsertDonation.with_stripe(amount: charge_amount, nonprofit_id: nonprofit.id, supporter_id: supporter.id, token: source_token.token, campaign_id: campaign.id) }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'supporter doesnt belong to nonprofit' do
|
2019-07-30 21:29:24 +00:00
|
|
|
validation_supporter_not_with_nonprofit { InsertDonation.with_stripe(amount: charge_amount, nonprofit_id: nonprofit.id, supporter_id: other_nonprofit_supporter.id, token: source_token.token) }
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'campaign doesnt belong to nonprofit' do
|
2019-07-30 21:29:24 +00:00
|
|
|
validation_campaign_not_with_nonprofit { InsertDonation.with_stripe(amount: charge_amount, nonprofit_id: nonprofit.id, supporter_id: supporter.id, token: source_token.token, campaign_id: other_campaign.id) }
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'event doesnt belong to nonprofit' do
|
2019-07-30 21:29:24 +00:00
|
|
|
validation_event_not_with_nonprofit { InsertDonation.with_stripe(amount: charge_amount, nonprofit_id: nonprofit.id, supporter_id: supporter.id, token: source_token.token, event_id: other_event.id) }
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'card doesnt belong to supporter' do
|
2019-07-30 21:29:24 +00:00
|
|
|
validation_card_not_with_supporter { InsertDonation.with_stripe(amount: charge_amount, nonprofit_id: nonprofit.id, supporter_id: supporter.id, token: other_source_token.token) }
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'charge returns failed' do
|
2019-07-30 21:29:24 +00:00
|
|
|
handle_charge_failed { InsertDonation.with_stripe(amount: charge_amount, nonprofit_id: nonprofit.id, supporter_id: supporter.id, token: source_token.token) }
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
describe 'success' do
|
2019-07-30 21:29:24 +00:00
|
|
|
before(:each) do
|
2018-03-25 17:30:42 +00:00
|
|
|
before_each_success
|
2019-07-30 21:29:24 +00:00
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
it 'process event donation' do
|
2019-07-30 21:29:24 +00:00
|
|
|
process_event_donation { InsertDonation.with_stripe(amount: charge_amount, nonprofit_id: nonprofit.id, supporter_id: supporter.id, token: source_token.token, event_id: event.id, date: (Time.now + 1.day).to_s, dedication: 'dedication', designation: 'designation') }
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'process campaign donation' do
|
2020-02-10 20:01:49 +00:00
|
|
|
expect(HoudiniEventPublisher).to receive(:announce).with(:campaign_create, any_args)
|
2019-07-30 21:29:24 +00:00
|
|
|
process_campaign_donation { InsertDonation.with_stripe(amount: charge_amount, nonprofit_id: nonprofit.id, supporter_id: supporter.id, token: source_token.token, campaign_id: campaign.id, date: (Time.now + 1.day).to_s, dedication: 'dedication', designation: 'designation') }
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'processes general donation' do
|
2019-07-30 21:29:24 +00:00
|
|
|
process_general_donation { InsertDonation.with_stripe(amount: charge_amount, nonprofit_id: nonprofit.id, supporter_id: supporter.id, token: source_token.token, profile_id: profile.id, date: (Time.now + 1.day).to_s, dedication: 'dedication', designation: 'designation') }
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
describe '#with_sepa' do
|
|
|
|
include_context :shared_rd_donation_value_context
|
|
|
|
|
|
|
|
describe 'saves donation' do
|
|
|
|
before(:each) do
|
|
|
|
before_each_sepa_success
|
|
|
|
end
|
|
|
|
it 'process event donation' do
|
|
|
|
process_event_donation(sepa: true) { InsertDonation.with_sepa(amount: charge_amount, nonprofit_id: nonprofit.id, supporter_id: supporter.id, direct_debit_detail_id: direct_debit_detail.id, event_id: event.id, date: (Time.now + 1.day).to_s, dedication: 'dedication', designation: 'designation') }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'process campaign donation' do
|
2020-02-10 20:01:49 +00:00
|
|
|
expect(HoudiniEventPublisher).to receive(:announce).with(:campaign_create, any_args)
|
2019-07-30 21:29:24 +00:00
|
|
|
process_campaign_donation(sepa: true) { InsertDonation.with_sepa(amount: charge_amount, nonprofit_id: nonprofit.id, supporter_id: supporter.id, direct_debit_detail_id: direct_debit_detail.id, campaign_id: campaign.id, date: (Time.now + 1.day).to_s, dedication: 'dedication', designation: 'designation') }
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'processes general donation' do
|
|
|
|
process_general_donation(sepa: true) { InsertDonation.with_sepa(amount: charge_amount, nonprofit_id: nonprofit.id, supporter_id: supporter.id, direct_debit_detail_id: direct_debit_detail.id, profile_id: profile.id, date: (Time.now + 1.day).to_s, dedication: 'dedication', designation: 'designation') }
|
|
|
|
end
|
|
|
|
end
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
# it 'saves donation' do
|
|
|
|
# expect { InsertDonation.with_sepa(data) }.to change(Donation, :count).by(1)
|
|
|
|
# end
|
|
|
|
#
|
|
|
|
# it 'returns a json hash' do
|
|
|
|
# result = InsertDonation.with_sepa(data)
|
|
|
|
#
|
|
|
|
# expect(result).to be_a(Hash)
|
|
|
|
# expect(result[:json]['donation']).to include data
|
|
|
|
# end
|
|
|
|
# end
|
|
|
|
|
|
|
|
it '.offsite', pending: true do
|
2019-07-30 21:29:24 +00:00
|
|
|
raise
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
2019-07-30 21:29:24 +00:00
|
|
|
end
|