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
|
2018-03-25 17:30:42 +00:00
|
|
|
require 'stripe_mock'
|
|
|
|
|
|
|
|
RSpec.shared_context :shared_donation_charge_context do
|
2020-04-16 20:50:03 +00:00
|
|
|
let(:nonprofit) { force_create(:nm_justice, name: 'nonprofit name', slug: 'nonprofit_nameo') }
|
|
|
|
let(:other_nonprofit) { force_create(:fv_poverty) }
|
2019-07-30 21:29:24 +00:00
|
|
|
let(:supporter) { force_create(:supporter, nonprofit: nonprofit, locale: 'locale_one') }
|
|
|
|
let(:other_nonprofit_supporter) { force_create(:supporter, nonprofit: other_nonprofit, locale: 'locale_two') }
|
|
|
|
let(:card) { force_create(:card, holder: supporter) }
|
|
|
|
let(:card_for_other_supporter) { force_create(:card, holder: other_nonprofit_supporter) }
|
|
|
|
let(:card_with_valid_stripe_id) { force_create(:card, holder: supporter) }
|
|
|
|
let(:direct_debit_detail) { force_create(:direct_debit_detail, holder: supporter) }
|
|
|
|
let(:direct_debit_detail_for_other_supporter) { force_create(:direct_debit_detail, holder: other_nonprofit_supporter) }
|
2018-03-25 17:30:42 +00:00
|
|
|
let(:bp_percentage) { 0.039 }
|
2019-07-30 21:29:24 +00:00
|
|
|
let(:billing_plan) { force_create(:billing_plan, percentage_fee: bp_percentage) }
|
|
|
|
let(:billing_subscription) { force_create(:billing_subscription, billing_plan: billing_plan, nonprofit: nonprofit) }
|
|
|
|
let(:campaign) { force_create(:campaign, nonprofit: nonprofit, goal_amount: 500) }
|
|
|
|
let(:other_campaign) { force_create(:campaign, nonprofit: other_nonprofit) }
|
|
|
|
let(:event) do
|
2018-03-25 17:30:42 +00:00
|
|
|
force_create(:event, nonprofit: nonprofit)
|
2019-07-30 21:29:24 +00:00
|
|
|
end
|
|
|
|
let(:other_event) do
|
2018-03-25 17:30:42 +00:00
|
|
|
force_create(:event, nonprofit: other_nonprofit)
|
2019-07-30 21:29:24 +00:00
|
|
|
end
|
|
|
|
let(:event_discount) { force_create(:event_discount, event: event, percent: 20) }
|
|
|
|
let(:other_event_discount) { force_create(:event_discount, event: other_event) }
|
|
|
|
let(:profile) { force_create(:profile) }
|
|
|
|
let(:user) { force_create(:user) }
|
|
|
|
let(:ticket_level) { force_create(:ticket_level, event: event, amount: 400, name: '1') }
|
|
|
|
let(:ticket_level2) { force_create(:ticket_level, event: event, amount: 500, name: '2') }
|
|
|
|
let(:free_ticket_level) { force_create(:ticket_level, event: event, amount: 0, name: 'free ticket level') }
|
|
|
|
let(:other_ticket_level) { force_create(:ticket_level, event: other_event, name: '3') }
|
2018-03-25 17:30:42 +00:00
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
let(:donation_for_rd) { force_create(:donation, recurring: true, nonprofit: nonprofit, supporter: supporter, card: card_with_valid_stripe_id, amount: 500) }
|
|
|
|
let(:recurring_donation) { force_create(:recurring_donation, donation: donation_for_rd, nonprofit: nonprofit, supporter: supporter, start_date: Time.now, interval: 1, time_unit: 'month') }
|
2018-03-25 17:30:42 +00:00
|
|
|
|
|
|
|
let(:stripe_helper) { StripeMock.create_test_helper }
|
|
|
|
|
2021-02-02 21:04:53 +00:00
|
|
|
|
|
|
|
let(:nonprofit_to_builder_base) do
|
|
|
|
{
|
|
|
|
'id' => nonprofit.id,
|
|
|
|
'name' => nonprofit.name,
|
|
|
|
'object' => 'nonprofit'
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
let(:supporter_to_builder_base) do
|
|
|
|
{
|
|
|
|
'anonymous' => false,
|
|
|
|
'deleted' => false,
|
|
|
|
'name' => name,
|
|
|
|
'organization' => nil,
|
|
|
|
'phone' => nil,
|
|
|
|
'supporter_addresses' => [kind_of(Numeric)],
|
|
|
|
'id'=> kind_of(Numeric),
|
|
|
|
'merged_into' => nil,
|
|
|
|
'nonprofit'=> nonprofit.id,
|
|
|
|
'object' => 'supporter'
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:supporter_address_to_builder_base) do
|
|
|
|
{
|
|
|
|
'id' => kind_of(Numeric),
|
|
|
|
'deleted' => false,
|
|
|
|
'address' => address,
|
|
|
|
'city' => nil,
|
|
|
|
'state_code' => nil,
|
|
|
|
'zip_code' => nil,
|
|
|
|
'country' => 'United States',
|
|
|
|
'object' => 'supporter_address',
|
2021-02-12 21:29:55 +00:00
|
|
|
'supporter' => kind_of(Numeric),
|
|
|
|
'nonprofit'=> nonprofit.id
|
2021-02-02 21:04:53 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
around(:each) do |example|
|
2018-03-25 17:30:42 +00:00
|
|
|
Timecop.freeze(2020, 5, 4) do
|
|
|
|
StripeMock.start
|
|
|
|
example.run
|
|
|
|
StripeMock.stop
|
|
|
|
end
|
2019-07-30 21:29:24 +00:00
|
|
|
end
|
2019-07-14 09:25:00 +00:00
|
|
|
end
|