Files
redux-scraper/spec/lib/scraper/sofurry_http_client_config_spec.rb
Dylan Knutson 572c61cebb add proxies
2025-07-23 04:51:44 +00:00

61 lines
1.6 KiB
Ruby

# typed: false
require "rails_helper"
RSpec.describe Scraper::SofurryHttpClientConfig do
subject(:config) { described_class.new }
describe "#map_response" do
let(:base_response_attrs) do
{
response_code: 200,
response_time_ms: 100,
body: "body",
performed_by: "direct",
}
end
context "with a response from an API host" do
let(:response) do
Scraper::CurlHttpPerformer::Response.new(
base_response_attrs.merge(
uri:
Addressable::URI.parse("https://api.sofurry.com/v2/submission"),
response_headers: {
"X-Some-Header" => "some-value",
},
),
)
end
it "adds the application/json content type" do
mapped_response = config.map_response(response)
expect(mapped_response.response_headers).to include(
"Content-Type" => "application/json",
"X-Some-Header" => "some-value",
)
end
end
context "with a response from a non-API host" do
let(:response) do
Scraper::CurlHttpPerformer::Response.new(
base_response_attrs.merge(
uri: Addressable::URI.parse("https://www.sofurry.com/browse"),
response_headers: {
"Content-Type" => "text/html",
},
),
)
end
it "does not modify the response" do
mapped_response = config.map_response(response)
expect(mapped_response).to be(response)
expect(mapped_response.response_headers).to eq(
"Content-Type" => "text/html",
)
end
end
end
end