defmodule WhoNeedHelp.Workers.LocalRetryProbeTest do
  use ExUnit.Case, async: true
  use Oban.Testing, repo: WhoNeedHelp.Repo

  alias WhoNeedHelp.Workers.LocalRetryProbe

  @args %{
    "confirmation" => "isolated-local-resilience-probe",
    "run_id" => "unit-probe"
  }

  test "fails the first attempt and succeeds on retry" do
    assert {:error, :expected_first_attempt_failure} =
             perform_job(LocalRetryProbe, @args, attempt: 1)

    assert :ok = perform_job(LocalRetryProbe, @args, attempt: 2)
    assert 1 = LocalRetryProbe.backoff(%Oban.Job{attempt: 1})
  end

  test "cancels jobs without the local confirmation" do
    assert {:cancel, :invalid_local_resilience_probe} =
             perform_job(LocalRetryProbe, %{"run_id" => "unit-probe"}, attempt: 1)
  end
end
