Skip to content
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
2 changes: 1 addition & 1 deletion app/models/alma/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def find_if_active(id)
return nil unless rec && rec.active?
end
rescue Error::AlmaRecordNotFoundError => e
return if e.message.include?('Alma query failed with response: 404')
return if %w[400 404].include? e.message

raise
end
Expand Down
4 changes: 2 additions & 2 deletions app/services/alma_services.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def authenticate_alma_patron?(alma_user_id, alma_password)
def get_user(alma_user_id)
params = { view: 'full', expand: 'fees' }
connection.get(user_uri_for(alma_user_id), params).tap do |res|
raise Error::AlmaRecordNotFoundError, "Alma query failed with response: #{res.status}" unless res.status == 200
raise Error::AlmaRecordNotFoundError, res.status unless res.status == 200
end
end

Expand Down Expand Up @@ -97,7 +97,7 @@ def credit(alma_user_id, pp_ref_number, fee)
payment_uri = URIs.append(fee_uri_for(alma_user_id, fee.id), '?', URI.encode_www_form(params))

connection.post(payment_uri).tap do |res|
raise Error::AlmaRecordNotFoundError, "Alma query failed with response: #{res.status}" unless res.status == 200
raise Error::AlmaRecordNotFoundError, res.status unless res.status == 200
end
end
end
Expand Down
14 changes: 12 additions & 2 deletions spec/forms_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,18 @@ def show_path(id)
it 'forbids users when active patron lookup returns Alma 404' do
patron_id = Alma::Type.sample_id_for(allowed_patron_types.first)
allow(AlmaServices::Patron).to receive(:get_user).with(patron_id)
.and_raise(Error::AlmaRecordNotFoundError,
'Alma query failed with response: 404')
.and_raise(Error::AlmaRecordNotFoundError, '404')

with_patron_login(patron_id) do
get new_form_path
expect(response).to have_http_status(:forbidden)
end
end

it 'forbids users when active patron lookup returns Alma 400' do
patron_id = Alma::Type.sample_id_for(allowed_patron_types.first)
allow(AlmaServices::Patron).to receive(:get_user).with(patron_id)
.and_raise(Error::AlmaRecordNotFoundError, '400')

with_patron_login(patron_id) do
get new_form_path
Expand Down
2 changes: 1 addition & 1 deletion spec/models/user_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@
user = User.new(uid: 'fake_uid')
allow(Alma::User).to receive(:find_if_active).with('fake_uid')
.and_raise(Error::AlmaRecordNotFoundError,
'Alma query failed with response: 500')
'500')

expect { user.primary_patron_record }.to raise_error(Error::AlmaRecordNotFoundError)
end
Expand Down
Loading