require "test_helper"
require "gds_api/test_helpers/link_checker_api"

class LinkCheckerApiReportTest < ActiveSupport::TestCase
  include GdsApi::TestHelpers::LinkCheckerApi

  test "replaces a batch report if it already exists" do
    link = "http://www.example.com"
    publication = create(:publication, body: "[link](#{link})")

    batch_id = 5

    report_payload = link_checker_api_batch_report_hash(
      id: batch_id,
      links: [{ uri: link }],
      status: "completed",
    ).with_indifferent_access

    LinkCheckerApiReport.create!(
      batch_id: batch_id,
      link_reportable: publication,
      status: "in_progress",
    )

    LinkCheckerApiReport.create_from_batch_report(report_payload, publication)

    report = LinkCheckerApiReport.find_by(batch_id: batch_id)
    assert_equal "completed", report.status
  end
end

Add a test for replacing link checker api reports
Add a test for replacing link checker api reports
