defmodule Aprsme.Is.IsSupervisorTest do
  use ExUnit.Case, async: false

  alias Aprsme.Is.IsSupervisor

  describe "init/1" do
    test "returns a supervisor spec with Aprsme.Is as a child" do
      # init/1 returns the {:ok, sup_flags, child_specs} tuple wrapped via
      # Supervisor.init/2 — the safest assertion is that the return type is
      # a valid supervisor init result.
      assert {:ok, {_sup_flags, child_specs}} = IsSupervisor.init(:ok)
      assert match?([_ | _], child_specs)
      assert Enum.any?(child_specs, fn spec -> spec.id == Aprsme.Is end)
    end
  end

  describe "start_link/1" do
    test "the supervisor module exists and is callable" do
      # We can't actually start the supervisor because Aprsme.Is.init/1 stops
      # itself in the test environment via :test_environment_disabled.
      # Verify init/1 returns the expected supervisor spec.
      assert {:ok, {_sup_flags, child_specs}} = IsSupervisor.init(:ok)
      assert Enum.any?(child_specs, fn spec -> spec.id == Aprsme.Is end)
    end
  end
end
