Correct a bug for where paydate comes as a string

This commit is contained in:
Eric Schultz 2018-04-12 14:22:38 -05:00 committed by Eric Schultz
parent b20a635ab0
commit a45991ff15
3 changed files with 37 additions and 3 deletions

View file

@ -10,11 +10,19 @@ module InsertRecurringDonation
.merge(token: {required: true, format: UUID::Regex}))
unless data[:recurring_donation].nil?
ParamValidation.new(data[:recurring_donation], {
interval: {is_integer: true},
start_date: {can_be_date: true},
time_unit: {included_in: %w(month day week year)},
paydate: {is_integer:true, min: 1, max: 28}
paydate: {is_integer:true}
})
if (data[:recurring_donation][:paydate])
data[:recurring_donation][:paydate] = data[:recurring_donation][:paydate].to_i
end
ParamValidation.new(data[:recurring_donation], {
paydate: {min:1, max:28}
})
else

View file

@ -11,12 +11,35 @@ describe InsertRecurringDonation do
it 'does recurring donation validation' do
expect {InsertRecurringDonation.with_stripe(amount: 1, nonprofit_id: 1, supporter_id: 1, token: fake_uuid,
recurring_donation: {interval: "not number", start_date: "not_date", time_unit: 4})}.to raise_error {|e|
recurring_donation: {interval: "not number", start_date: "not_date", time_unit: 4, paydate: "faf"})}.to raise_error {|e|
expect(e).to be_a ParamValidation::ValidationError
expect_validation_errors(e.data, [
{key: :interval, name: :is_integer},
{key: :start_date, name: :can_be_date},
{key: :time_unit, name: :included_in}
{key: :time_unit, name: :included_in},
{key: :paydate, name: :is_integer}
])
}
end
it 'does paydate validation min' do
expect {InsertRecurringDonation.with_stripe(amount: 1, nonprofit_id: 1, supporter_id: 1, token: fake_uuid,
recurring_donation: {paydate: "0"})}.to raise_error {|e|
expect(e).to be_a ParamValidation::ValidationError
expect_validation_errors(e.data, [
{key: :paydate, name: :min}
])
}
end
it 'does paydate validation max' do
expect {InsertRecurringDonation.with_stripe(amount: 1, nonprofit_id: 1, supporter_id: 1, token: fake_uuid,
recurring_donation: {paydate: "29"})}.to raise_error {|e|
expect(e).to be_a ParamValidation::ValidationError
expect_validation_errors(e.data, [
{key: :paydate, name: :max}
])
}

View file

@ -12,6 +12,9 @@ RSpec.shared_context :shared_rd_donation_value_context do
let(:charge_amount) {100}
let(:default_edit_token) {'7903e34c-10fe-11e8-9ead-d302c690bee4'}
before(:each){
Event.any_instance.stub(:geocode).and_return([1,1])
}
def generate_expected(donation_id, payment_id, charge_id, card, supporter, nonprofit, stripe_charge_id, data = {})