Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactored to make the renewal response from Sirsi uniform. #84

Merged
merged 4 commits into from
Jan 27, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 3 additions & 10 deletions app/controllers/renewals_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -78,17 +78,10 @@ def bulk_renewal_summary_flash(response, type)
end

def renewal_attempt_report(renewal_response)
if renewal_response.respond_to?(:each)
non_renewal_reason = error_prompt renewal_response[:error_message]
return renewal_response[:renewal].bib_summary + (non_renewal_reason || '')
if renewal_response[:sirsi_response].present?
return "#{renewal_response[:renewal].bib_summary} #{tag(:br)} Denied: #{renewal_response[:sirsi_response]}"
end

renewal_response.bib_summary
end

def error_prompt(error_message)
return if error_message.empty?

content_tag(:span, "<br>Denied: #{error_message}", nil, false)
renewal_response[:renewal].bib_summary
end
end
4 changes: 2 additions & 2 deletions app/services/symphony_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ def renew_items(user, checkouts)

case response.status
when 200
status[:success] << checkout
status[:success] << { renewal: checkout, sirsi_response: nil }
else
Rails.logger.error("Renewal (#{checkout.item_key}): #{response.body}")
status[:error] << { renewal: checkout, error_message: (error_message(response) || '') }
status[:error] << { renewal: checkout, sirsi_response: (error_message(response) || '') }
end
end
end
Expand Down
16 changes: 9 additions & 7 deletions spec/controllers/renewals_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@
end

context 'when all items returns 200' do
let(:renew_items_response) { { success: [checkouts[0], checkouts[1]], error: [] } }
let(:renew_items_response) { { success: [{ renewal: checkouts[0], sirsi_response: nil },
{ renewal: checkouts[1], sirsi_response: nil }], error: [] } }

it 'renews the items and sets flash messages' do
post :create, params: { renewal_list: ['123', '456'] }
Expand All @@ -60,9 +61,9 @@
end

context 'when not all items return 200' do
let(:non_renewal_reason) { 'Item has holds' }
let(:error_response) { { renewal: checkouts[2], error_message: non_renewal_reason } }
let(:renew_items_response) { { success: [checkouts[0]], error: [error_response] } }
let(:renew_items_response) { { success: [{ renewal: checkouts[0], sirsi_response: nil },
{ renewal: checkouts[1], sirsi_response: nil }],
error: [{ renewal: checkouts[2], sirsi_response: 'Item has holds' }] } }

it 'renews the eligible items and sets flash messages' do
post :create, params: { renewal_list: ['123', '789'] }
Expand Down Expand Up @@ -96,8 +97,9 @@
end

context 'when response include errored items with empty error message' do
let(:error_response) { { renewal: checkouts[2], error_message: '' } }
let(:renew_items_response) { { success: [checkouts[0]], error: [error_response] } }
let(:error_response) { { renewal: checkouts[2], sirsi_response: '' } }
let(:renew_items_response) { { success: [{ renewal: checkouts[0], sirsi_response: nil },
{ renewal: checkouts[1], sirsi_response: nil }], error: [] } }

it 'error messages include items title only' do
post :create, params: { renewal_list: ['123', '789'] }
Expand All @@ -108,7 +110,7 @@

context 'when user renews more than renewal flash limit items' do
let(:non_renewal_reason) { 'Item has holds' }
let(:error_response) { { renewal: checkouts[2], error_message: non_renewal_reason } }
let(:error_response) { { renewal: checkouts[2], sirsi_response: non_renewal_reason } }
let(:renew_items_response) {
{ success: [checkouts[0], [checkouts[1]]], error: [error_response] }
}
Expand Down
9 changes: 5 additions & 4 deletions spec/services/symphony_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,15 +110,16 @@

it 'returns all responses for individual renewal requests in symphony regardless of success or error' do
renew_response = client.renew_items(user, [checkouts.first, checkouts.second])
error_response = { renewal: checkouts.second, error_message: 'Item has holds' }
fail_response = { renewal: checkouts.second, sirsi_response: 'Item has holds' }
success_response = { renewal: checkouts.first, sirsi_response: nil }

expect(renew_response).to eq error: [error_response],
success: [checkouts.first]
expect(renew_response).to eq error: [fail_response],
success: [success_response]
end

it 'returns customized error messages' do
renew_response = client.renew_items(user, [checkouts.last])
error_response = { renewal: checkouts.last, error_message: 'Item has holds, cannot be renewed.' }
error_response = { renewal: checkouts.last, sirsi_response: 'Item has holds, cannot be renewed.' }

expect(renew_response).to include error: [error_response]
end
Expand Down