# typed: strict
# require "rails_helper"

# describe Domain::E621::CsvPostImporter do
#   let(:csv_row) do
#     {
#       "id" => 12_345,
#       "md5" => "1c6169aa51668681e9697a48144d7c78",
#       "updated_at" => "2023-08-24 07:35:09.171905",
#       "file_ext" => "jpg",
#       "description" => "a description",
#       "rating" => "s",
#       "score" => 67,
#       "up_score" => 69,
#       "down_score" => 2,
#       "fav_count" => 420,
#       "comment_count" => 1,
#       "change_seq" => 0,
#       "parent_id" => nil,
#       "is_deleted" => "f",
#       "is_pending" => "t",
#       "is_flagged" => "f",
#       "source" => "src1\nsrc2",
#       "tag_string" => "tag1 tag2",
#     }
#   end

#   it "imports new posts" do
#     expect do described_class.import_row(csv_row) end.to change(
#       Domain::E621::Post,
#       :count,
#     ).by(1)
#     post = Domain::E621::Post.find_by(e621_id: csv_row["id"])
#     expect(SpecUtil.enqueued_jobs(Domain::E621::Job::StaticFileJob)).to match(
#       [including(args: [{ post: post }])],
#     )

#     expect(post.md5).to eq(csv_row["md5"])
#     expect(post.file_url_str).to eq(
#       "https://static1.e621.net/data/1c/61/1c6169aa51668681e9697a48144d7c78.jpg",
#     )
#     expect(post.description).to eq(csv_row["description"])
#     expect(post.sources_array).to eq(%w[src1 src2])
#     expect(post.tags_array).to eq(%w[tag1 tag2])
#     expect(post.tags.map(&:name)).to match(%w[tag1 tag2])
#     expect(post.taggings.map(&:category).to_set).to eq(["general"].to_set)
#     expect(post.e621_updated_at).to eq(Time.parse "2023-08-24T07:35:09")
#   end

#   it "does not touch posts updated after the csv" do
#     post =
#       Domain::E621::Post.create!(
#         {
#           e621_id: csv_row["id"],
#           md5: csv_row["md5"],
#           tags_array: %w[tag3 tag4],
#         },
#       )
#     new_time = "2023-08-25T07:35:09-07:00"
#     post.e621_updated_at = new_time
#     post.save!

#     expect do described_class.import_row(csv_row) end.to_not change(
#       Domain::E621::Post,
#       :count,
#     )

#     post.reload
#     expect(post.e621_updated_at).to eq(Time.parse new_time)
#     expect(post.tags_array).to eq(%w[tag3 tag4])
#   end
# end
