defmodule Geolix.Adapter.MMDB2.ResultTest do
  use ExUnit.Case, async: true

  alias Geolix.Adapter.MMDB2.Result

  defp result_for(type), do: Result.to_struct(type, %{}, nil).__struct__

  test "unknown type is unmodified" do
    data = %{foo: :bar}

    assert data == Result.to_struct("invalid-type", data, nil)
  end

  test "type to struct mapping" do
    assert Result.City == result_for("GeoIP2-City")
    assert Result.City == result_for("GeoLite2-City")
    assert Result.Country == result_for("GeoIP2-Country")
    assert Result.Country == result_for("GeoLite2-Country")
  end

  test "type to flat struct mapping" do
    assert Result.AnonymousIP == result_for("GeoIP2-Anonymous-IP")
    assert Result.ConnectionType == result_for("GeoIP2-Connection-Type")
    assert Result.Domain == result_for("GeoIP2-Domain")
    assert Result.ISP == result_for("GeoIP2-ISP")
  end
end

defmodule Geolix.Adapter.MMDB2.ResultTest do
  use ExUnit.Case, async: true

  alias Geolix.Adapter.MMDB2.Result

  test "unknown type is unmodified" do
    assert %{foo: :bar} = Result.to_struct("invalid-type", %{foo: :bar}, nil)
  end

  test "type to struct mapping" do
    assert %Result.City{} = Result.to_struct("GeoIP2-City", %{}, nil)
    assert %Result.City{} = Result.to_struct("GeoLite2-City", %{}, nil)
    assert %Result.Country{} = Result.to_struct("GeoIP2-Country", %{}, nil)
    assert %Result.Country{} = Result.to_struct("GeoLite2-Country", %{}, nil)
  end

  test "type to flat struct mapping" do
    assert %Result.AnonymousIP{} = Result.to_struct("GeoIP2-Anonymous-IP", %{}, nil)
    assert %Result.ConnectionType{} = Result.to_struct("GeoIP2-Connection-Type", %{}, nil)
    assert %Result.Domain{} = Result.to_struct("GeoIP2-Domain", %{}, nil)
    assert %Result.ISP{} = Result.to_struct("GeoIP2-ISP", %{}, nil)
  end
end

Clean up result struct conversion test
Clean up result struct conversion test

elixir-geolix/adapter_mmdb2,elixir-geolix/adapter_mmdb2