normalize fa cdn hosts to avoid redownloading files
This commit is contained in:
@@ -219,4 +219,81 @@ describe Domain::Fa::Job::ScanPostJob do
|
||||
expect(post.state).to eq("removed")
|
||||
end
|
||||
end
|
||||
|
||||
describe "#uri_same_with_normalized_facdn_host?" do
|
||||
let(:client_mock_config) { [] }
|
||||
|
||||
shared_examples "has result" do |result|
|
||||
it "is #{result.to_s}, both have schema" do
|
||||
url1 = "https://#{host1}#{path1}"
|
||||
url2 = "https://#{host2}#{path2}"
|
||||
expect(
|
||||
described_class.uri_same_with_normalized_facdn_host?(url1, url2),
|
||||
).to eq(result)
|
||||
end
|
||||
|
||||
it "is #{result.to_s}, both missing schema" do
|
||||
url1 = "//#{host1}#{path1}"
|
||||
url2 = "//#{host2}#{path2}"
|
||||
expect(
|
||||
described_class.uri_same_with_normalized_facdn_host?(url1, url2),
|
||||
).to eq(result)
|
||||
end
|
||||
|
||||
it "is #{result.to_s}, one has schema" do
|
||||
url1 = "https://#{host1}#{path1}"
|
||||
url2 = "//#{host2}#{path2}"
|
||||
expect(
|
||||
described_class.uri_same_with_normalized_facdn_host?(url1, url2),
|
||||
).to eq(result)
|
||||
end
|
||||
end
|
||||
|
||||
shared_context "host: different cdn hosts" do
|
||||
let(:host1) { "d.facdn.net" }
|
||||
let(:host2) { "d.furaffinity.net" }
|
||||
end
|
||||
|
||||
shared_context "host: both hosts are d.facdn.net" do
|
||||
let(:host1) { "d.facdn.net" }
|
||||
let(:host2) { "d.facdn.net" }
|
||||
end
|
||||
|
||||
shared_context "host: both hosts are d.furaffinity.net" do
|
||||
let(:host1) { "d.furaffinity.net" }
|
||||
let(:host2) { "d.furaffinity.net" }
|
||||
end
|
||||
|
||||
shared_context "host: one domain is not a cdn" do
|
||||
let(:host1) { "d.facdn.net" }
|
||||
let(:host2) { "example.com" }
|
||||
end
|
||||
|
||||
shared_context "paths: are the same" do
|
||||
let(:path1) { "/art/user/1234567890/image.jpg" }
|
||||
let(:path2) { "/art/user/1234567890/image.jpg" }
|
||||
end
|
||||
|
||||
shared_context "paths: are different" do
|
||||
let(:path1) { "/art/user/1234567890/image.jpg" }
|
||||
let(:path2) { "/art/user/1234567890/some_other_image.jpg" }
|
||||
end
|
||||
|
||||
[
|
||||
["host: different cdn hosts", "paths: are the same", true],
|
||||
["host: both hosts are d.facdn.net", "paths: are the same", true],
|
||||
["host: both hosts are d.furaffinity.net", "paths: are the same", true],
|
||||
["host: one domain is not a cdn", "paths: are the same", false],
|
||||
["host: different cdn hosts", "paths: are different", false],
|
||||
["host: both hosts are d.facdn.net", "paths: are different", false],
|
||||
["host: both hosts are d.furaffinity.net", "paths: are different", false],
|
||||
["host: one domain is not a cdn", "paths: are different", false],
|
||||
].each do |host_context, path_context, result|
|
||||
context "#{host_context} and #{path_context}" do
|
||||
include_context host_context
|
||||
include_context path_context
|
||||
include_examples "has result", result
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user