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'
|
|
|
|
|
|
|
|
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
|
|
|
|
@np = force_create(:nonprofit)
|
|
|
|
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
|