95 lines
2.6 KiB
Ruby
95 lines
2.6 KiB
Ruby
# typed: false
|
|
require "rails_helper"
|
|
|
|
describe Domain::Fa::Job::UserPageJob do
|
|
let(:http_client_mock) { instance_double("::Scraper::HttpClient") }
|
|
before do
|
|
Scraper::ClientFactory.http_client_mock = http_client_mock
|
|
@log_entries =
|
|
HttpClientMockHelpers.init_http_client_mock(
|
|
http_client_mock,
|
|
client_mock_config,
|
|
)
|
|
end
|
|
|
|
context "scanning a normal user" do
|
|
let(:client_mock_config) do
|
|
[
|
|
{
|
|
uri: "https://www.furaffinity.net/user/meesh/",
|
|
status_code: 200,
|
|
content_type: "text/html",
|
|
contents:
|
|
SpecUtil.read_fixture_file("domain/fa/job/user_page_meesh.html"),
|
|
},
|
|
]
|
|
end
|
|
|
|
it "succeeds" do
|
|
perform_now({ url_name: "meesh" })
|
|
user = Domain::User::FaUser.find_by(url_name: "meesh")
|
|
expect(user).to_not be_nil
|
|
avatar = user.avatar
|
|
expect(avatar).to_not be_nil
|
|
expect(avatar.url_str).to eq(
|
|
"https://a.furaffinity.net/1635789297/meesh.gif",
|
|
)
|
|
expect(avatar.state).to eq("pending")
|
|
expect(
|
|
SpecUtil.enqueued_job_args(Domain::Fa::Job::UserAvatarJob),
|
|
).to match([{ avatar: avatar, caused_by_entry: @log_entries[0] }])
|
|
end
|
|
end
|
|
|
|
context "with a user with buggy favcount" do
|
|
let(:client_mock_config) do
|
|
[
|
|
{
|
|
uri: "https://www.furaffinity.net/user/marsdust/",
|
|
status_code: 200,
|
|
content_type: "text/html",
|
|
contents:
|
|
SpecUtil.read_fixture_file("domain/fa/job/user_page_marsdust.html"),
|
|
},
|
|
]
|
|
end
|
|
|
|
it "records the right fav count" do
|
|
perform_now({ url_name: "marsdust" })
|
|
user = Domain::User::FaUser.find_by(url_name: "marsdust")
|
|
expect(user).to_not be_nil
|
|
expect(user.avatar.url_str).to eq(
|
|
"https://a.furaffinity.net/1424255659/marsdust.gif",
|
|
)
|
|
expect(user.num_favorites).to eq(0)
|
|
end
|
|
end
|
|
|
|
context "user with page that links to unseen users" do
|
|
let(:client_mock_config) do
|
|
[
|
|
{
|
|
uri: "https://www.furaffinity.net/user/angelpawqt/",
|
|
status_code: 200,
|
|
content_type: "text/html",
|
|
contents:
|
|
SpecUtil.read_fixture_file(
|
|
"domain/fa/user_page/user_page_angelpawqt.html",
|
|
),
|
|
},
|
|
]
|
|
end
|
|
|
|
it "enqueues jobs for the unseen users" do
|
|
perform_now({ url_name: "angelpawqt", skip_enqueue_found_links: false })
|
|
expect(
|
|
SpecUtil.enqueued_job_args(Domain::Fa::Job::UserPageJob),
|
|
).to include(
|
|
hash_including(
|
|
user: Domain::User::FaUser.find_by(url_name: "8bitstarshon1"),
|
|
),
|
|
)
|
|
end
|
|
end
|
|
end
|