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