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

fix for new hold form for non holdable records #240

Merged
merged 9 commits into from
Sep 14, 2020
Merged
Show file tree
Hide file tree
Changes from 3 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
15 changes: 15 additions & 0 deletions app/controllers/holds_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class HoldsController < ApplicationController
before_action :set_cache_headers
before_action :authenticate_user!
before_action :check_for_blanks!, only: :create
rescue_from NewHoldException, with: :deny_new
rescue_from HoldCreateException, with: :deny_create
rescue_from HoldException, with: :past_date

Expand Down Expand Up @@ -42,10 +43,14 @@ def batch_update
#
# GET /holds/new
def new
raise NewHoldException, 'Error' if params[:catkey].blank?

form_builder = PlaceHoldForm::Builder.new(catkey: params[:catkey],
user_token: current_user.session_token,
client: symphony_client)
@place_hold_form_params = form_builder.generate

raise NewHoldException, 'Error' if @place_hold_form_params.blank?
end

# Handles placing holds
Expand Down Expand Up @@ -88,6 +93,16 @@ def check_for_blanks!
raise HoldCreateException, 'Error'
end

def deny_new
flash[:error] = if params['catkey'].blank?
t 'myaccount.hold.new_hold.catkey_missing'
else
t 'myaccount.hold.new_hold.error_html'
end

redirect_to summaries_path
end

def deny_create
flash[:error] = if barcodes.blank?
t 'myaccount.hold.place_hold.select_volumes'
Expand Down
2 changes: 1 addition & 1 deletion app/models/bib.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def initialize(record)
end

def call_list
bib.dig 'callList'
bib&.dig 'callList'
end

private
Expand Down
3 changes: 3 additions & 0 deletions app/models/new_hold_exception.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# frozen_string_literal: true

class NewHoldException < RuntimeError; end
7 changes: 7 additions & 0 deletions app/services/place_hold_form/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,16 @@ def initialize(catkey:, user_token:, client:)

def generate
bib_info = Bib.new(SymphonyClientParser::parsed_response(@client, :get_bib_info, @catkey, @user_token))

# record with empty callList
return if bib_info.call_list.blank?

@call_list = bib_info.call_list.map { |call| Call.new record: call }
process_volumetric_calls

# no holdable locations found
return if @call_list.blank?

{
catkey: @catkey,
title: bib_info.title,
Expand Down
5 changes: 4 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,7 @@ en:
select_date: To place a hold, please choose a not needed after date.
select_volumes: To place a hold, please select a volume.
success_html: <small class="text-secondary">For placed hold(s), you will receive a library notice once items are available for pick up. On-shelf items generally arrive within 2-3 weekdays. Items checked out to other borrowers will be recalled. Recalled items take a minimum of 10 days to arrive at your pickup location.</small>
error_html: <small class="text-secondary">We could not process your request. Please visit our website for more information under <a href="https://libraries.psu.edu/services/borrow-renew#QuestionsReLibraryAcct">"Why did my hold fail?"</a></small>
error_html: <small class="text-secondary">We could not process your request. Please visit our website for more information under <a href="https://libraries.psu.edu/services/borrow-renew#QuestionsReLibraryAcct">"Why did my hold fail?"</a></small>
new_hold:
catkey_missing: Please select an item to place a hold.
error_html: <span class="font-weight-bold">Sorry!</span> You cannot place a hold on this item. Contact your library if you need assistance.<br>
32 changes: 31 additions & 1 deletion spec/controllers/holds_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,10 +83,40 @@
end

it 'sends the form parameters to the view' do
get :new
get :new, params: { catkey: 1 }

expect(assigns(:place_hold_form_params)).to eq(form_params)
end

context 'when catkey param is missing' do
it 'sets a flash error message' do
get :new, params: {}

expect(flash[:error]).to match(/select an item to place a hold/)
end

it 'redirects to the summaries' do
get :new, params: {}

expect(response).to redirect_to summaries_path
end
end

context 'when user tries with a non holdable record' do
let(:form_params) {}

it 'sets a flash error message' do
get :new, params: { catkey: 1 }

expect(flash[:error]).to match(/cannot place a hold on this item/)
end

it 'redirects to the summaries' do
get :new, params: { catkey: 1 }

expect(response).to redirect_to summaries_path
end
end
end

describe '#create' do
Expand Down
190 changes: 190 additions & 0 deletions spec/factories/bibs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,196 @@
}
end

factory :bib_with_no_holdable_locations do
initialize_with {
new(body)
}

