122 lines
3.5 KiB
Ruby
122 lines
3.5 KiB
Ruby
# typed: false
|
|
require "rails_helper"
|
|
|
|
describe FaBackfillFavs do
|
|
let(:backfiller) { FaBackfillFavs.new }
|
|
|
|
let(:iiszed_html) do
|
|
File.read("test/fixtures/files/domain/fa/favs_backfill/iiszed_1.html")
|
|
end
|
|
let(:renamonzeo_html) do
|
|
File.read("test/fixtures/files/domain/fa/favs_backfill/renamonzeo_1.html")
|
|
end
|
|
let(:stickiest_html) do
|
|
File.read("test/fixtures/files/domain/fa/favs_backfill/stickiest_1.html")
|
|
end
|
|
|
|
let!(:iiszed_user) do
|
|
Domain::Fa::User.create!(url_name: "iiszed", name: "I_Is_Zed")
|
|
end
|
|
let!(:renamonzeo_user) do
|
|
Domain::Fa::User.create!(url_name: "renamonzeo", name: "Renamonzeo")
|
|
end
|
|
let!(:stickiest_user) do
|
|
Domain::Fa::User.create!(url_name: "stickiest", name: "stickiest")
|
|
end
|
|
|
|
before do
|
|
# Create all posts found in the HTML
|
|
[iiszed_html, renamonzeo_html, stickiest_html].each do |html|
|
|
page = Domain::Fa::Parser::Page.new(html)
|
|
submissions = page.submissions_parsed
|
|
submissions.each do |submission|
|
|
Domain::Fa::Post.find_or_initialize_by_submission_parser(
|
|
submission,
|
|
).save!
|
|
end
|
|
end
|
|
|
|
# Create empty headers record for reuse
|
|
empty_headers = HttpLogEntryHeader.find_or_create(headers: {})
|
|
|
|
# Create HttpLogEntry records for each user's favorites page
|
|
HttpLogEntry.create!(
|
|
uri_host: "www.furaffinity.net",
|
|
uri_path: "/favorites/iiszed/1183854116/next",
|
|
uri_scheme: "https",
|
|
verb: :get,
|
|
performed_by: "direct",
|
|
status_code: 200,
|
|
response_time_ms: 100,
|
|
content_type: "text/html",
|
|
requested_at: Time.current,
|
|
request_headers: empty_headers,
|
|
response_headers: empty_headers,
|
|
response: create(:blob_file, contents: iiszed_html),
|
|
)
|
|
|
|
HttpLogEntry.create!(
|
|
uri_host: "www.furaffinity.net",
|
|
uri_path: "/favorites/renamonzeo",
|
|
uri_scheme: "https",
|
|
verb: :get,
|
|
performed_by: "direct",
|
|
status_code: 200,
|
|
response_time_ms: 100,
|
|
content_type: "text/html",
|
|
requested_at: Time.current,
|
|
request_headers: empty_headers,
|
|
response_headers: empty_headers,
|
|
response: create(:blob_file, contents: renamonzeo_html),
|
|
)
|
|
|
|
HttpLogEntry.create!(
|
|
uri_host: "www.furaffinity.net",
|
|
uri_path: "/favorites/stickiest",
|
|
uri_scheme: "https",
|
|
verb: :get,
|
|
performed_by: "direct",
|
|
status_code: 200,
|
|
response_time_ms: 100,
|
|
content_type: "text/html",
|
|
requested_at: Time.current,
|
|
request_headers: empty_headers,
|
|
response_headers: empty_headers,
|
|
response: create(:blob_file, contents: stickiest_html),
|
|
)
|
|
end
|
|
|
|
it "processes favorites from log entries" do
|
|
backfiller.run
|
|
|
|
expect(
|
|
Domain::Fa::Fav.where(
|
|
user: iiszed_user,
|
|
post: Domain::Fa::Post.find_by!(fa_id: 48_999_001),
|
|
),
|
|
).not_to be_empty
|
|
|
|
expect(
|
|
Domain::Fa::Fav.where(
|
|
user: iiszed_user,
|
|
post: Domain::Fa::Post.find_by!(fa_id: 48_996_138),
|
|
),
|
|
).not_to be_empty
|
|
|
|
expect(
|
|
Domain::Fa::Fav.where(
|
|
user: iiszed_user,
|
|
post: Domain::Fa::Post.find_by!(fa_id: 48_993_021),
|
|
),
|
|
).not_to be_empty
|
|
|
|
# Check total number of favorites for iiszed
|
|
expect(Domain::Fa::Fav.where(user: iiszed_user).count).to eq(48) # Total number of figures in the HTML
|
|
|
|
expect(Domain::Fa::Fav.where(user: renamonzeo_user).count).to eq(48) # Total number of figures in the HTML
|
|
|
|
# Verify no posts were created for stickiest (empty favorites page)
|
|
expect(Domain::Fa::Fav.where(user: stickiest_user).count).to eq(0)
|
|
end
|
|
end
|