# frozen_string_literal: true
# This file is part of Alexandria.
#
# See the file README.md for authorship and licensing information.
require "spec_helper"
RSpec.describe Alexandria::BookProviders::WorldCatProvider do
let(:sky_catalog_main) do
<<~XHTML
XHTML
end
let(:sky_catalog_details) do
<<~XHTML
Sky catalogue 2000.0 ed. by Alan Hirshfeld and Roger W. Sinnott
XHTML
end
let(:florence_ru_details) do
<<~XHTML
Флоренс Аравийская : роман /
Florens Araviĭskai︠a︡ : roman
XHTML
end
it "works for an isbn with multiple results" do
stub_request(:get, "https://www.worldcat.org/search?q=isbn:9780521247108&qt=advanced")
.to_return(status: 200, body: +sky_catalog_main, headers: {})
stub_request(:get,
"https://www.worldcat.org/title/" \
"sky-catalogue-20000-ed-by-alan-hirshfeld-and-roger-w-sinnott" \
"/oclc/476534140&referer=brief_results")
.to_return(status: 200, body: +sky_catalog_details, headers: {})
assert_correct_search_result(described_class, "9780521247108")
end
it "works with vernacular" do
stub_request(:get, "https://www.worldcat.org/search?q=isbn:9785941454136&qt=advanced")
.to_return(status: 200, body: +florence_ru_details, headers: {})
assert_correct_search_result(described_class, "9785941454136")
end
it "works with multiple authors" do
stub_request(:get, "https://www.worldcat.org/search?q=isbn:9785941454136&qt=advanced")
.to_return(status: 200, body: +florence_ru_details, headers: {})
results = assert_correct_search_result(described_class,
"9785941454136")
this_book = results.first
expect(this_book.authors).to be_instance_of(Array), "Not an array!"
expect(this_book.authors.length).to eq(2), "Wrong number of authors for this book!"
end
end