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 UpdateMiscellaneousNpInfo do
|
|
|
|
describe '#update' do
|
|
|
|
describe 'validates parameters' do
|
|
|
|
it 'does basic validation' do
|
2019-07-30 21:29:24 +00:00
|
|
|
expect { UpdateMiscellaneousNpInfo.update(nil, nil) }.to (raise_error do |error|
|
|
|
|
expect(error).to be_a ParamValidation::ValidationError
|
|
|
|
expect_validation_errors(error.data, [{ key: :np_id, name: :required },
|
|
|
|
{ key: :np_id, name: :is_integer },
|
|
|
|
{ key: :misc_settings, name: :required },
|
|
|
|
{ key: :misc_settings, name: :is_hash }])
|
|
|
|
end)
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
it 'does np validation' do
|
2019-07-30 21:29:24 +00:00
|
|
|
expect { UpdateMiscellaneousNpInfo.update(50, {}) }.to (raise_error do |error|
|
|
|
|
expect(error).to be_a ParamValidation::ValidationError
|
|
|
|
expect_validation_errors(error.data, [{ key: :np_id }])
|
|
|
|
end)
|
2018-03-25 17:30:42 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe 'main' do
|
2020-04-16 20:50:03 +00:00
|
|
|
let!(:np) { force_create(:nm_justice) }
|
2019-07-30 21:29:24 +00:00
|
|
|
let (:working_message) { '<p>working message</p>' }
|
2018-03-25 17:30:42 +00:00
|
|
|
it 'sets change_amount_message to nil if empty tags' do
|
|
|
|
expect(MiscellaneousNpInfo.count).to eq 0
|
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
update_result = UpdateMiscellaneousNpInfo.update(np.id, donate_again_url: 'url', not_an_attribute: 3, change_amount_message: '<p><br></p>')
|
|
|
|
expect(update_result).to have_attributes donate_again_url: 'url', nonprofit: np, change_amount_message: nil
|
2018-03-25 17:30:42 +00:00
|
|
|
expect(MiscellaneousNpInfo.count).to eq 1
|
|
|
|
expect(update_result).to eq MiscellaneousNpInfo.first!
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'add misc if it doesnt exist' do
|
|
|
|
expect(MiscellaneousNpInfo.count).to eq 0
|
|
|
|
|
2019-07-30 21:29:24 +00:00
|
|
|
update_result = UpdateMiscellaneousNpInfo.update(np.id, donate_again_url: 'url', not_an_attribute: 3, change_amount_message: working_message)
|
|
|
|
expect(update_result).to have_attributes donate_again_url: 'url', nonprofit: np, change_amount_message: working_message
|
2018-03-25 17:30:42 +00:00
|
|
|
expect(MiscellaneousNpInfo.count).to eq 1
|
|
|
|
expect(update_result).to eq MiscellaneousNpInfo.first!
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'update misc if already there' do
|
2019-07-30 21:29:24 +00:00
|
|
|
Timecop.freeze(2020, 0o1, 0o5) do
|
2018-03-25 17:30:42 +00:00
|
|
|
old_misc = create(:miscellaneous_np_info, nonprofit: np, donate_again_url: 'old_url')
|
|
|
|
expect(MiscellaneousNpInfo.count).to eq 1
|
|
|
|
Timecop.freeze(10) do
|
2019-07-30 21:29:24 +00:00
|
|
|
update_result = UpdateMiscellaneousNpInfo.update(np.id, donate_again_url: 'url', not_an_attribute: 3, change_amount_message: working_message)
|
|
|
|
expect(update_result).to have_attributes donate_again_url: 'url', nonprofit: np, change_amount_message: working_message
|
2018-03-25 17:30:42 +00:00
|
|
|
expect(MiscellaneousNpInfo.count).to eq 1
|
|
|
|
expect(update_result).to eq MiscellaneousNpInfo.first!
|
|
|
|
|
|
|
|
expect(update_result.created_at).to eq old_misc.created_at
|
|
|
|
expect(update_result.updated_at).to be > old_misc.updated_at
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2019-07-30 21:29:24 +00:00
|
|
|
end
|