From 5cffe2e38e5392ec69803fe0820c3aea2f92d26e Mon Sep 17 00:00:00 2001 From: Jane Sandberg Date: Tue, 30 Jan 2024 12:01:12 -0800 Subject: [PATCH 1/3] Start organizing request spec by patron group Co-authored-by: Christina Chortaria Co-authored-by: Kevin Reiss Co-authored-by: Mark Zelesky Co-authored-by: regineheberlein Co-authored-by: Ryan Laddusaw --- .../requests/requests_by_patron_group_spec.rb | 83 +++++++++++++++++++ spec/fixtures/bibdata/patron/faculty.json | 13 +++ 2 files changed, 96 insertions(+) create mode 100644 spec/features/requests/requests_by_patron_group_spec.rb create mode 100644 spec/fixtures/bibdata/patron/faculty.json diff --git a/spec/features/requests/requests_by_patron_group_spec.rb b/spec/features/requests/requests_by_patron_group_spec.rb new file mode 100644 index 000000000..3347830e1 --- /dev/null +++ b/spec/features/requests/requests_by_patron_group_spec.rb @@ -0,0 +1,83 @@ +# frozen_string_literal: true +require 'rails_helper' + +RSpec.shared_examples "can request", vcr: { cassette_name: 'request_features', record: :none } do + let(:mms_id) { '9994933183506421?mfhd=22558528920006421' } + let(:user) { FactoryBot.create(:user) } + + before do + login_as user + end + + it "PUL ReCAP print item" do + stub_catalog_raw(bib_id: '9994933183506421') + stub_scsb_availability(bib_id: "9994933183506421", institution_id: "PUL", barcode: '32101095798938') + scsb_url = "#{Requests::Config[:scsb_base]}/requestItem/requestItem" + stub_request(:post, scsb_url) + .with(body: hash_including(author: "", bibId: "9994933183506421", callNumber: "PJ7962.A5495 A95 2016", chapterTitle: "", deliveryLocation: "PA", emailAddress: 'a@b.com', endPage: "", issue: "", itemBarcodes: ["32101095798938"], itemOwningInstitution: "PUL", patronBarcode: "22101008199999", + requestNotes: "", requestType: "RETRIEVAL", requestingInstitution: "PUL", startPage: "", titleIdentifier: "ʻAwāṭif madfūnah عواطف مدفونة", username: "jstudent", volume: "")) + .to_return(status: 200, body: good_response, headers: {}) + stub_request(:post, Requests::Config[:scsb_base]) + .with(headers: { 'Accept' => '*/*' }) + .to_return(status: 200, body: "", headers: {}) + stub_request(:post, "#{Alma.configuration.region}/almaws/v1/bibs/9994933183506421/holdings/22558528920006421/items/23558528910006421/requests?user_id=960594184") + .with(body: hash_including(request_type: "HOLD", pickup_location_type: "LIBRARY", pickup_location_library: "firestone")) + .to_return(status: 200, body: fixture("alma_hold_response.json"), headers: { 'content-type': 'application/json' }) + visit "/requests/#{mms_id}" + expect(page).to have_content 'Electronic Delivery' + # some weird issue with this and capybara examining the page source shows it is there. + expect(page).to have_selector '#request_user_barcode', visible: :hidden + choose('requestable__delivery_mode_23558528910006421_print') # chooses 'print' radio button + select('Firestone Library', from: 'requestable__pick_up_23558528910006421') + expect { click_button 'Request this Item' }.to change { ActionMailer::Base.deliveries.count }.by(1) + expect(a_request(:post, scsb_url)).to have_been_made + expect(page).to have_content I18n.t("requests.submit.recap_success") + confirm_email = ActionMailer::Base.deliveries.last + expect(confirm_email.subject).to eq("Patron Initiated Catalog Request Confirmation") + expect(confirm_email.html_part.body.to_s).not_to have_content("translation missing") + expect(confirm_email.text_part.body.to_s).not_to have_content("translation missing") + expect(confirm_email.to).to eq(["a@b.com"]) + expect(confirm_email.cc).to be_blank + expect(confirm_email.html_part.body.to_s).to have_content("ʻAwāṭif madfūnah") + expect(confirm_email.html_part.body.to_s).not_to have_content("Remain only in the designated pick-up area") + end + +end + +describe 'Faculty and Professional (P)' do + let(:patron_response) { fixture('/bibdata/patron/faculty.json') } + let(:good_response) { fixture('/scsb_request_item_response.json') } + it_behaves_like "can request" +end + +describe 'Regular Staff (REG)' do +end + +describe 'Graduate Student (GRAD)' do +end + +describe 'Senior Undergraduate (SENR)' do +end + +describe 'Undergraduate (UGRAD)' do +end + +describe 'Faculty Affiliate (Affiliate-P)' do + context 'when logging in using a NetID in CAS' do + end + context 'when logging in using Alma' do + end +end + +describe 'Affiliate (Affiliate)' do + context 'when logging in using a NetID in CAS' do + end + context 'when logging in using Alma' do + end +end + +describe 'Guest Patron (GST)' do +end + +describe 'Casual Hourly (CASUAL)' do +end diff --git a/spec/fixtures/bibdata/patron/faculty.json b/spec/fixtures/bibdata/patron/faculty.json new file mode 100644 index 000000000..4feffcd3a --- /dev/null +++ b/spec/fixtures/bibdata/patron/faculty.json @@ -0,0 +1,13 @@ +{ + "netid": "netid123", + "first_name": "Faculty", + "last_name": "Faculty", + "barcode": "1234567890", + "university_id": "1234", + "patron_id": "5678", + "patron_group": "staff", + "patron_group_desc": "P Faculty & Professional", + "active_email": "netid123@Princeton.EDU", + "campus_authorized": true, + "campus_authorized_category": "full" +} From 9074f5812a4385f98a60a15db0669bfe24644993 Mon Sep 17 00:00:00 2001 From: regineheberlein Date: Mon, 12 Feb 2024 14:00:23 -0500 Subject: [PATCH 2/3] Stubbed alma holdings, delivery locations; added fixture for availability # Co-authored-by: Carolyn Cole git commit -m --- .../requests/requests_by_patron_group_spec.rb | 10 +- .../9994933183506421_22558528920006421.json | 22 +++ spec/fixtures/raw/9994933183506421.json | 129 ++++++++++++++++++ 3 files changed, 160 insertions(+), 1 deletion(-) create mode 100644 spec/fixtures/availability/by_holding_id/9994933183506421_22558528920006421.json create mode 100644 spec/fixtures/raw/9994933183506421.json diff --git a/spec/features/requests/requests_by_patron_group_spec.rb b/spec/features/requests/requests_by_patron_group_spec.rb index 3347830e1..d60792e95 100644 --- a/spec/features/requests/requests_by_patron_group_spec.rb +++ b/spec/features/requests/requests_by_patron_group_spec.rb @@ -4,18 +4,26 @@ RSpec.shared_examples "can request", vcr: { cassette_name: 'request_features', record: :none } do let(:mms_id) { '9994933183506421?mfhd=22558528920006421' } let(:user) { FactoryBot.create(:user) } + let(:username) { "netid123" } before do login_as user + stub_alma_holding_locations + stub_single_holding_location("recap$pa") + stub_availability_by_holding_id(bib_id:"9994933183506421", holding_id:"22558528920006421", body: true) + stub_delivery_locations end + #failure message: Failure/Error: expect(page).to have_content 'Electronic Delivery' + #Failed to lookup your library account + it "PUL ReCAP print item" do stub_catalog_raw(bib_id: '9994933183506421') stub_scsb_availability(bib_id: "9994933183506421", institution_id: "PUL", barcode: '32101095798938') scsb_url = "#{Requests::Config[:scsb_base]}/requestItem/requestItem" stub_request(:post, scsb_url) .with(body: hash_including(author: "", bibId: "9994933183506421", callNumber: "PJ7962.A5495 A95 2016", chapterTitle: "", deliveryLocation: "PA", emailAddress: 'a@b.com', endPage: "", issue: "", itemBarcodes: ["32101095798938"], itemOwningInstitution: "PUL", patronBarcode: "22101008199999", - requestNotes: "", requestType: "RETRIEVAL", requestingInstitution: "PUL", startPage: "", titleIdentifier: "ʻAwāṭif madfūnah عواطف مدفونة", username: "jstudent", volume: "")) + requestNotes: "", requestType: "RETRIEVAL", requestingInstitution: "PUL", startPage: "", titleIdentifier: "ʻAwāṭif madfūnah عواطف مدفونة", username: username, volume: "")) .to_return(status: 200, body: good_response, headers: {}) stub_request(:post, Requests::Config[:scsb_base]) .with(headers: { 'Accept' => '*/*' }) diff --git a/spec/fixtures/availability/by_holding_id/9994933183506421_22558528920006421.json b/spec/fixtures/availability/by_holding_id/9994933183506421_22558528920006421.json new file mode 100644 index 000000000..e4f0d961c --- /dev/null +++ b/spec/fixtures/availability/by_holding_id/9994933183506421_22558528920006421.json @@ -0,0 +1,22 @@ +[ +{ +"barcode": "32101095798938", +"id": "23558528910006421", +"holding_id": "22558528920006421", +"copy_number": "0", +"status": "Available", +"status_label": "Item in place", +"status_source": "base_status", +"process_type": null, +"on_reserve": "N", +"item_type": "Gen", +"pickup_location_id": "recap", +"pickup_location_code": "recap", +"location": "recap$pa", +"label": "ReCAP - Remote Storage", +"description": "", +"enum_display": "", +"chron_display": "", +"in_temp_library": false +} +] \ No newline at end of file diff --git a/spec/fixtures/raw/9994933183506421.json b/spec/fixtures/raw/9994933183506421.json new file mode 100644 index 000000000..b4968ffa7 --- /dev/null +++ b/spec/fixtures/raw/9994933183506421.json @@ -0,0 +1,129 @@ +{ +"id": "9994933183506421", +"numeric_id_b": true, +"author_display": [ +"Samḥān, Najāt", +"سمحان، نجاة،" +], +"author_citation_display": [ +"Samḥān, Najāt" +], +"author_roles_1display": "{\"secondary_authors\":[\"سمحان، نجاة،\"],\"translators\":[],\"editors\":[],\"compilers\":[],\"primary_author\":\"Samḥān, Najāt\"}", +"author_s": [ +"Samḥān, Najāt", +"سمحان، نجاة،" +], +"marc_relator_display": [ +"Author" +], +"title_display": "ʻAwāṭif madfūnah / Najāt al-Samḥān.", +"title_vern_display": "عواطف مدفونة / نجاة السمحان.", +"title_t": [ +"ʻAwāṭif madfūnah / Najāt al-Samḥān." +], +"title_citation_display": [ +"ʻAwāṭif madfūnah", +"عواطف مدفونة" +], +"compiled_created_t": [ +"ʻAwāṭif madfūnah / Najāt al-Samḥān.", +"عواطف مدفونة / نجاة السمحان." +], +"pub_created_vern_display": [ +"القاهرة : دار الكتاب الحديث، 2016." +], +"pub_created_display": [ +"al-Qāhirah : Dār al-Kitāb al-Ḥadīth, 2016.", +"القاهرة : دار الكتاب الحديث، 2016." +], +"pub_created_s": [ +"al-Qāhirah : Dār al-Kitāb al-Ḥadīth, 2016.", +"القاهرة : دار الكتاب الحديث، 2016." +], +"pub_citation_display": [ +"al-Qāhirah: Dār al-Kitāb al-Ḥadīth", +"القاهرة: دار الكتاب الحديث،" +], +"pub_date_display": [ +"2016" +], +"pub_date_start_sort": 2016, +"cataloged_tdt": "2016-01-19T00:00:00Z", +"format": [ +"Book" +], +"description_display": [ +"230 pages ; 20 cm" +], +"description_t": [ +"230 pages ; 20 cm" +], +"number_of_pages_citation_display": [ +"230 pages" +], +"notes_display": [ +"Short stories." +], +"language_name_display": [ +"Arabic" +], +"language_facet": [ +"Arabic" +], +"language_iana_s": [ +"ar" +], +"lc_subject_display": [ +"Short stories, Arabic—21st century" +], +"subject_facet": [ +"Short stories, Arabic—21st century" +], +"isbn_display": [ +"9789773506827", +"9773506827" +], +"isbn_s": [ +"9789773506827" +], +"oclc_s": [ +"932335821" +], +"other_version_s": [ +"9789773506827", +"ocn932335821" +], +"subject_era_facet": [ +"21st century" +], +"holdings_1display": "{\"22558528920006421\":{\"location_code\":\"recap$pa\",\"location\":\"Remote Storage\",\"library\":\"ReCAP\",\"call_number\":\"PJ7962.A5495 A95 2016\",\"call_number_browse\":\"PJ7962.A5495 A95 2016\",\"items\":[{\"holding_id\":\"22558528920006421\",\"id\":\"23558528910006421\",\"status_at_load\":\"1\",\"barcode\":\"32101095798938\",\"copy_number\":\"0\"}]}}", +"location_code_s": [ +"recap$pa" +], +"location": [ +"ReCAP" +], +"location_display": [ +"Remote Storage" +], +"advanced_location_s": [ +"recap$pa", +"ReCAP" +], +"name_title_browse_s": [ +"Samḥān, Najāt. ʻAwāṭif madfūnah", +"سمحان، نجاة،. عواطف مدفونة" +], +"call_number_display": [ +"PJ7962.A5495 A95 2016" +], +"call_number_browse_s": [ +"PJ7962.A5495 A95 2016" +], +"call_number_locator_display": [ +"PJ7962.A5495 A95 2016" +], +"hashed_id_ssi": "fd5824304556cdcc", +"_version_": 1773889407970967600, +"timestamp": "2023-08-11T00:12:48.249Z" +} \ No newline at end of file From 7891b7be70116411d82b21604816da4d6b7a5d77 Mon Sep 17 00:00:00 2001 From: Max Kadel Date: Fri, 23 Feb 2024 12:29:42 -0500 Subject: [PATCH 3/3] Stubbed patron response Co-authored-by: Carolyn Cole Co-authored-by: Christina Chortaria Co-authored-by: Jane Sandberg Co-authored-by: Kevin Reiss Co-authored-by: regineheberlein Co-authored-by: Ryan Laddusaw --- .../requests/requests_by_patron_group_spec.rb | 14 +++++++++----- spec/fixtures/bibdata/patron/faculty.json | 2 +- spec/fixtures/raw/9994933183506421.json | 5 +---- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/spec/features/requests/requests_by_patron_group_spec.rb b/spec/features/requests/requests_by_patron_group_spec.rb index d60792e95..eb9bcf248 100644 --- a/spec/features/requests/requests_by_patron_group_spec.rb +++ b/spec/features/requests/requests_by_patron_group_spec.rb @@ -6,18 +6,23 @@ let(:user) { FactoryBot.create(:user) } let(:username) { "netid123" } + # Make a decision (for this file) to use either stubs or VCR, not both + # Currently failing: + # @submission.service_errors + # [{:type=>"recap", :bibid=>"9994933183506421", :item=>["32101095798938"], :user_name=>"netid123", :barcode=>"22101000009999", :error=>"Request failed because Authentication Failed\n"}] + before do login_as user stub_alma_holding_locations stub_single_holding_location("recap$pa") stub_availability_by_holding_id(bib_id:"9994933183506421", holding_id:"22558528920006421", body: true) stub_delivery_locations + patron_record_uri = "#{Requests.config['bibdata_base']}/patron/#{user.uid}?ldap=true" + stub_request(:get, patron_record_uri) + .to_return(status: 200, body: patron_response, headers: {}) end - #failure message: Failure/Error: expect(page).to have_content 'Electronic Delivery' - #Failed to lookup your library account - - it "PUL ReCAP print item" do + it "PUL ReCAP print item", js: true do stub_catalog_raw(bib_id: '9994933183506421') stub_scsb_availability(bib_id: "9994933183506421", institution_id: "PUL", barcode: '32101095798938') scsb_url = "#{Requests::Config[:scsb_base]}/requestItem/requestItem" @@ -33,7 +38,6 @@ .to_return(status: 200, body: fixture("alma_hold_response.json"), headers: { 'content-type': 'application/json' }) visit "/requests/#{mms_id}" expect(page).to have_content 'Electronic Delivery' - # some weird issue with this and capybara examining the page source shows it is there. expect(page).to have_selector '#request_user_barcode', visible: :hidden choose('requestable__delivery_mode_23558528910006421_print') # chooses 'print' radio button select('Firestone Library', from: 'requestable__pick_up_23558528910006421') diff --git a/spec/fixtures/bibdata/patron/faculty.json b/spec/fixtures/bibdata/patron/faculty.json index 4feffcd3a..c98a919f2 100644 --- a/spec/fixtures/bibdata/patron/faculty.json +++ b/spec/fixtures/bibdata/patron/faculty.json @@ -2,7 +2,7 @@ "netid": "netid123", "first_name": "Faculty", "last_name": "Faculty", - "barcode": "1234567890", + "barcode": "22101000009999", "university_id": "1234", "patron_id": "5678", "patron_group": "staff", diff --git a/spec/fixtures/raw/9994933183506421.json b/spec/fixtures/raw/9994933183506421.json index b4968ffa7..1fb63d7d6 100644 --- a/spec/fixtures/raw/9994933183506421.json +++ b/spec/fixtures/raw/9994933183506421.json @@ -122,8 +122,5 @@ ], "call_number_locator_display": [ "PJ7962.A5495 A95 2016" -], -"hashed_id_ssi": "fd5824304556cdcc", -"_version_": 1773889407970967600, -"timestamp": "2023-08-11T00:12:48.249Z" +] } \ No newline at end of file