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'
require 'stripe_mock'
describe InsertCharge do
include_context :shared_donation_charge_context
2019-07-30 21:29:24 +00:00
let! ( :donation ) { force_create ( :donation , id : 555 ) }
2018-03-25 17:30:42 +00:00
describe '.with_stripe' do
2019-07-30 21:29:24 +00:00
before ( :each ) do
2018-03-25 17:30:42 +00:00
Settings . payment_provider . stripe_connect = true
2019-07-30 21:29:24 +00:00
end
2018-03-25 17:30:42 +00:00
describe 'param validation' do
it 'does basic validation' do
2019-07-30 21:29:24 +00:00
expect { InsertCharge . with_stripe ( nil ) } . to ( raise_error do | error |
2018-03-25 17:30:42 +00:00
expect ( error ) . to be_a ParamValidation :: ValidationError
expect_validation_errors ( error . data ,
[
2019-07-30 21:29:24 +00:00
{ key : :amount , name : :required } ,
{ key : :amount , name : :is_integer } ,
{ key : :amount , name : :min } ,
{ key : :nonprofit_id , name : :required } ,
{ key : :nonprofit_id , name : :is_integer } ,
{ key : :supporter_id , name : :required } ,
{ key : :supporter_id , name : :is_integer } ,
{ key : :card_id , name : :required } ,
{ key : :card_id , name : :is_integer } ,
{ key : :statement , name : :required } ,
{ key : :statement , name : :not_blank }
] )
end )
2018-03-25 17:30:42 +00:00
end
it 'verify the amount minimum works' do
2019-07-30 21:29:24 +00:00
expect { InsertCharge . with_stripe ( amount : - 1 ) } . to ( raise_error do | error |
2018-03-25 17:30:42 +00:00
expect ( error ) . to be_a ParamValidation :: ValidationError
expect_validation_errors ( error . data ,
[
2019-07-30 21:29:24 +00:00
{ key : :amount , name : :min } ,
{ key : :nonprofit_id , name : :required } ,
{ key : :nonprofit_id , name : :is_integer } ,
{ key : :supporter_id , name : :required } ,
{ key : :supporter_id , name : :is_integer } ,
{ key : :card_id , name : :required } ,
{ key : :card_id , name : :is_integer } ,
{ key : :statement , name : :required } ,
{ key : :statement , name : :not_blank }
2018-03-25 17:30:42 +00:00
] )
2019-07-30 21:29:24 +00:00
end )
2018-03-25 17:30:42 +00:00
end
it 'verify that we check for valid nonprofit' do
2019-07-30 21:29:24 +00:00
expect do
InsertCharge . with_stripe ( amount : 100 ,
nonprofit_id : 5555 ,
supporter_id : 5555 ,
card_id : 5555 ,
statement : 'our statement' )
end . to ( raise_error do | error |
expect ( error ) . to be_a ParamValidation :: ValidationError
expect_validation_errors ( error . data ,
[
{ key : :nonprofit_id }
] )
end )
2018-03-25 17:30:42 +00:00
end
it 'verify that we check for valid supporter' do
2019-07-30 21:29:24 +00:00
expect do
InsertCharge . with_stripe ( amount : 100 ,
nonprofit_id : nonprofit . id ,
supporter_id : 5555 ,
card_id : 5555 ,
statement : 'our statement' )
end . to ( raise_error do | error |
expect ( error ) . to be_a ParamValidation :: ValidationError
expect_validation_errors ( error . data ,
[
{ key : :supporter_id }
] )
end )
2018-03-25 17:30:42 +00:00
end
it 'verify that we check for valid card' do
2019-07-30 21:29:24 +00:00
expect do
InsertCharge . with_stripe ( amount : 100 ,
nonprofit_id : nonprofit . id ,
supporter_id : supporter . id ,
card_id : 5555 ,
statement : 'our statement' )
end . to ( raise_error do | error |
expect ( error ) . to be_a ParamValidation :: ValidationError
expect_validation_errors ( error . data ,
[
{ key : :card_id }
] )
end )
2018-03-25 17:30:42 +00:00
end
it 'verify that we check that the supporter belongs to the correct nonprofit' do
2019-07-30 21:29:24 +00:00
expect do
InsertCharge . with_stripe ( amount : 100 ,
nonprofit_id : other_nonprofit . id ,
supporter_id : supporter . id ,
card_id : card . id ,
statement : 'our statement' )
end . to ( raise_error do | error |
expect ( error ) . to be_a ParamValidation :: ValidationError
expect ( error . message ) . to eq " #{ supporter . id } does not belong to this nonprofit #{ other_nonprofit . id } "
expect_validation_errors ( error . data ,
[
{ key : :supporter_id }
] )
end )
2018-03-25 17:30:42 +00:00
end
it 'verify that we check that the card belongs to the correct supporter' do
2019-07-30 21:29:24 +00:00
expect do
InsertCharge . with_stripe ( amount : 100 ,
nonprofit_id : nonprofit . id ,
supporter_id : supporter . id ,
card_id : card_for_other_supporter . id ,
statement : 'our statement' )
end . to ( raise_error do | error |
expect ( error ) . to be_a ParamValidation :: ValidationError
expect ( error . message ) . to eq " #{ card_for_other_supporter . id } does not belong to this supporter #{ supporter . id } "
expect_validation_errors ( error . data ,
[
{ key : :card_id }
] )
end )
2018-03-25 17:30:42 +00:00
end
end
describe 'handle StripeAccount Find and Create failure' do
2019-07-30 21:29:24 +00:00
before ( :each ) do
StripeMock . prepare_error ( Stripe :: StripeError . new ( 'chaos' ) , :new_account )
end
2018-03-25 17:30:42 +00:00
it 'does it fail properly' do
2019-07-30 21:29:24 +00:00
expect do
InsertCharge . with_stripe ( amount : 100 ,
nonprofit_id : nonprofit . id ,
supporter_id : supporter . id ,
card_id : card . id ,
statement : 'our statement' )
end . to ( raise_error do | error |
expect ( error ) . to be_a Stripe :: StripeError
end )
2018-03-25 17:30:42 +00:00
expect ( Charge ) . to_not be_exists
expect ( Payment ) . to_not be_exists
end
end
describe 'charge when customer belongs to client' do
2019-07-30 21:29:24 +00:00
before ( :each ) do
nonprofit . stripe_account_id = Stripe :: Account . create [ 'id' ]
2018-03-25 17:30:42 +00:00
nonprofit . save!
card . stripe_customer_id = 'some other id'
card . save!
2019-07-30 21:29:24 +00:00
StripeMock . prepare_error ( Stripe :: StripeError . new ( 'chaos' ) , :get_customer )
end
2018-03-25 17:30:42 +00:00
it 'handles card error' do
2019-07-30 21:29:24 +00:00
expect ( Stripe :: Charge ) . to receive ( :create ) . with ( { application_fee : 33 ,
customer : card . stripe_customer_id ,
amount : 100 ,
currency : 'usd' ,
description : 'our statement<> blah-no-way' ,
statement_descriptor : 'our statement blah-n' ,
metadata : nil } , stripe_account : nonprofit . stripe_account_id ) . and_wrap_original { | m , * args | m . call ( * args ) }
StripeMock . prepare_card_error ( :card_declined )
2018-03-25 17:30:42 +00:00
2019-07-30 21:29:24 +00:00
finished_result = InsertCharge . with_stripe ( amount : 100 ,
nonprofit_id : nonprofit . id ,
supporter_id : supporter . id ,
card_id : card . id ,
statement : 'our statement<> blah-no-way' )
2018-03-25 17:30:42 +00:00
2019-07-30 21:29:24 +00:00
common_expected = { id : Charge . first . id , amount : 100 , fee : 33 , stripe_charge_id : nil , status : 'failed' , failure_message : 'There was an error with your card: The card was declined' , created_at : Time . now , updated_at : Time . now , disbursed : nil }
2018-03-25 17:30:42 +00:00
2019-07-30 21:29:24 +00:00
result_expected = common_expected . merge ( card_id : card . id , nonprofit_id : nonprofit . id , donation_id : nil , supporter_id : supporter . id , ticket_id : nil , payment_id : nil , profile_id : nil , direct_debit_detail_id : nil ) . with_indifferent_access
2018-03-25 17:30:42 +00:00
2019-07-30 21:29:24 +00:00
expect ( finished_result [ 'charge' ] . attributes ) . to eq result_expected
expect ( Charge . first . attributes ) . to eq result_expected
2018-03-25 17:30:42 +00:00
2019-07-30 21:29:24 +00:00
expect ( Payment ) . to_not be_exists
2018-03-25 17:30:42 +00:00
end
it 'handles general Stripe error' do
2019-07-30 21:29:24 +00:00
expect ( Stripe :: Charge ) . to receive ( :create ) . with ( { application_fee : 33 ,
customer : card . stripe_customer_id ,
amount : 100 ,
currency : 'usd' ,
description : 'our statement<> blah-no-way' ,
statement_descriptor : 'our statement blah-n' ,
metadata : nil } , stripe_account : nonprofit . stripe_account_id ) . and_wrap_original { | m , * args | m . call ( * args ) }
StripeMock . prepare_error ( Stripe :: StripeError . new ( 'blah' ) , :new_charge )
2018-03-25 17:30:42 +00:00
2019-07-30 21:29:24 +00:00
finished_result = InsertCharge . with_stripe ( amount : 100 ,
nonprofit_id : nonprofit . id ,
supporter_id : supporter . id ,
card_id : card . id ,
statement : 'our statement<> blah-no-way' )
2018-03-25 17:30:42 +00:00
2019-07-30 21:29:24 +00:00
common_expected = { id : Charge . first . id , amount : 100 , fee : 33 , stripe_charge_id : nil , status : 'failed' , failure_message : " We're sorry, but something went wrong. We've been notified about this issue. " , created_at : Time . now , updated_at : Time . now , disbursed : nil }
2018-03-25 17:30:42 +00:00
2019-07-30 21:29:24 +00:00
result_expected = common_expected . merge ( card_id : card . id , nonprofit_id : nonprofit . id , donation_id : nil , supporter_id : supporter . id , ticket_id : nil , payment_id : nil , profile_id : nil , direct_debit_detail_id : nil ) . with_indifferent_access
2018-03-25 17:30:42 +00:00
2019-07-30 21:29:24 +00:00
expect ( finished_result [ 'charge' ] . attributes ) . to eq result_expected
expect ( Charge . first . attributes ) . to eq result_expected
2018-03-25 17:30:42 +00:00
2019-07-30 21:29:24 +00:00
expect ( Payment ) . to_not be_exists
2018-03-25 17:30:42 +00:00
end
describe 'input success' do
2019-07-30 21:29:24 +00:00
let ( :valid_input ) do
{ amount : 100 ,
nonprofit_id : nonprofit . id ,
supporter_id : supporter . id ,
card_id : card . id ,
donation_id : 555 ,
towards : 'blah' ,
kind : 'kind' ,
statement : 'our statement<> blah-no-way' }
end
let ( :date ) { Time . new ( 2002 , 10 , 31 ) }
let ( :valid_input_with_date ) { valid_input . merge ( date : date ) }
2018-03-25 17:30:42 +00:00
it 'saves the payment and updates the charge' do
2019-07-30 21:29:24 +00:00
stripe_charge_id = nil
expect ( Stripe :: Charge ) . to receive ( :create ) . with ( { application_fee : 33 ,
customer : card . stripe_customer_id ,
amount : 100 ,
currency : 'usd' ,
description : 'our statement<> blah-no-way' ,
statement_descriptor : 'our statement blah-n' ,
metadata : nil } , stripe_account : nonprofit . stripe_account_id ) . and_wrap_original { | m , * args |
a = m . call ( * args )
stripe_charge_id = a [ 'id' ]
a
}
finished_result = InsertCharge . with_stripe ( valid_input )
common_charge_expected = { id : Charge . first . id , amount : 100 , fee : 33 , stripe_charge_id : stripe_charge_id , status : 'pending' , failure_message : nil , created_at : Time . now , updated_at : Time . now , disbursed : nil }
result_charge_expected = common_charge_expected . merge ( card_id : card . id , nonprofit_id : nonprofit . id , donation_id : 555 , supporter_id : supporter . id , ticket_id : nil , payment_id : Payment . first . id , profile_id : nil , direct_debit_detail_id : nil ) . with_indifferent_access
expect ( finished_result [ 'charge' ] . attributes ) . to eq result_charge_expected
expect ( Charge . first . attributes ) . to eq result_charge_expected
expect ( Charge . count ) . to eq 1
common_payment_expected = { id : Payment . first . id ,
gross_amount : 100 ,
fee_total : - 33 ,
net_amount : 67 ,
towards : 'blah' ,
kind : 'kind' ,
donation_id : 555 ,
nonprofit_id : nonprofit . id ,
supporter_id : supporter . id ,
refund_total : 0 ,
date : Time . now ,
created_at : Time . now ,
updated_at : Time . now ,
search_vectors : nil } . with_indifferent_access
expect ( finished_result [ 'payment' ] . attributes ) . to eq common_payment_expected
expect ( Payment . first . attributes ) . to eq common_payment_expected
expect ( Payment . count ) . to eq 1
2018-03-25 17:30:42 +00:00
end
it 'saves the payment and updates the charge with passed date' do
2019-07-30 21:29:24 +00:00
stripe_charge_id = nil
expect ( Stripe :: Charge ) . to receive ( :create ) . with ( { application_fee : 33 ,
customer : card . stripe_customer_id ,
amount : 100 ,
currency : 'usd' ,
description : 'our statement<> blah-no-way' ,
statement_descriptor : 'our statement blah-n' ,
metadata : nil } , stripe_account : nonprofit . stripe_account_id ) . and_wrap_original { | m , * args |
a = m . call ( * args )
stripe_charge_id = a [ 'id' ]
a
}
finished_result = InsertCharge . with_stripe ( valid_input_with_date )
common_charge_expected = { id : Charge . first . id , amount : 100 , fee : 33 , stripe_charge_id : stripe_charge_id , status : 'pending' , failure_message : nil , created_at : Time . now , updated_at : Time . now , disbursed : nil }
result_charge_expected = common_charge_expected . merge ( card_id : card . id , nonprofit_id : nonprofit . id , donation_id : 555 , supporter_id : supporter . id , ticket_id : nil , payment_id : Payment . first . id , profile_id : nil , direct_debit_detail_id : nil ) . with_indifferent_access
expect ( finished_result [ 'charge' ] . attributes ) . to eq result_charge_expected
expect ( Charge . first . attributes ) . to eq result_charge_expected
expect ( Charge . count ) . to eq 1
common_payment_expected = { id : Payment . first . id ,
gross_amount : 100 ,
fee_total : - 33 ,
net_amount : 67 ,
towards : 'blah' ,
kind : 'kind' ,
donation_id : 555 ,
nonprofit_id : nonprofit . id ,
supporter_id : supporter . id ,
refund_total : 0 ,
date : date ,
created_at : Time . now ,
updated_at : Time . now ,
search_vectors : nil } . with_indifferent_access
expect ( finished_result [ 'payment' ] . attributes ) . to eq common_payment_expected
expect ( Payment . first . attributes ) . to eq common_payment_expected
expect ( Payment . count ) . to eq 1
2018-03-25 17:30:42 +00:00
end
end
end
describe 'charge when customer belongs to us' do
2019-07-30 21:29:24 +00:00
before ( :each ) do
nonprofit . stripe_account_id = Stripe :: Account . create [ 'id' ]
2018-03-25 17:30:42 +00:00
nonprofit . save!
card . stripe_customer_id = 'some other id'
2019-07-30 21:29:24 +00:00
cust = Stripe :: Customer . create
2018-03-25 17:30:42 +00:00
card . stripe_customer_id = cust [ 'id' ]
card . save!
2019-07-30 21:29:24 +00:00
new_cust = Stripe :: Customer . create
2018-03-25 17:30:42 +00:00
card_for_other_supporter . stripe_customer_id = new_cust [ 'id' ]
card_for_other_supporter . save!
2019-07-30 21:29:24 +00:00
# StripeMock.prepare_error(Stripe::StripeError.new("chaos"), :get_customer)
end
2018-03-25 17:30:42 +00:00
def create_expected_charge_args ( expected_card )
2019-07-30 21:29:24 +00:00
[ { application_fee : 33 ,
customer : expected_card . stripe_customer_id ,
amount : 100 ,
currency : 'usd' ,
description : 'our statement<> blah-no-way' ,
statement_descriptor : 'our statement blah-n' ,
metadata : nil ,
destination : nonprofit . stripe_account_id } , { } ]
2018-03-25 17:30:42 +00:00
end
it 'handles card error' do
2019-07-30 21:29:24 +00:00
expect ( Stripe :: Charge ) . to receive ( :create ) . with ( * create_expected_charge_args ( card ) ) . and_wrap_original { | m , * args | m . call ( * args ) }
StripeMock . prepare_card_error ( :card_declined )
2018-03-25 17:30:42 +00:00
2019-07-30 21:29:24 +00:00
finished_result = InsertCharge . with_stripe ( amount : 100 ,
nonprofit_id : nonprofit . id ,
supporter_id : supporter . id ,
card_id : card . id ,
statement : 'our statement<> blah-no-way' )
2018-03-25 17:30:42 +00:00
2019-07-30 21:29:24 +00:00
common_expected = { id : Charge . first . id , amount : 100 , fee : 33 , stripe_charge_id : nil , status : 'failed' , failure_message : 'There was an error with your card: The card was declined' , created_at : Time . now , updated_at : Time . now , disbursed : nil }
2018-03-25 17:30:42 +00:00
2019-07-30 21:29:24 +00:00
result_expected = common_expected . merge ( card_id : card . id , nonprofit_id : nonprofit . id , donation_id : nil , supporter_id : supporter . id , ticket_id : nil , payment_id : nil , profile_id : nil , direct_debit_detail_id : nil ) . with_indifferent_access
2018-03-25 17:30:42 +00:00
2019-07-30 21:29:24 +00:00
expect ( finished_result [ 'charge' ] . attributes ) . to eq result_expected
expect ( Charge . first . attributes ) . to eq result_expected
2018-03-25 17:30:42 +00:00
2019-07-30 21:29:24 +00:00
expect ( Payment ) . to_not be_exists
2018-03-25 17:30:42 +00:00
end
it 'handles general Stripe error' do
2019-07-30 21:29:24 +00:00
expect ( Stripe :: Charge ) . to receive ( :create ) . with ( * create_expected_charge_args ( card ) ) . and_wrap_original { | m , * args | m . call ( * args ) }
StripeMock . prepare_error ( Stripe :: StripeError . new ( 'blah' ) , :new_charge )
2018-03-25 17:30:42 +00:00
2019-07-30 21:29:24 +00:00
finished_result = InsertCharge . with_stripe ( amount : 100 ,
nonprofit_id : nonprofit . id ,
supporter_id : supporter . id ,
card_id : card . id ,
statement : 'our statement<> blah-no-way' )
2018-03-25 17:30:42 +00:00
2019-07-30 21:29:24 +00:00
common_expected = { id : Charge . first . id , amount : 100 , fee : 33 , stripe_charge_id : nil , status : 'failed' , failure_message : " We're sorry, but something went wrong. We've been notified about this issue. " , created_at : Time . now , updated_at : Time . now , disbursed : nil }
2018-03-25 17:30:42 +00:00
2019-07-30 21:29:24 +00:00
result_expected = common_expected . merge ( card_id : card . id , nonprofit_id : nonprofit . id , donation_id : nil , supporter_id : supporter . id , ticket_id : nil , payment_id : nil , profile_id : nil , direct_debit_detail_id : nil ) . with_indifferent_access
2018-03-25 17:30:42 +00:00
2019-07-30 21:29:24 +00:00
expect ( finished_result [ 'charge' ] . attributes ) . to eq result_expected
expect ( Charge . first . attributes ) . to eq result_expected
2018-03-25 17:30:42 +00:00
2019-07-30 21:29:24 +00:00
expect ( Payment ) . to_not be_exists
2018-03-25 17:30:42 +00:00
end
describe 'input success' do
2019-07-30 21:29:24 +00:00
let ( :date ) { Time . new ( 2002 , 10 , 31 ) }
2018-03-25 17:30:42 +00:00
it 'saves the payment and updates the charge' do
saves_the_payment_updates_the_charge ( card )
end
it 'saves the payment and updates the charge, if old rd and using wrong card' do
saves_the_payment_updates_the_charge ( card_for_other_supporter , true )
end
it 'saves the payment and updates the charge with passed date' do
saves_the_payment_and_updates_the_charge_with_passed_date ( card )
end
it 'saves the payment and updates the charge with passed date, if old rd and using wrong card' do
saves_the_payment_and_updates_the_charge_with_passed_date ( card , true )
end
2019-07-30 21:29:24 +00:00
def insert_charge_input ( expected_card , pass_old_donation = nil , pass_date = nil )
inner = { amount : 100 ,
nonprofit_id : nonprofit . id ,
supporter_id : supporter . id ,
card_id : expected_card . id ,
donation_id : 555 ,
towards : 'blah' ,
kind : 'kind' ,
statement : 'our statement<> blah-no-way' }
2018-03-25 17:30:42 +00:00
2019-07-30 21:29:24 +00:00
inner = inner . merge ( old_donation : true ) if pass_old_donation
2018-03-25 17:30:42 +00:00
2019-07-30 21:29:24 +00:00
inner = inner . merge ( date : date ) if pass_date
2018-03-25 17:30:42 +00:00
2019-07-30 21:29:24 +00:00
inner
2018-03-25 17:30:42 +00:00
end
2019-07-30 21:29:24 +00:00
def saves_the_payment_updates_the_charge ( expected_card , pass_old_donation = nil )
stripe_charge_id = nil
expect ( Stripe :: Charge ) . to receive ( :create ) . with ( * create_expected_charge_args ( expected_card ) ) . and_wrap_original { | m , * args |
a = m . call ( * args )
stripe_charge_id = a [ 'id' ]
a
}
finished_result = InsertCharge . with_stripe ( insert_charge_input ( expected_card , pass_old_donation ) )
common_charge_expected = { id : Charge . first . id , amount : 100 , fee : 33 , stripe_charge_id : stripe_charge_id , status : 'pending' , failure_message : nil , created_at : Time . now , updated_at : Time . now , disbursed : nil }
result_charge_expected = common_charge_expected . merge ( card_id : expected_card . id , nonprofit_id : nonprofit . id , donation_id : 555 , supporter_id : supporter . id , ticket_id : nil , payment_id : Payment . first . id , profile_id : nil , direct_debit_detail_id : nil ) . with_indifferent_access
expect ( finished_result [ 'charge' ] . attributes ) . to eq result_charge_expected
expect ( Charge . first . attributes ) . to eq result_charge_expected
expect ( Charge . count ) . to eq 1
common_payment_expected = { id : Payment . first . id ,
gross_amount : 100 ,
fee_total : - 33 ,
net_amount : 67 ,
towards : 'blah' ,
kind : 'kind' ,
donation_id : 555 ,
nonprofit_id : nonprofit . id ,
supporter_id : supporter . id ,
refund_total : 0 ,
date : Time . now ,
created_at : Time . now ,
updated_at : Time . now ,
search_vectors : nil } . with_indifferent_access
expect ( finished_result [ 'payment' ] . attributes ) . to eq common_payment_expected
expect ( Payment . first . attributes ) . to eq common_payment_expected
expect ( Payment . count ) . to eq 1
end
2018-03-25 17:30:42 +00:00
2019-07-30 21:29:24 +00:00
def saves_the_payment_and_updates_the_charge_with_passed_date ( expected_card , pass_old_donation = nil )
stripe_charge_id = nil
expect ( Stripe :: Charge ) . to receive ( :create ) . with ( * create_expected_charge_args ( expected_card ) ) . and_wrap_original { | m , * args |
a = m . call ( * args )
stripe_charge_id = a [ 'id' ]
a
}
finished_result = InsertCharge . with_stripe ( insert_charge_input ( expected_card , pass_old_donation , true ) )
common_charge_expected = { id : Charge . first . id , amount : 100 , fee : 33 , stripe_charge_id : stripe_charge_id , status : 'pending' , failure_message : nil , created_at : Time . now , updated_at : Time . now , disbursed : nil }
result_charge_expected = common_charge_expected . merge ( card_id : card . id , nonprofit_id : nonprofit . id , donation_id : 555 , supporter_id : supporter . id , ticket_id : nil , payment_id : Payment . first . id , profile_id : nil , direct_debit_detail_id : nil ) . with_indifferent_access
expect ( finished_result [ 'charge' ] . attributes ) . to eq result_charge_expected
expect ( Charge . first . attributes ) . to eq result_charge_expected
expect ( Charge . count ) . to eq 1
common_payment_expected = { id : Payment . first . id ,
gross_amount : 100 ,
fee_total : - 33 ,
net_amount : 67 ,
towards : 'blah' ,
kind : 'kind' ,
donation_id : 555 ,
nonprofit_id : nonprofit . id ,
supporter_id : supporter . id ,
refund_total : 0 ,
date : date ,
created_at : Time . now ,
updated_at : Time . now ,
search_vectors : nil } . with_indifferent_access
expect ( finished_result [ 'payment' ] . attributes ) . to eq common_payment_expected
expect ( Payment . first . attributes ) . to eq common_payment_expected
expect ( Payment . count ) . to eq 1
2018-03-25 17:30:42 +00:00
end
end
end
2019-07-30 21:29:24 +00:00
end
2018-03-25 17:30:42 +00:00
end