Files
redux-scraper/spec/jobs/domain/fa/job/scan_fuzzysearch_job_spec.rb
2025-07-25 04:20:40 +00:00

172 lines
4.5 KiB
Ruby

# typed: false
require "rails_helper"
describe Domain::Fa::Job::ScanFuzzysearchJob do
let!(:log_entries) do
HttpClientMockHelpers.init_with(
[
{
uri:
"https://api-next.fuzzysearch.net/v1/file/furaffinity?search=#{fa_id}",
status_code:,
content_type: "application/json",
contents: File.read("test/fixtures/files/fuzzysearch/#{fa_id}.json"),
},
],
)
end
describe "post was marked removed" do
let(:post) do
create(
:domain_post_fa_post,
state: "removed",
keywords: nil,
fa_id: fa_id,
)
end
context "and fuzzysearch has post info" do
let(:fa_id) { 51_015_903 }
let(:status_code) { 200 }
it "updates the post" do
perform_now({ post: })
post.reload
expect(post.fuzzysearch_checked_at).to be_present
expect(post.fuzzysearch_entry).to be_present
expect(post.fuzzysearch_json).to be_present
end
it "sets tags" do
perform_now({ post: })
post.reload
expect(post.keywords).to eq(%w[some_tag another_tag])
end
it "sets file" do
perform_now({ post: })
post.reload
expect(post.file).to be_present
expect(post.file.url_str).to eq(
"https://d.furaffinity.net/art/crimetxt/1676417528/1676417528.crimetxt_2023-02-15_00_18_48.png",
)
end
it "sets the creator" do
perform_now({ post: })
post.reload
expect(post.creator).to be_present
expect(post.creator.url_name).to eq("crimetxt")
end
it "sets the file sha256" do
perform_now({ post: })
post.reload
expect(post.fuzzysearch_json["sha256"]).to eq(
"d488dabd8eb22398a228fb662eb520bb4daaac3a9ab0dc9be8b8c5e1b9522efb",
)
end
it "enqueues a fur archiver post file job" do
perform_now({ post: })
post.reload
job_args = SpecUtil.enqueued_job_args(Job::FaPostFurArchiverPostFileJob)
expect(job_args).to match(
[{ post_file: post.file, caused_by_entry: post.fuzzysearch_entry }],
)
end
context "the post file is already downloaded" do
before do
post.file = create(:domain_post_file, :has_file)
post.save!
end
it "does not enqueue a fur archiver post file job" do
perform_now({ post: })
post.reload
job_args =
SpecUtil.enqueued_job_args(Job::FaPostFurArchiverPostFileJob)
expect(job_args).to be_empty
end
end
end
context "and fuzzysearch has no post info" do
let(:fa_id) { 21_275_696 }
let(:status_code) { 200 }
it "does not set the creator" do
perform_now({ post: })
post.reload
expect(post.creator).to be_nil
end
it "does not create a file" do
perform_now({ post: })
post.reload
expect(post.file).to be_nil
end
end
context "and the artist name has capitalizations" do
let(:fa_id) { 53_068_507 }
let(:status_code) { 200 }
it "sets the creator" do
perform_now({ post: })
post.reload
expect(post.creator).to be_present
expect(post.creator.url_name).to eq("meesh")
expect(post.creator.name).to eq("Meesh")
expect(post.creator.full_name).to eq("Meesh")
end
end
context "and the post has a story url" do
let(:fa_id) { 61_665_194 }
let(:status_code) { 200 }
it "does not change the post state" do
perform_now({ post: })
post.reload
expect(post.state).to eq("removed")
end
it "sets the artist" do
perform_now({ post: })
post.reload
expect(post.creator).to be_present
expect(post.creator.url_name).to eq("irontankris")
end
it "updates keywords" do
post.keywords = []
post.save!
perform_now({ post: })
post.reload
expect(post.keywords).to include("female", "mlp", "little", "anthro")
end
end
context "the post has no sha256" do
let(:fa_id) { 61_429_615 }
let(:status_code) { 200 }
it "sets the artist" do
perform_now({ post: })
post.reload
expect(post.creator).to be_present
expect(post.creator.url_name).to eq("622000")
end
it "does not set the sha256" do
perform_now({ post: })
post.reload
expect(post.fuzzysearch_json["sha256"]).to be_nil
end
end
end
end