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 FetchMiscellaneousNpInfo do
|
|
|
|
describe '.fetch' do
|
|
|
|
describe 'validates params' do
|
|
|
|
it 'with empty args' do
|
2019-07-30 21:29:24 +00:00
|
|
|
expect { FetchMiscellaneousNpInfo.fetch(nil) }.to(raise_error do |error|
|
2018-03-25 17:30:42 +00:00
|
|
|
expect(error).to be_a ParamValidation::ValidationError
|
2019-07-30 21:29:24 +00:00
|
|
|
expect_validation_errors(error.data, [{ key: :np_id, name: :required },
|
|
|
|
{ key: :np_id, name: :is_integer }])
|
|
|
|
end)
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'with invalid np' do
|
2019-07-30 21:29:24 +00:00
|
|
|
expect { FetchMiscellaneousNpInfo.fetch(50) }.to(raise_error do |error|
|
2018-03-25 17:30:42 +00:00
|
|
|
expect(error).to be_a ParamValidation::ValidationError
|
2019-07-30 21:29:24 +00:00
|
|
|
expect_validation_errors(error.data, [{ key: :np_id }])
|
|
|
|
end)
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'with valid nonprofit' do
|
|
|
|
before(:each) do
|
2020-04-16 20:50:03 +00:00
|
|
|
@np = force_create(:nm_justice)
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns hash with empty misc settings' do
|
|
|
|
expect(FetchMiscellaneousNpInfo.fetch(@np.id).attributes).to eq(MiscellaneousNpInfo.new.attributes)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns the misc if already there' do
|
2019-07-30 21:29:24 +00:00
|
|
|
a = force_create(:miscellaneous_np_info, nonprofit: @np, donate_again_url: 'http://donateagain.url')
|
2018-03-25 17:30:42 +00:00
|
|
|
expect(FetchMiscellaneousNpInfo.fetch(@np.id)).to eq(a)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-07-30 21:29:24 +00:00
|
|
|
end
|