defmodule Towerops.JobMonitoring.EventsTest do
  use Towerops.DataCase, async: true

  alias Towerops.JobMonitoring.Events

  describe "broadcast_job_event/3" do
    test "broadcasts job lifecycle event to PubSub" do
      Phoenix.PubSub.subscribe(Towerops.PubSub, "job:lifecycle")

      job = %Oban.Job{
        id: 123,
        worker: "Towerops.Workers.DevicePollerWorker",
        args: %{"device_id" => 456}
      }

      Events.broadcast_job_event(job, :started, %{})

      assert_receive %{
        job_id: 123,
        worker: "Towerops.Workers.DevicePollerWorker",
        device_id: 456,
        event: :started,
        metadata: %{},
        timestamp: %DateTime{}
      }
    end
  end
end
