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 'rails_helper'
|
|
|
|
|
|
|
|
describe DirectDebitDetailsController, type: :request do
|
|
|
|
describe 'POST /sepa' do
|
2019-07-30 21:29:24 +00:00
|
|
|
let!(:nonprofit) { Nonprofit.create(name: 'new', city: 'NY', state_code: 'NY') }
|
2018-03-25 17:30:42 +00:00
|
|
|
let(:supporter) { Supporter.create(nonprofit: nonprofit) }
|
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
let(:valid_params) do
|
|
|
|
{
|
2018-03-25 17:30:42 +00:00
|
|
|
supporter_id: supporter.id,
|
|
|
|
sepa_params: {
|
2019-07-30 21:29:24 +00:00
|
|
|
iban: 'iban',
|
|
|
|
bic: 'bic',
|
|
|
|
name: 'name'
|
2018-03-25 17:30:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'requires params' do
|
|
|
|
it 'is valid when sepa_params, donation_id and supporter_id are present' do
|
2019-07-30 21:29:24 +00:00
|
|
|
post '/sepa', params: valid_params
|
2018-03-25 17:30:42 +00:00
|
|
|
|
|
|
|
assert_response 200
|
2019-07-30 21:29:24 +00:00
|
|
|
assert_equal nil, JSON.parse(@response.body)['errors']
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'is not valid without sepa_params' do
|
2019-07-30 21:29:24 +00:00
|
|
|
post '/sepa', params: valid_params.except(:sepa_params)
|
2018-03-25 17:30:42 +00:00
|
|
|
|
|
|
|
assert_response 422
|
2019-07-30 21:29:24 +00:00
|
|
|
assert_equal ['sepa_params required'], JSON.parse(@response.body)['errors']
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'is not valid without supporter_id' do
|
2019-07-30 21:29:24 +00:00
|
|
|
post '/sepa', params: valid_params.except(:supporter_id)
|
2018-03-25 17:30:42 +00:00
|
|
|
|
|
|
|
assert_response 422
|
2019-07-30 21:29:24 +00:00
|
|
|
assert_equal ['supporter_id required'], JSON.parse(@response.body)['errors']
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|