diff --git a/.env.test b/.env.test index 90ff698a..46e4faa8 100644 --- a/.env.test +++ b/.env.test @@ -16,3 +16,5 @@ BOOTSNAP_CACHE_DIR=./tmp # turn of functionality during FOLIO update FOLIO_UPDATE_IN_PROGRESS= + +CATALOGUE_SERVICES_API_BASE_URL=http://catservices.test diff --git a/app/models/solr_document.rb b/app/models/solr_document.rb index 2c5760b4..3951cc1a 100644 --- a/app/models/solr_document.rb +++ b/app/models/solr_document.rb @@ -98,8 +98,8 @@ def wrap_in_paragraph(value) def availability_status holdings, item = CatalogueServicesClient.new.get_item_ids(instance_id: self["folio_instance_id_ssi"]) - p "solrdoc" - pp [holdings, item] + Rails.logger.debug "solrdoc" + Rails.logger.debug [holdings, item] CatalogueServicesClient.new.get_requestable(instance_id: self["folio_instance_id_ssi"], holdings_id: holdings, item_id: item) end diff --git a/app/services/catalogue_services_client.rb b/app/services/catalogue_services_client.rb index 3bb07889..59493718 100644 --- a/app/services/catalogue_services_client.rb +++ b/app/services/catalogue_services_client.rb @@ -60,8 +60,8 @@ def get_item_ids(instance_id:) item_id = all_holdings.first["itemRecords"].first["holdingsRecordId"] if all_holdings.first["itemRecords"].any? holding_id = all_holdings.first["itemRecords"].first["id"] if all_holdings.first["itemRecords"].any? - p "catservices" - pp [item_id, holding_id] + Rails.logger.debug "catservices" + Rails.logger.debug [item_id, holding_id] [item_id, holding_id] end diff --git a/config/initializers/faraday.rb b/config/initializers/faraday.rb new file mode 100644 index 00000000..f207835a --- /dev/null +++ b/config/initializers/faraday.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +require "faraday" + +# Make sure Faraday requests include a non-default User-Agent, since it will break the specs +# every time Faraday is upgraded. +Faraday.default_connection_options = {headers: {user_agent: "nla-arclight/#{Rails.configuration.version}"}} diff --git a/spec/features/document_component_spec.rb b/spec/features/document_component_spec.rb index 595f73a4..ab0f7142 100644 --- a/spec/features/document_component_spec.rb +++ b/spec/features/document_component_spec.rb @@ -13,6 +13,11 @@ } ) .to_return(status: 200, body: solr_response, headers: {}) + + cat_response = IO.read("spec/files/catalogue_services/08aed703-3648-54d0-80ef-fddb3c635731.json") + + WebMock.stub_request(:get, /catalogue-services\/folio\/instance\/(.*)/) + .to_return(status: 200, body: cat_response, headers: {"Content-Type" => "application/json"}) end it "has correct tab title, including the collection prefix" do diff --git a/spec/services/catalogue_services_client_spec.rb b/spec/services/catalogue_services_client_spec.rb index ff3edc4e..5d3bbaa7 100644 --- a/spec/services/catalogue_services_client_spec.rb +++ b/spec/services/catalogue_services_client_spec.rb @@ -6,31 +6,20 @@ subject(:service) { described_class.new } describe "#get_holdings" do + before do + cat_response = IO.read("spec/files/catalogue_services/08aed703-3648-54d0-80ef-fddb3c635731.json") + WebMock.stub_request(:get, /catservices.test\/catalogue-services\/folio\/instance\/08aed703-3648-54d0-80ef-fddb3c635731/) + .to_return(status: 200, body: cat_response, headers: {"Content-Type" => "application/json"}) + end + it "returns holdings records" do - pp service.get_holdings(instance_id: "08aed703-3648-54d0-80ef-fddb3c635731") expect(service.get_holdings(instance_id: "08aed703-3648-54d0-80ef-fddb3c635731").size).to eq 5 end - end - - # WebMock.stub_request(:get, "http://catservices.test/catalogue-services/folio/instance/6bf69425-293d-5e3f-a050-16124aca9a4e"). - # with( - # headers: { - # 'Accept'=>'*/*', - # 'Accept-Encoding'=>'gzip;q=1.0,deflate;q=0.6,identity;q=0.3', - # }). - # to_return(status: 200, body: "", headers: {}) - describe "#get_holdings" do context "when unable to request holdings" do it "raises a ItemRequestError" do - WebMock.stub_request(:get, "http://catservices.test/catalogue-services/folio/instance/08aed703-3648-54d0-80ef-fddb3c635731") - .with( - headers: { - "Accept" => "*/*", - "Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3" - } - ) - .to_return(status: 401, body: "", headers: {}) + WebMock.stub_request(:get, /catservices.test\/catalogue-services\/folio\/instance\/08aed703-3648-54d0-80ef-fddb3c635731/) + .to_return(status: 401, body: "", headers: {"Content-Type" => "application/json"}) expect { service.get_holdings(instance_id: "08aed703-3648-54d0-80ef-fddb3c635731") }.to raise_error(HoldingsRequestError) end @@ -38,34 +27,11 @@ context "when requesting holdings records" do it "returns holdings records" do - # ________________from file - cat_response = IO.read("spec/files/catalogue_services/08aed703-3648-54d0-80ef-fddb3c635731.json") - WebMock.stub_request(:get, "http://catservices.test/catalogue-services/folio/instance/08aed703-3648-54d0-80ef-fddb3c635731") - .with( - headers: { - "Accept" => "*/*", - "Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3" - } - ) - .to_return(status: 200, body: cat_response, headers: {}) - - # ________________empty stub - # WebMock.stub_request(:get, "http://catservices.test/catalogue-services/folio/instance/08aed703-3648-54d0-80ef-fddb3c635731") - # .with( - # headers: { - # "Accept" => "*/*", - # "Accept-Encoding" => "gzip;q=1.0,deflate;q=0.6,identity;q=0.3" - # } - # ) - # .to_return(status: 200, body: "", headers: {}) - - pp service.get_holdings(instance_id: "08aed703-3648-54d0-80ef-fddb3c635731") expect(service.get_holdings(instance_id: "08aed703-3648-54d0-80ef-fddb3c635731").size).to eq 5 end end end - # describe "#get_holdings" do # it "returns holdings records" do # pp service.get_holdings(instance_id: "6bf69425-293d-5e3f-a050-16124aca9a4e")