describe Celsius::Primo::Adapter do let(:adapter_options) do { institution: "PAD", languages: [ "ger", "eng" ], locations:[ { type: "local", value: "scope:(PAD_ALEPH)" } ], soap_api_options: { searcher_url: "http://primo.kobv.de/primo_library/libweb/webservices/services/searcher" } } end let(:adapter) do described_class.new(adapter_options) end describe "#mget" do it "returns a normalzed mget result", :vcr do mget_request = YAML.load(read_asset("adapter/mget/mget_request.yml")) expected_mget_result = YAML.load(read_asset("adapter/mget/mget_result.yml")) expect(mget_result = adapter.mget(mget_request)).to eq(expected_mget_result) end end describe "#search" do asset_dir = "adapter/search" it "returns a normalized search result", :vcr do [ ["#{asset_dir}/search_request.yml", "#{asset_dir}/search_result.yml"], ["#{asset_dir}/search_request_with_empty_result.yml", "#{asset_dir}/empty_search_result.yml"], ["#{asset_dir}/search_request_for_multiple_publishers.yml", "#{asset_dir}/search_result_with_multiple_publishers.yml"] ] .each do |search_request_yaml_filename, search_response_yaml_filename| search_request = YAML.load(read_asset(search_request_yaml_filename)) expected_search_result = YAML.load(read_asset(search_response_yaml_filename)) expect(search_result = adapter.search(search_request)).to eq(expected_search_result) end end context "if a the adapter specifies a timeout" do context "if the server does not respond within this timeout" do let(:timeout) { 0.1 } # decimals can be used the specifiy milliseconds it "raises an Timeout::Error" do require "timeout" allow(HTTPI).to receive(:post) { sleep(timeout * 2) } search_request = YAML.load(read_asset("adapter/search/search_request.yml")) expect { adapter.search(search_request, timeout: timeout) }.to raise_error(Timeout::Error) end end end end end