From 801c18f589cc7a09be23ae59119e60acf5941f1d Mon Sep 17 00:00:00 2001 From: Ryan Laddusaw Date: Fri, 13 Dec 2024 16:53:23 -0500 Subject: [PATCH 1/7] Catch when patron_hash is TrueClass --- app/models/requests/patron.rb | 7 +- spec/features/requests/form_spec.rb | 21 ++ .../9951680203506421_22480938160006421.json | 122 +++++++++++ .../holding_locations/annex_noncirc.json | 200 ++++++++++++++++++ spec/fixtures/raw/9951680203506421.json | 155 ++++++++++++++ 5 files changed, 504 insertions(+), 1 deletion(-) create mode 100644 spec/fixtures/availability/by_holding_id/9951680203506421_22480938160006421.json create mode 100644 spec/fixtures/holding_locations/annex_noncirc.json create mode 100644 spec/fixtures/raw/9951680203506421.json diff --git a/app/models/requests/patron.rb b/app/models/requests/patron.rb index d87cc1362..bad7fe416 100644 --- a/app/models/requests/patron.rb +++ b/app/models/requests/patron.rb @@ -93,8 +93,13 @@ def to_h private def load_patron(user:) + patron_error = "A problem occurred looking up your library account." patron_hash = current_patron_hash(user.uid) - errors << "A problem occurred looking up your library account." if patron_hash.blank? + errors << patron_error if patron_hash.blank? + if patron_hash.instance_of?(TrueClass) + errors << patron_error + return {} + end patron_hash || {} end diff --git a/spec/features/requests/form_spec.rb b/spec/features/requests/form_spec.rb index c51b4a3eb..aab615241 100644 --- a/spec/features/requests/form_spec.rb +++ b/spec/features/requests/form_spec.rb @@ -16,6 +16,7 @@ let(:temp_item_id) { '4815239' } let(:temp_id_mfhd) { '5018096' } let(:mutiple_items) { '9979171923506421' } + let(:the_senses) { '9951680203506421' } let(:transaction_url) { "https://lib-illiad.princeton.edu/ILLiadWebPlatform/transaction" } let(:transaction_note_url) { "https://lib-illiad.princeton.edu/ILLiadWebPlatform/transaction/1093806/notes" } @@ -1441,5 +1442,25 @@ expect(confirm_email.subject).to eq("In Process Request") end end + + context 'when the bibdata patron request fails' do + let(:user) { FactoryBot.create(:user) } + let(:first_item) { the_senses } + + before do + stub_availability_by_holding_id(bib_id: '9951680203506421', holding_id: '22480938160006421') + stub_catalog_raw(bib_id: '9951680203506421') + stub_single_holding_location('annex$noncirc') + stub_request(:get, "#{Requests.config[:bibdata_base]}/patron/#{user.uid}?ldap=true") + .to_return(status: 500) + login_as user + end + + it 'displays an error when the patron data can not be retreived' do + visit 'requests/9951680203506421?aeon=false&mfhd=22480938160006421' + + expect(page).to have_content('A problem occurred looking up your library account.') + end + end end # rubocop:enable Metrics/BlockLength diff --git a/spec/fixtures/availability/by_holding_id/9951680203506421_22480938160006421.json b/spec/fixtures/availability/by_holding_id/9951680203506421_22480938160006421.json new file mode 100644 index 000000000..be3fab7e2 --- /dev/null +++ b/spec/fixtures/availability/by_holding_id/9951680203506421_22480938160006421.json @@ -0,0 +1,122 @@ +[ + { + "barcode": "32101061062418", + "id": "23480938080006421", + "holding_id": "22480938160006421", + "copy_number": "1", + "status": "Available", + "status_label": "Item in place", + "status_source": "base_status", + "process_type": null, + "on_reserve": "N", + "item_type": "NoCirc", + "pickup_location_id": "annex", + "pickup_location_code": "annex", + "location": "annex$noncirc", + "label": "Forrestal Annex - Non-Circulating", + "description": "vol.6", + "enum_display": "vol.6", + "chron_display": "", + "in_temp_library": false + }, + { + "barcode": "32101061062459", + "id": "23480938090006421", + "holding_id": "22480938160006421", + "copy_number": "1", + "status": "Available", + "status_label": "Item in place", + "status_source": "base_status", + "process_type": null, + "on_reserve": "N", + "item_type": "NoCirc", + "pickup_location_id": "annex", + "pickup_location_code": "annex", + "location": "annex$noncirc", + "label": "Forrestal Annex - Non-Circulating", + "description": "vol.5", + "enum_display": "vol.5", + "chron_display": "", + "in_temp_library": false + }, + { + "barcode": "32101061062400", + "id": "23480938100006421", + "holding_id": "22480938160006421", + "copy_number": "1", + "status": "Available", + "status_label": "Item in place", + "status_source": "base_status", + "process_type": null, + "on_reserve": "N", + "item_type": "NoCirc", + "pickup_location_id": "annex", + "pickup_location_code": "annex", + "location": "annex$noncirc", + "label": "Forrestal Annex - Non-Circulating", + "description": "vol.4", + "enum_display": "vol.4", + "chron_display": "", + "in_temp_library": false + }, + { + "barcode": "32101061062467", + "id": "23480938110006421", + "holding_id": "22480938160006421", + "copy_number": "1", + "status": "Available", + "status_label": "Item in place", + "status_source": "base_status", + "process_type": null, + "on_reserve": "N", + "item_type": "NoCirc", + "pickup_location_id": "annex", + "pickup_location_code": "annex", + "location": "annex$noncirc", + "label": "Forrestal Annex - Non-Circulating", + "description": "vol.3", + "enum_display": "vol.3", + "chron_display": "", + "in_temp_library": false + }, + { + "barcode": "32101061062392", + "id": "23480938120006421", + "holding_id": "22480938160006421", + "copy_number": "1", + "status": "Available", + "status_label": "Item in place", + "status_source": "base_status", + "process_type": null, + "on_reserve": "N", + "item_type": "NoCirc", + "pickup_location_id": "annex", + "pickup_location_code": "annex", + "location": "annex$noncirc", + "label": "Forrestal Annex - Non-Circulating", + "description": "vol.2", + "enum_display": "vol.2", + "chron_display": "", + "in_temp_library": false + }, + { + "barcode": "32101060781513", + "id": "23480938130006421", + "holding_id": "22480938160006421", + "copy_number": "1", + "status": "Available", + "status_label": "Item in place", + "status_source": "base_status", + "process_type": null, + "on_reserve": "N", + "item_type": "NoCirc", + "pickup_location_id": "annex", + "pickup_location_code": "annex", + "location": "annex$noncirc", + "label": "Forrestal Annex - Non-Circulating", + "description": "vol.1", + "enum_display": "vol.1", + "chron_display": "", + "in_temp_library": false + } +] diff --git a/spec/fixtures/holding_locations/annex_noncirc.json b/spec/fixtures/holding_locations/annex_noncirc.json new file mode 100644 index 000000000..53caacfc7 --- /dev/null +++ b/spec/fixtures/holding_locations/annex_noncirc.json @@ -0,0 +1,200 @@ +{ + "label": "Non-Circulating", + "code": "annex$noncirc", + "aeon_location": false, + "recap_electronic_delivery_location": false, + "open": false, + "requestable": true, + "always_requestable": false, + "circulates": true, + "remote_storage": "", + "fulfillment_unit": "Closed", + "library": { + "label": "Forrestal Annex", + "code": "annex", + "order": 0 + }, + "holding_library": null, + "delivery_locations": [ + { + "label": "Plasma Physics Library", + "address": "Forrestal Campus Princeton, NJ 08544", + "phone_number": "609-243-3565", + "contact_email": "lewislib@princeton.edu", + "gfa_pickup": "PQ", + "staff_only": false, + "pickup_location": true, + "digital_location": true, + "library": { + "label": "Harold P. Furth Plasma Physics Library", + "code": "plasma", + "order": 0 + } + }, + { + "label": "Technical Services 693", + "address": "693 Alexander Rd. Princeton, NJ 08544", + "phone_number": "609-258-1470", + "contact_email": "catalogn@princeton.edu", + "gfa_pickup": "QT", + "staff_only": true, + "pickup_location": true, + "digital_location": false, + "library": { + "label": "Firestone Library", + "code": "firestone", + "order": 0 + } + }, + { + "label": "Architecture Library", + "address": "School of Architecture Building, Second Floor Princeton, NJ 08544", + "phone_number": "609-258-3256", + "contact_email": "ues@princeton.edu", + "gfa_pickup": "PW", + "staff_only": false, + "pickup_location": true, + "digital_location": true, + "library": { + "label": "Architecture Library", + "code": "arch", + "order": 0 + } + }, + { + "label": "East Asian Library", + "address": "Frist Campus Center, Room 317 Princeton, NJ 08544", + "phone_number": "609-258-3182", + "contact_email": "gestcirc@princeton.edu", + "gfa_pickup": "PL", + "staff_only": false, + "pickup_location": true, + "digital_location": true, + "library": { + "label": "East Asian Library", + "code": "eastasian", + "order": 0 + } + }, + { + "label": "Engineering Library", + "address": "Friend Center for Engineering Education Princeton, NJ 08544", + "phone_number": "609-258-3200", + "contact_email": "englib@princeton.edu", + "gfa_pickup": "PT", + "staff_only": false, + "pickup_location": true, + "digital_location": true, + "library": { + "label": "Engineering Library", + "code": "engineer", + "order": 0 + } + }, + { + "label": "Marquand Library of Art and Archaeology", + "address": "McCormick Hall Princeton, NJ 08544", + "phone_number": "609-258-5863", + "contact_email": "marquand@princeton.edu", + "gfa_pickup": "PJ", + "staff_only": false, + "pickup_location": true, + "digital_location": true, + "library": { + "label": "Marquand Library", + "code": "marquand", + "order": 0 + } + }, + { + "label": "Mendel Music Library", + "address": "Woolworth Center Princeton, NJ 08544", + "phone_number": "609-258-3230", + "contact_email": "muslib@princeton.edu", + "gfa_pickup": "PK", + "staff_only": false, + "pickup_location": true, + "digital_location": true, + "library": { + "label": "Mendel Music Library", + "code": "mendel", + "order": 0 + } + }, + { + "label": "Stokes Library", + "address": "Wallace Hall, Lower Level Princeton, NJ 08544", + "phone_number": "609-258-5455", + "contact_email": "piaprlib@princeton.edu", + "gfa_pickup": "PM", + "staff_only": false, + "pickup_location": true, + "digital_location": true, + "library": { + "label": "Stokes Library", + "code": "stokes", + "order": 0 + } + }, + { + "label": "Firestone Library, Resource Sharing", + "address": "One Washington Rd. Princeton, NJ 08544", + "phone_number": "609-258-1470", + "contact_email": "fstcirc@princeton.edu", + "gfa_pickup": "QA", + "staff_only": true, + "pickup_location": true, + "digital_location": false, + "library": { + "label": "Firestone Library", + "code": "firestone", + "order": 0 + } + }, + { + "label": "Lewis Library", + "address": "Washington Road and Ivy Lane Princeton, NJ 08544", + "phone_number": "609-258-6004", + "contact_email": "lewislib@princeton.edu", + "gfa_pickup": "PN", + "staff_only": false, + "pickup_location": true, + "digital_location": true, + "library": { + "label": "Lewis Library", + "code": "lewis", + "order": 0 + } + }, + { + "label": "Firestone Library", + "address": "One Washington Rd. Princeton, NJ 08544", + "phone_number": "609-258-1470", + "contact_email": "fstcirc@princeton.edu", + "gfa_pickup": "PA", + "staff_only": false, + "pickup_location": true, + "digital_location": true, + "library": { + "label": "Firestone Library", + "code": "firestone", + "order": 0 + } + }, + { + "label": "Technical Services HMT", + "address": "One Washington Rd. Princeton, NJ 08544", + "phone_number": "609-258-1470", + "contact_email": "catalogn@princeton.edu", + "gfa_pickup": "QC", + "staff_only": true, + "pickup_location": true, + "digital_location": false, + "library": { + "label": "Firestone Library", + "code": "firestone", + "order": 0 + } + } + ] +} diff --git a/spec/fixtures/raw/9951680203506421.json b/spec/fixtures/raw/9951680203506421.json new file mode 100644 index 000000000..16ddaac42 --- /dev/null +++ b/spec/fixtures/raw/9951680203506421.json @@ -0,0 +1,155 @@ +{ + "id": "9951680203506421", + "numeric_id_b": true, + "author_citation_display": [ + "Basbaum, A. I." + ], + "author_roles_1display": "{\"secondary_authors\":[\"Basbaum, A. I.\"],\"translators\":[],\"editors\":[],\"compilers\":[]}", + "author_s": [ + "Basbaum, A. I." + ], + "title_display": "The senses : a comprehensive reference.", + "title_t": [ + "The senses : a comprehensive reference." + ], + "title_citation_display": [ + "The senses : a comprehensive reference" + ], + "compiled_created_t": [ + "The senses : a comprehensive reference." + ], + "edition_display": [ + "1st ed." + ], + "pub_created_display": [ + "Amsterdam ; New York : Elsevier, 2008." + ], + "pub_created_s": [ + "Amsterdam ; New York : Elsevier, 2008." + ], + "pub_citation_display": [ + "New York: Elsevier" + ], + "pub_date_display": [ + "2008" + ], + "pub_date_start_sort": 2008, + "cataloged_tdt": "2008-01-09T00:00:00Z", + "format": [ + "Book" + ], + "description_display": [ + "6 v. : ill. (some col.) ; 27 cm." + ], + "description_t": [ + "6 v. : ill. (some col.) ; 27 cm." + ], + "number_of_pages_citation_display": [ + "6 v." + ], + "notes_display": [ + "\"Advisory board, Allan I. Basbaum ... [et al.].\"" + ], + "bib_ref_notes_display": [ + "Includes bibliographical references and indexes." + ], + "language_name_display": [ + "English" + ], + "language_facet": [ + "English" + ], + "language_iana_s": [ + "en" + ], + "contents_display": [ + "v. 1-2. Vision / vol. editors, Richard H. Masland, Tom Albright", + "v. 3. Audition / vol. editors, Peter Dallos, Donata Oertel", + "v. 4. Olfaction and taste / vol. editors, Stuart Firestein, Gary K. Beauchamp", + "v. 5. Pain / vol. editors, M. Catherine Bushnell, Allan I. Basbaum", + "v. 6. Somatosensation / vol. editors, Esther Gardner, Jon H. Kaas." + ], + "other_format_display": [ + "Also available online." + ], + "lc_subject_display": [ + "Senses and sensation" + ], + "subject_facet": [ + "Senses and sensation" + ], + "related_name_json_1display": "{\"Related name\":[\"Basbaum, A. I.\"]}", + "isbn_display": [ + "9780126394825 (set : hd.bd.)", + "0126394822 (set : hd.bd.)", + "9780120885367 (v. 1 : hd.bd.)", + "0120885360 (v. 1 : hd.bd.)", + "9780120885374 (v. 2 : hd.bd.)", + "0120885379 (v. 2 : hd.bd.)", + "9780120885381 (v. 3 : hd.bd.)", + "0120885387 (v. 3 : hd.bd.)", + "9780120885398 (v. 4 : hd.bd.)", + "0120885395 (v. 4 : hd.bd.)", + "9780120885404 (v. 5 : hd.bd.)", + "0120885409 (v. 5 : hd.bd.)", + "9780120885411 (v. 6 : hd.bd.)", + "0120885417 (v. 6 : hd.bd.)" + ], + "lccn_display": [ + " 2007939855" + ], + "lccn_s": [ + "2007939855" + ], + "isbn_s": [ + "9780126394825", + "9780120885367", + "9780120885374", + "9780120885381", + "9780120885398", + "9780120885404", + "9780120885411" + ], + "oclc_s": [ + "84611998" + ], + "other_version_s": [ + "9780126394825", + "9780120885367", + "9780120885374", + "9780120885381", + "9780120885398", + "9780120885404", + "9780120885411", + "ocm84611998" + ], + "holdings_1display": "{\"22480938160006421\":{\"location_code\":\"annex$noncirc\",\"location\":\"Non-Circulating\",\"library\":\"Forrestal Annex\",\"call_number\":\"QP431 .S4425 2008\",\"call_number_browse\":\"QP431 .S4425 2008\",\"items\":[{\"holding_id\":\"22480938160006421\",\"description\":\"vol.1\",\"id\":\"23480938130006421\",\"status_at_load\":\"1\",\"barcode\":\"32101060781513\",\"copy_number\":\"1\"},{\"holding_id\":\"22480938160006421\",\"description\":\"vol.6\",\"id\":\"23480938080006421\",\"status_at_load\":\"1\",\"barcode\":\"32101061062418\",\"copy_number\":\"1\"},{\"holding_id\":\"22480938160006421\",\"description\":\"vol.5\",\"id\":\"23480938090006421\",\"status_at_load\":\"1\",\"barcode\":\"32101061062459\",\"copy_number\":\"1\"},{\"holding_id\":\"22480938160006421\",\"description\":\"vol.2\",\"id\":\"23480938120006421\",\"status_at_load\":\"1\",\"barcode\":\"32101061062392\",\"copy_number\":\"1\"},{\"holding_id\":\"22480938160006421\",\"description\":\"vol.4\",\"id\":\"23480938100006421\",\"status_at_load\":\"1\",\"barcode\":\"32101061062400\",\"copy_number\":\"1\"},{\"holding_id\":\"22480938160006421\",\"description\":\"vol.3\",\"id\":\"23480938110006421\",\"status_at_load\":\"1\",\"barcode\":\"32101061062467\",\"copy_number\":\"1\"}],\"location_has\":[\"Vol. 1-v. 6\"],\"supplements\":[null],\"indexes\":[null]}}", + "location_code_s": [ + "annex$noncirc" + ], + "location": [ + "Forrestal Annex" + ], + "location_display": [ + "Non-Circulating" + ], + "advanced_location_s": [ + "annex$noncirc", + "Forrestal Annex" + ], + "call_number_display": [ + "QP431 .S4425 2008" + ], + "call_number_browse_s": [ + "QP431 .S4425 2008" + ], + "call_number_locator_display": [ + "QP431 .S4425 2008" + ], + "electronic_portfolio_s": [ + "{\"desc\":null,\"title\":\"Online Content\",\"url\":\"https://na05.alma.exlibrisgroup.com/view/uresolver/01PRI_INST/openurl?u.ignore_date_coverage=true\u0026portfolio_pid=53822803240006421\u0026Force_direct=true\",\"start\":null,\"end\":\"latest\",\"notes\":[]}" + ], + "hashed_id_ssi": "edd22a9831c941f3", + "_version_": 1813705631017730048, + "timestamp": "2024-10-23T11:54:37.824Z" +} From 7cd77f53fef7bb886af4fb18e2996c9b85c97ee0 Mon Sep 17 00:00:00 2001 From: Ryan Laddusaw Date: Mon, 16 Dec 2024 10:47:01 -0500 Subject: [PATCH 2/7] Address reek warnings --- app/models/requests/patron.rb | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app/models/requests/patron.rb b/app/models/requests/patron.rb index bad7fe416..1c16203b6 100644 --- a/app/models/requests/patron.rb +++ b/app/models/requests/patron.rb @@ -93,11 +93,9 @@ def to_h private def load_patron(user:) - patron_error = "A problem occurred looking up your library account." patron_hash = current_patron_hash(user.uid) - errors << patron_error if patron_hash.blank? - if patron_hash.instance_of?(TrueClass) - errors << patron_error + if patron_hash.instance_of?(TrueClass) || patron_hash.blank? + errors << "A problem occurred looking up your library account." return {} end patron_hash || {} From e6f8fa06bd007e179cdf2159d02d7d87ac905063 Mon Sep 17 00:00:00 2001 From: Ryan Laddusaw Date: Mon, 16 Dec 2024 13:57:29 -0500 Subject: [PATCH 3/7] Remove duplicate fixture --- spec/fixtures/alma/current_fixtures.json | 239 ----------------------- 1 file changed, 239 deletions(-) diff --git a/spec/fixtures/alma/current_fixtures.json b/spec/fixtures/alma/current_fixtures.json index 6574e2791..0dd40d19f 100644 --- a/spec/fixtures/alma/current_fixtures.json +++ b/spec/fixtures/alma/current_fixtures.json @@ -32907,245 +32907,6 @@ "In the Library" ] }, -{ - "id": [ - "9951680203506421" - ], - "numeric_id_b": [ - true - ], - "cjk_all": [ - "" - ], - "cjk_notes": [ - "" - ], - "author_citation_display": [ - "Basbaum, A. I." - ], - "author_roles_1display": [ - "{\"secondary_authors\":[\"Basbaum, A. I.\"],\"translators\":[],\"editors\":[],\"compilers\":[]}" - ], - "author_s": [ - "Basbaum, A. I." - ], - "title_display": [ - "The senses : a comprehensive reference." - ], - "title_a_index": [ - "The senses" - ], - "title_sort": [ - "senses : a comprehensive reference." - ], - "title_no_h_index": [ - "The senses : a comprehensive reference.", - "senses : a comprehensive reference." - ], - "title_t": [ - "The senses : a comprehensive reference." - ], - "title_citation_display": [ - "The senses : a comprehensive reference" - ], - "compiled_created_t": [ - "The senses : a comprehensive reference." - ], - "edition_display": [ - "1st ed." - ], - "pub_created_display": [ - "Amsterdam ; New York : Elsevier, 2008." - ], - "pub_created_s": [ - "Amsterdam ; New York : Elsevier, 2008." - ], - "pub_citation_display": [ - "New York: Elsevier" - ], - "pub_date_display": [ - "2008" - ], - "pub_date_start_sort": [ - "2008" - ], - "cataloged_tdt": [ - "2008-01-09T01:00:00Z" - ], - "format": [ - "Book" - ], - "electronic_access_1display": [ - "{\"http://www.sciencedirect.com/science/referenceworks/9780123708809\":[\"www.sciencedirect.com\"]}" - ], - "electronic_access_index": [ - "http://www.sciencedirect.com/science/referenceworks/9780123708809" - ], - "description_display": [ - "6 v. : ill. (some col.) ; 27 cm." - ], - "description_t": [ - "6 v. : ill. (some col.) ; 27 cm." - ], - "number_of_pages_citation_display": [ - "6 v." - ], - "notes_index": [ - "\"Advisory board, Allan I. Basbaum ... [et al.].\"", - "Includes bibliographical references and indexes.", - "v. 1-2. Vision / vol. editors, Richard H. Masland, Tom Albright -- v. 3. Audition / vol. editors, Peter Dallos, Donata Oertel -- v. 4. Olfaction and taste / vol. editors, Stuart Firestein, Gary K. Beauchamp -- v. 5. Pain / vol. editors, M. Catherine Bushnell, Allan I. Basbaum -- v. 6. Somatosensation / vol. editors, Esther Gardner, Jon H. Kaas.", - "Also available online." - ], - "notes_display": [ - "\"Advisory board, Allan I. Basbaum ... [et al.].\"" - ], - "bib_ref_notes_display": [ - "Includes bibliographical references and indexes." - ], - "language_facet": [ - "English" - ], - "publication_place_facet": [ - "Netherlands" - ], - "language_code_s": [ - "eng" - ], - "language_iana_s": [ - "en" - ], - "contents_display": [ - "v. 1-2. Vision / vol. editors, Richard H. Masland, Tom Albright", - "v. 3. Audition / vol. editors, Peter Dallos, Donata Oertel", - "v. 4. Olfaction and taste / vol. editors, Stuart Firestein, Gary K. Beauchamp", - "v. 5. Pain / vol. editors, M. Catherine Bushnell, Allan I. Basbaum", - "v. 6. Somatosensation / vol. editors, Esther Gardner, Jon H. Kaas." - ], - "other_format_display": [ - "Also available online." - ], - "lc_subject_display": [ - "Senses and sensation" - ], - "lc_subject_include_archaic_search_terms_index": [ - "Senses and sensation" - ], - "subject_unstem_search": [ - "Senses and sensation" - ], - "local_subject_unstem_search": null, - "siku_subject_unstem_search": null, - "homoit_subject_unstem_search": null, - "subject_facet": [ - "Senses and sensation" - ], - "subject_topic_facet": [ - "Senses and sensation" - ], - "lc_1letter_facet": [ - "Q - Science" - ], - "lc_rest_facet": [ - "QP - Physiology" - ], - "lc_facet": [ - "Q - Science", - "Q - Science:QP - Physiology" -], - "call_number_scheme_facet": [ - "Library of Congress" - ], - "call_number_group_facet": [ - "Q - Science" - ], - "call_number_full_facet": [ - "QP - Physiology" - ], - "related_name_json_1display": [ - "{\"Related name\":[\"Basbaum, A. I.\"]}" - ], - "isbn_display": [ - "9780126394825 (set : hd.bd.)", - "0126394822 (set : hd.bd.)", - "9780120885367 (v. 1 : hd.bd.)", - "0120885360 (v. 1 : hd.bd.)", - "9780120885374 (v. 2 : hd.bd.)", - "0120885379 (v. 2 : hd.bd.)", - "9780120885381 (v. 3 : hd.bd.)", - "0120885387 (v. 3 : hd.bd.)", - "9780120885398 (v. 4 : hd.bd.)", - "0120885395 (v. 4 : hd.bd.)", - "9780120885404 (v. 5 : hd.bd.)", - "0120885409 (v. 5 : hd.bd.)", - "9780120885411 (v. 6 : hd.bd.)", - "0120885417 (v. 6 : hd.bd.)" - ], - "lccn_display": [ - " 2007939855" - ], - "lccn_s": [ - "2007939855" - ], - "isbn_s": [ - "9780126394825", - "9780120885367", - "9780120885374", - "9780120885381", - "9780120885398", - "9780120885404", - "9780120885411" - ], - "oclc_s": [ - "84611998" - ], - "standard_no_index": [ - "5168020", - "5168020-princetondb", - "ocm84611998" - ], - "other_version_s": [ - "9780126394825", - "9780120885367", - "9780120885374", - "9780120885381", - "9780120885398", - "9780120885404", - "9780120885411", - "ocm84611998" - ], - "holdings_1display": [ - "{\"22480938160006421\":{\"location_code\":\"annex$noncirc\",\"location\":\"Non-Circulating\",\"library\":\"Forrestal Annex\",\"call_number\":\"QP431 .S4425 2008\",\"call_number_browse\":\"QP431 .S4425 2008\",\"items\":[{\"holding_id\":\"22480938160006421\",\"enumeration\":\"vol.1\",\"id\":\"23480938130006421\",\"status_at_load\":\"1\",\"barcode\":\"32101060781513\",\"copy_number\":\"1\"},{\"holding_id\":\"22480938160006421\",\"enumeration\":\"vol.6\",\"id\":\"23480938080006421\",\"status_at_load\":\"1\",\"barcode\":\"32101061062418\",\"copy_number\":\"1\"},{\"holding_id\":\"22480938160006421\",\"enumeration\":\"vol.5\",\"id\":\"23480938090006421\",\"status_at_load\":\"1\",\"barcode\":\"32101061062459\",\"copy_number\":\"1\"},{\"holding_id\":\"22480938160006421\",\"enumeration\":\"vol.2\",\"id\":\"23480938120006421\",\"status_at_load\":\"1\",\"barcode\":\"32101061062392\",\"copy_number\":\"1\"},{\"holding_id\":\"22480938160006421\",\"enumeration\":\"vol.4\",\"id\":\"23480938100006421\",\"status_at_load\":\"1\",\"barcode\":\"32101061062400\",\"copy_number\":\"1\"},{\"holding_id\":\"22480938160006421\",\"enumeration\":\"vol.3\",\"id\":\"23480938110006421\",\"status_at_load\":\"1\",\"barcode\":\"32101061062467\",\"copy_number\":\"1\"}],\"location_has\":[\"Vol. 1-v. 6\"],\"supplements\":[null],\"indexes\":[null]}}" - ], - "location_code_s": [ - "annex$noncirc" - ], - "location": [ - "Forrestal Annex" - ], - "location_display": [ - "Non-Circulating" - ], - "advanced_location_s": [ - "annex$noncirc", - "Forrestal Annex" - ], - "call_number_display": [ - "QP431 .S4425 2008" - ], - "call_number_browse_s": [ - "QP431 .S4425 2008" - ], - "call_number_locator_display": [ - "QP431 .S4425 2008" - ], - "electronic_portfolio_s": [ - "{\"desc\":null,\"title\":\"Online Content\",\"url\":\"https://na05.alma.exlibrisgroup.com/view/uresolver/01PRI_INST/openurl?u.ignore_date_coverage=true&portfolio_pid=53822803240006421&Force_direct=true\",\"start\":null,\"end\":\"latest\",\"notes\":[]}" - ], - "access_facet": [ - "Online", - "In the Library" - ] -}, { "id": [ "99126831126106421" From 18dc116c2001ac65be7fa75b65280e5e1f00f902 Mon Sep 17 00:00:00 2001 From: Ryan Laddusaw Date: Mon, 16 Dec 2024 14:13:47 -0500 Subject: [PATCH 4/7] Remove solr version data --- spec/fixtures/raw/9951680203506421.json | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/spec/fixtures/raw/9951680203506421.json b/spec/fixtures/raw/9951680203506421.json index 16ddaac42..88ca914f9 100644 --- a/spec/fixtures/raw/9951680203506421.json +++ b/spec/fixtures/raw/9951680203506421.json @@ -148,8 +148,5 @@ ], "electronic_portfolio_s": [ "{\"desc\":null,\"title\":\"Online Content\",\"url\":\"https://na05.alma.exlibrisgroup.com/view/uresolver/01PRI_INST/openurl?u.ignore_date_coverage=true\u0026portfolio_pid=53822803240006421\u0026Force_direct=true\",\"start\":null,\"end\":\"latest\",\"notes\":[]}" - ], - "hashed_id_ssi": "edd22a9831c941f3", - "_version_": 1813705631017730048, - "timestamp": "2024-10-23T11:54:37.824Z" + ] } From d0b5571abbc1fc621074a4bdc5fd42f37db52dbc Mon Sep 17 00:00:00 2001 From: Ryan Laddusaw Date: Mon, 16 Dec 2024 14:26:49 -0500 Subject: [PATCH 5/7] Revert "Remove duplicate fixture" This reverts commit e6f8fa06bd007e179cdf2159d02d7d87ac905063. --- spec/fixtures/alma/current_fixtures.json | 239 +++++++++++++++++++++++ 1 file changed, 239 insertions(+) diff --git a/spec/fixtures/alma/current_fixtures.json b/spec/fixtures/alma/current_fixtures.json index 0dd40d19f..6574e2791 100644 --- a/spec/fixtures/alma/current_fixtures.json +++ b/spec/fixtures/alma/current_fixtures.json @@ -32907,6 +32907,245 @@ "In the Library" ] }, +{ + "id": [ + "9951680203506421" + ], + "numeric_id_b": [ + true + ], + "cjk_all": [ + "" + ], + "cjk_notes": [ + "" + ], + "author_citation_display": [ + "Basbaum, A. I." + ], + "author_roles_1display": [ + "{\"secondary_authors\":[\"Basbaum, A. I.\"],\"translators\":[],\"editors\":[],\"compilers\":[]}" + ], + "author_s": [ + "Basbaum, A. I." + ], + "title_display": [ + "The senses : a comprehensive reference." + ], + "title_a_index": [ + "The senses" + ], + "title_sort": [ + "senses : a comprehensive reference." + ], + "title_no_h_index": [ + "The senses : a comprehensive reference.", + "senses : a comprehensive reference." + ], + "title_t": [ + "The senses : a comprehensive reference." + ], + "title_citation_display": [ + "The senses : a comprehensive reference" + ], + "compiled_created_t": [ + "The senses : a comprehensive reference." + ], + "edition_display": [ + "1st ed." + ], + "pub_created_display": [ + "Amsterdam ; New York : Elsevier, 2008." + ], + "pub_created_s": [ + "Amsterdam ; New York : Elsevier, 2008." + ], + "pub_citation_display": [ + "New York: Elsevier" + ], + "pub_date_display": [ + "2008" + ], + "pub_date_start_sort": [ + "2008" + ], + "cataloged_tdt": [ + "2008-01-09T01:00:00Z" + ], + "format": [ + "Book" + ], + "electronic_access_1display": [ + "{\"http://www.sciencedirect.com/science/referenceworks/9780123708809\":[\"www.sciencedirect.com\"]}" + ], + "electronic_access_index": [ + "http://www.sciencedirect.com/science/referenceworks/9780123708809" + ], + "description_display": [ + "6 v. : ill. (some col.) ; 27 cm." + ], + "description_t": [ + "6 v. : ill. (some col.) ; 27 cm." + ], + "number_of_pages_citation_display": [ + "6 v." + ], + "notes_index": [ + "\"Advisory board, Allan I. Basbaum ... [et al.].\"", + "Includes bibliographical references and indexes.", + "v. 1-2. Vision / vol. editors, Richard H. Masland, Tom Albright -- v. 3. Audition / vol. editors, Peter Dallos, Donata Oertel -- v. 4. Olfaction and taste / vol. editors, Stuart Firestein, Gary K. Beauchamp -- v. 5. Pain / vol. editors, M. Catherine Bushnell, Allan I. Basbaum -- v. 6. Somatosensation / vol. editors, Esther Gardner, Jon H. Kaas.", + "Also available online." + ], + "notes_display": [ + "\"Advisory board, Allan I. Basbaum ... [et al.].\"" + ], + "bib_ref_notes_display": [ + "Includes bibliographical references and indexes." + ], + "language_facet": [ + "English" + ], + "publication_place_facet": [ + "Netherlands" + ], + "language_code_s": [ + "eng" + ], + "language_iana_s": [ + "en" + ], + "contents_display": [ + "v. 1-2. Vision / vol. editors, Richard H. Masland, Tom Albright", + "v. 3. Audition / vol. editors, Peter Dallos, Donata Oertel", + "v. 4. Olfaction and taste / vol. editors, Stuart Firestein, Gary K. Beauchamp", + "v. 5. Pain / vol. editors, M. Catherine Bushnell, Allan I. Basbaum", + "v. 6. Somatosensation / vol. editors, Esther Gardner, Jon H. Kaas." + ], + "other_format_display": [ + "Also available online." + ], + "lc_subject_display": [ + "Senses and sensation" + ], + "lc_subject_include_archaic_search_terms_index": [ + "Senses and sensation" + ], + "subject_unstem_search": [ + "Senses and sensation" + ], + "local_subject_unstem_search": null, + "siku_subject_unstem_search": null, + "homoit_subject_unstem_search": null, + "subject_facet": [ + "Senses and sensation" + ], + "subject_topic_facet": [ + "Senses and sensation" + ], + "lc_1letter_facet": [ + "Q - Science" + ], + "lc_rest_facet": [ + "QP - Physiology" + ], + "lc_facet": [ + "Q - Science", + "Q - Science:QP - Physiology" +], + "call_number_scheme_facet": [ + "Library of Congress" + ], + "call_number_group_facet": [ + "Q - Science" + ], + "call_number_full_facet": [ + "QP - Physiology" + ], + "related_name_json_1display": [ + "{\"Related name\":[\"Basbaum, A. I.\"]}" + ], + "isbn_display": [ + "9780126394825 (set : hd.bd.)", + "0126394822 (set : hd.bd.)", + "9780120885367 (v. 1 : hd.bd.)", + "0120885360 (v. 1 : hd.bd.)", + "9780120885374 (v. 2 : hd.bd.)", + "0120885379 (v. 2 : hd.bd.)", + "9780120885381 (v. 3 : hd.bd.)", + "0120885387 (v. 3 : hd.bd.)", + "9780120885398 (v. 4 : hd.bd.)", + "0120885395 (v. 4 : hd.bd.)", + "9780120885404 (v. 5 : hd.bd.)", + "0120885409 (v. 5 : hd.bd.)", + "9780120885411 (v. 6 : hd.bd.)", + "0120885417 (v. 6 : hd.bd.)" + ], + "lccn_display": [ + " 2007939855" + ], + "lccn_s": [ + "2007939855" + ], + "isbn_s": [ + "9780126394825", + "9780120885367", + "9780120885374", + "9780120885381", + "9780120885398", + "9780120885404", + "9780120885411" + ], + "oclc_s": [ + "84611998" + ], + "standard_no_index": [ + "5168020", + "5168020-princetondb", + "ocm84611998" + ], + "other_version_s": [ + "9780126394825", + "9780120885367", + "9780120885374", + "9780120885381", + "9780120885398", + "9780120885404", + "9780120885411", + "ocm84611998" + ], + "holdings_1display": [ + "{\"22480938160006421\":{\"location_code\":\"annex$noncirc\",\"location\":\"Non-Circulating\",\"library\":\"Forrestal Annex\",\"call_number\":\"QP431 .S4425 2008\",\"call_number_browse\":\"QP431 .S4425 2008\",\"items\":[{\"holding_id\":\"22480938160006421\",\"enumeration\":\"vol.1\",\"id\":\"23480938130006421\",\"status_at_load\":\"1\",\"barcode\":\"32101060781513\",\"copy_number\":\"1\"},{\"holding_id\":\"22480938160006421\",\"enumeration\":\"vol.6\",\"id\":\"23480938080006421\",\"status_at_load\":\"1\",\"barcode\":\"32101061062418\",\"copy_number\":\"1\"},{\"holding_id\":\"22480938160006421\",\"enumeration\":\"vol.5\",\"id\":\"23480938090006421\",\"status_at_load\":\"1\",\"barcode\":\"32101061062459\",\"copy_number\":\"1\"},{\"holding_id\":\"22480938160006421\",\"enumeration\":\"vol.2\",\"id\":\"23480938120006421\",\"status_at_load\":\"1\",\"barcode\":\"32101061062392\",\"copy_number\":\"1\"},{\"holding_id\":\"22480938160006421\",\"enumeration\":\"vol.4\",\"id\":\"23480938100006421\",\"status_at_load\":\"1\",\"barcode\":\"32101061062400\",\"copy_number\":\"1\"},{\"holding_id\":\"22480938160006421\",\"enumeration\":\"vol.3\",\"id\":\"23480938110006421\",\"status_at_load\":\"1\",\"barcode\":\"32101061062467\",\"copy_number\":\"1\"}],\"location_has\":[\"Vol. 1-v. 6\"],\"supplements\":[null],\"indexes\":[null]}}" + ], + "location_code_s": [ + "annex$noncirc" + ], + "location": [ + "Forrestal Annex" + ], + "location_display": [ + "Non-Circulating" + ], + "advanced_location_s": [ + "annex$noncirc", + "Forrestal Annex" + ], + "call_number_display": [ + "QP431 .S4425 2008" + ], + "call_number_browse_s": [ + "QP431 .S4425 2008" + ], + "call_number_locator_display": [ + "QP431 .S4425 2008" + ], + "electronic_portfolio_s": [ + "{\"desc\":null,\"title\":\"Online Content\",\"url\":\"https://na05.alma.exlibrisgroup.com/view/uresolver/01PRI_INST/openurl?u.ignore_date_coverage=true&portfolio_pid=53822803240006421&Force_direct=true\",\"start\":null,\"end\":\"latest\",\"notes\":[]}" + ], + "access_facet": [ + "Online", + "In the Library" + ] +}, { "id": [ "99126831126106421" From 2a0feb63c7f0d73d2057e22b732c9e4fddcf990a Mon Sep 17 00:00:00 2001 From: Ryan Laddusaw Date: Tue, 17 Dec 2024 14:08:58 -0500 Subject: [PATCH 6/7] return empty hash from rescue when bibdata returns an error Co-authored-by: Max Kadel --- app/models/requests/alma_patron.rb | 2 +- app/models/requests/full_patron.rb | 4 ++-- app/models/requests/patron.rb | 9 +++------ app/services/bibdata.rb | 10 +++++----- spec/models/requests/alma_patron_spec.rb | 6 +++--- 5 files changed, 14 insertions(+), 17 deletions(-) diff --git a/app/models/requests/alma_patron.rb b/app/models/requests/alma_patron.rb index 819b8f0d5..6b87ebdec 100644 --- a/app/models/requests/alma_patron.rb +++ b/app/models/requests/alma_patron.rb @@ -6,7 +6,7 @@ def initialize(uid:) @uid = uid end - def hash + def patron_hash { last_name:, active_email:, diff --git a/app/models/requests/full_patron.rb b/app/models/requests/full_patron.rb index 062c834ee..95d76dafc 100644 --- a/app/models/requests/full_patron.rb +++ b/app/models/requests/full_patron.rb @@ -2,9 +2,9 @@ module Requests # FullPatron pulls all available data from both Alma and LDAP via Bibdata class FullPatron - attr_reader :hash + attr_reader :patron_hash def initialize(user: nil) - @hash = ::Bibdata.get_patron(user, ldap: true) + @patron_hash = ::Bibdata.get_patron(user, ldap: true) end end end diff --git a/app/models/requests/patron.rb b/app/models/requests/patron.rb index 1c16203b6..9d3965d89 100644 --- a/app/models/requests/patron.rb +++ b/app/models/requests/patron.rb @@ -94,18 +94,15 @@ def to_h def load_patron(user:) patron_hash = current_patron_hash(user.uid) - if patron_hash.instance_of?(TrueClass) || patron_hash.blank? - errors << "A problem occurred looking up your library account." - return {} - end + errors << "A problem occurred looking up your library account." if patron_hash.blank? patron_hash || {} end def current_patron_hash(uid) if alma_provider? - AlmaPatron.new(uid:).hash + AlmaPatron.new(uid:).patron_hash else - FullPatron.new(user:).hash + FullPatron.new(user:).patron_hash end end end diff --git a/app/services/bibdata.rb b/app/services/bibdata.rb index 0bb0a630b..96bf04618 100644 --- a/app/services/bibdata.rb +++ b/app/services/bibdata.rb @@ -19,22 +19,22 @@ def get_patron(user, ldap:) build_api_patron(api_response:, user:) rescue ServerError Rails.logger.error('An error was encountered with the Patron Data Service.') - nil + {} rescue PerSecondThresholdError => per_second_error Rails.logger.error("The maximum number of HTTP requests per second for the Alma API has been exceeded.") raise(per_second_error) rescue ResourceNotFoundError Rails.logger.error("404 Patron #{user.uid} cannot be found in the Patron Data Service.") - nil + {} rescue ForbiddenError Rails.logger.error("403 Not Authorized to Connect to Patron Data Service at #{api_base_uri}/patron/#{user.uid}") - nil + {} rescue Faraday::ConnectionFailed Rails.logger.error("Unable to connect to #{api_base_uri}") - nil + {} rescue EmptyResponseError Rails.logger.error("#{patron_uri} returned an empty patron response") - nil + {} end def holding_locations diff --git a/spec/models/requests/alma_patron_spec.rb b/spec/models/requests/alma_patron_spec.rb index 8201085a0..9c1875419 100644 --- a/spec/models/requests/alma_patron_spec.rb +++ b/spec/models/requests/alma_patron_spec.rb @@ -19,20 +19,20 @@ describe '#hash' do it 'has a hash' do - expect(described_class.new(uid:).hash).to be_an_instance_of(HashWithIndifferentAccess) + expect(described_class.new(uid:).patron_hash).to be_an_instance_of(HashWithIndifferentAccess) end end context 'with multiple barcodes' do it 'creates an access patron with the active barcode' do patron = described_class.new(uid:) - expect(patron.hash[:barcode]).to eq('77777777') + expect(patron.patron_hash[:barcode]).to eq('77777777') expect(alma_stub).to have_been_requested.once end end it 'has a patron_group' do patron = described_class.new(uid:) - expect(patron.hash[:patron_group]).to eq('GST') + expect(patron.patron_hash[:patron_group]).to eq('GST') end end end From 0069df9370a65f53d0a7890859ca92508152d367 Mon Sep 17 00:00:00 2001 From: Ryan Laddusaw Date: Wed, 18 Dec 2024 12:14:00 -0500 Subject: [PATCH 7/7] Fix broken tests --- spec/controllers/account_controller_spec.rb | 6 +++--- spec/services/bibdata_spec.rb | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/controllers/account_controller_spec.rb b/spec/controllers/account_controller_spec.rb index a3da83695..4cc001362 100644 --- a/spec/controllers/account_controller_spec.rb +++ b/spec/controllers/account_controller_spec.rb @@ -141,7 +141,7 @@ stub_request(:get, invalid_patron_record_uri) .to_return(status: 404, body: 'Not Here', headers: {}) patron = account_controller.send(:current_patron, invalid_user) - expect(patron).to be nil + expect(patron).to eq({}) end it "returns a nil value when the application isn't authorized to access patron data" do @@ -149,7 +149,7 @@ stub_request(:get, unauthorized_patron_record_uri) .to_return(status: 403, body: 'Not Authorized', headers: {}) patron = account_controller.send(:current_patron, unauthorized_user) - expect(patron).to be nil + expect(patron).to eq({}) end it 'returns a nil value when the HTTP response to the API request has a 500 status code' do @@ -157,7 +157,7 @@ stub_request(:get, valid_patron_record_uri) .to_return(status: 500, body: 'Error', headers: {}) patron = account_controller.send(:current_patron, valid_user) - expect(patron).to be nil + expect(patron).to eq({}) end end end diff --git a/spec/services/bibdata_spec.rb b/spec/services/bibdata_spec.rb index 0cb933ecd..2e8b0a853 100644 --- a/spec/services/bibdata_spec.rb +++ b/spec/services/bibdata_spec.rb @@ -82,7 +82,7 @@ end it 'returns a nil value and logs a message' do - expect(patron).to be nil + expect(patron).to eq({}) expect(logger).to have_received(:error).with("An error was encountered with the Patron Data Service.") end end @@ -112,7 +112,7 @@ end it 'returns a nil value and logs a message' do - expect(patron).to be nil + expect(patron).to eq({}) expect(logger).to have_received(:error).with("404 Patron bbird cannot be found in the Patron Data Service.") end end @@ -127,7 +127,7 @@ end it 'returns a nil value and logs a message' do - expect(patron).to be nil + expect(patron).to eq({}) expect(logger).to have_received(:error).with("403 Not Authorized to Connect to Patron Data Service at #{Requests.config['bibdata_base']}/patron/bbird") end end