defmodule Towerops.Accounts.HIBPTest do
  use ExUnit.Case, async: true

  alias Towerops.Accounts.HIBP

  describe "check_password/1 with non-binary input" do
    test "returns {:ok, :unknown} for nil" do
      assert {:ok, :unknown} = HIBP.check_password(nil)
    end

    test "returns {:ok, :unknown} for empty string" do
      assert {:ok, :unknown} = HIBP.check_password("")
    end

    test "returns {:ok, :unknown} for integer" do
      assert {:ok, :unknown} = HIBP.check_password(123)
    end

    test "returns {:ok, :unknown} for list" do
      assert {:ok, :unknown} = HIBP.check_password([])
    end

    test "returns {:ok, :unknown} for atom" do
      assert {:ok, :unknown} = HIBP.check_password(:foo)
    end
  end

  describe "check_password/1 with real API" do
    @tag :integration
    test "finds commonly breached password" do
      assert {:ok, count} = HIBP.check_password("password")
      assert is_integer(count)
      assert count > 0
    end

    @tag :integration
    test "returns 0 for likely-unique password" do
      unique = Base.encode64(:crypto.strong_rand_bytes(32))
      assert {:ok, 0} = HIBP.check_password(unique)
    end
  end
end