body {
{
'resource' => '/catalog/bib',
'key' => '26141494',
'fields' => {
'shadowed' => false,
'author' => 'Diamond, Jared M. author.',
'titleControlNumber' => 'l2018952825',
'catalogDate' => '2019-05-28',
'catalogFormat' => {
'resource' => '/policy/catalogFormat', 'key' => 'MARC'
},
'modifiedDate' => '2019-12-08',
'systemModifiedDate' => '2020-02-04T15:11:00-05:00',
'title' => 'Upheaval : turning points for nations in crisis',
'callList' => [{
'resource' => '/catalog/call',
'key' => '26141494:4',
'fields' => {
'library' => {
'resource' => '/policy/library', 'key' => 'UP-PAT'
},
'callNumber' => 'HN13.D52 2019',
'shadowed' => false,
'volumetric' => nil,
'dispCallNumber' => 'HN13.D52 2019',
'bib' => {
'resource' => '/catalog/bib', 'key' => '26141494'
},
'itemList' => [{
'resource' => '/catalog/item',
'key' => '26141494:4:2',
'fields' => {
'call' => {
'resource' => '/catalog/call', 'key' => '26141494:4'
},
'mediaDesk' => nil,
'itemType' => {
'resource' => '/policy/itemType', 'key' => 'BOOK'
},
'library' => {
'resource' => '/policy/library', 'key' => 'UP-PAT'
},
'shadowed' => false,
'homeLocation' => {
'resource' => '/policy/location', 'key' => 'PATERNO-2'
},
'copyNumber' => 2,
'bib' => {
'resource' => '/catalog/bib', 'key' => '26141494'
},
'barcode' => '000081297085',
'circulate' => false,
'currentLocation' => {
'resource' => '/policy/location', 'key' => 'ILLEND'
}
}
}],
'classification' => {
'resource' => '/policy/classification', 'key' => 'LC'
}
}
},
{
'resource' => '/catalog/call',
'key' => '26141494:6',
'fields' => {
'library' => {
'resource' => '/policy/library', 'key' => 'ALTOONA'
},
'callNumber' => 'HN13.D52 2019',
'shadowed' => false,
'volumetric' => nil,
'dispCallNumber' => 'HN13.D52 2019',
'bib' => {
'resource' => '/catalog/bib', 'key' => '26141494'
},
'itemList' => [{
'resource' => '/catalog/item',
'key' => '26141494:6:1',
'fields' => {
'call' => {
'resource' => '/catalog/call', 'key' => '26141494:6'
},
'mediaDesk' => nil,
'itemType' => {
'resource' => '/policy/itemType', 'key' => 'BOOKFLOAT'
},
'library' => {
'resource' => '/policy/library', 'key' => 'ALTOONA'
},
'shadowed' => false,
'homeLocation' => {
'resource' => '/policy/location', 'key' => 'STACKS-AA'
},
'copyNumber' => 1,
'bib' => {
'resource' => '/catalog/bib', 'key' => '26141494'
},
'barcode' => '000081321605',
'circulate' => false,
'currentLocation' => {
'resource' => '/policy/location', 'key' => 'ILLEND'
}
}
}],
'classification' => {
'resource' => '/policy/classification', 'key' => 'LC'
}
}
},
{
'resource' => '/catalog/call',
'key' => '26141494:3',
'fields' => {
'library' => {
'resource' => '/policy/library', 'key' => 'BEHREND'
},
'callNumber' => 'HN13.D52 2019',
'shadowed' => false,
'volumetric' => nil,
'dispCallNumber' => 'HN13.D52 2019',
'bib' => {
'resource' => '/catalog/bib', 'key' => '26141494'
},
'itemList' => [{
'resource' => '/catalog/item',
'key' => '26141494:3:1',
'fields' => {
'call' => {
'resource' => '/catalog/call', 'key' => '26141494:3'
},
'mediaDesk' => nil,
'itemType' => {
'resource' => '/policy/itemType', 'key' => 'BOOKFLOAT'
},
'library' => {
'resource' => '/policy/library', 'key' => 'BEHREND'
},
'shadowed' => false,
'homeLocation' => {
'resource' => '/policy/location', 'key' => 'STACKS-BD'
},
'copyNumber' => 1,
'bib' => {
'resource' => '/catalog/bib', 'key' => '26141494'
},
'barcode' => '000081287932',
'circulate' => false,
'currentLocation' => {
'resource' => '/policy/location', 'key' => 'ILLEND'
}
}
}],
'classification' => {
'resource' => '/policy/classification', 'key' => 'LC'
}
}
},
{
'resource' => '/catalog/call',
'key' => '26141494:1',
'fields' => {
'library' => {
'resource' => '/policy/library', 'key' => 'WSCRANTON'
},
'callNumber' => 'SN15687372',
'shadowed' => false,
'volumetric' => nil,
'dispCallNumber' => 'SN15687372',
'bib' => {
'resource' => '/catalog/bib', 'key' => '26141494'
},
'itemList' => [],
'classification' => {
'resource' => '/policy/classification', 'key' => 'LC'
}
}
}],
'createDate' => '2019-03-11'
}
}
}
end

factory :bib_with_holdables do
initialize_with {
new(body)
Expand Down
18 changes: 18 additions & 0 deletions spec/services/place_hold_form/builder_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,24 @@
expect(form_params[:author]).to eq 'Hill Street blues (Television program)'
end

context 'when item is not holdable' do
before do
bib_info.record['fields']['callList'] = ''
end

it 'will not generate form params' do
expect(form_params).to be_nil
end
end

context 'when item has no items with holdable locations' do
let(:bib_info) { build(:bib_with_no_holdable_locations) }

it 'will not generate form params' do
expect(form_params).to be_nil
end
end

context 'when there are volumetric calls to present to the user' do
it 'will generate holdables when supplied with a body that has a callList' do
expect(form_params[:volumetric_calls].count).to be 8
Expand Down