Skip to content

Commit

Permalink
test: fix specs
Browse files Browse the repository at this point in the history
  • Loading branch information
yetti committed Jun 17, 2024
1 parent c851ffd commit 7241f9c
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 46 deletions.
2 changes: 2 additions & 0 deletions .env.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions app/models/solr_document.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions app/services/catalogue_services_client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
7 changes: 7 additions & 0 deletions config/initializers/faraday.rb
Original file line number Diff line number Diff line change
@@ -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}"}}
5 changes: 5 additions & 0 deletions spec/features/document_component_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
50 changes: 8 additions & 42 deletions spec/services/catalogue_services_client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,66 +6,32 @@
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
end

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")
Expand Down

0 comments on commit 7241f9c

Please sign in to comment.