Sha256: e2751b13d78ea5d6a636e1c608264aa432ee61693bd994f0bb0a0b64d86c7d6d

Contents?: true

Size: 1.95 KB

Versions: 1

Compression:

Stored size: 1.95 KB

Contents

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(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"]
      ]
      .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(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

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
celsius-primo-0.1.1 spec/celsius-primo/adapter_spec.rb