2020-01-26 19:34:25 +00:00
|
|
|
defmodule Mobilizon.GraphQL.Resolvers.AddressTest do
|
2020-01-26 20:36:50 +00:00
|
|
|
use Mobilizon.Web.ConnCase
|
2020-01-26 19:34:25 +00:00
|
|
|
|
2019-03-14 17:31:14 +00:00
|
|
|
import Mobilizon.Factory
|
|
|
|
|
2020-01-26 19:34:25 +00:00
|
|
|
alias Mobilizon.GraphQL.AbsintheHelpers
|
|
|
|
|
2019-03-14 17:31:14 +00:00
|
|
|
describe "Address Resolver" do
|
|
|
|
test "search/3 search for addresses", %{conn: conn} do
|
|
|
|
address = insert(:address, description: "10 rue Jangot, Lyon")
|
|
|
|
|
|
|
|
query = """
|
|
|
|
{
|
|
|
|
searchAddress(query: "10 Rue Jangot") {
|
2019-03-22 14:51:23 +00:00
|
|
|
street,
|
2019-03-14 17:31:14 +00:00
|
|
|
description,
|
|
|
|
geom
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> get("/api", AbsintheHelpers.query_skeleton(query, "address"))
|
|
|
|
|
|
|
|
json_response(res, 200)["data"]["searchAddress"]
|
|
|
|
|> Enum.each(fn addr -> assert Map.get(addr, "description") == address.description end)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "geocode/3 reverse geocodes coordinates", %{conn: conn} do
|
|
|
|
query = """
|
|
|
|
{
|
|
|
|
reverseGeocode(longitude: -23.01, latitude: 30.01) {
|
|
|
|
description,
|
|
|
|
geom
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> get("/api", AbsintheHelpers.query_skeleton(query, "address"))
|
|
|
|
|
2019-11-08 18:37:14 +00:00
|
|
|
assert json_response(res, 200)["data"]["reverseGeocode"] |> hd |> Map.get("description") ==
|
|
|
|
"Anywhere"
|
2019-03-14 17:31:14 +00:00
|
|
|
|
|
|
|
query = """
|
|
|
|
{
|
|
|
|
reverseGeocode(longitude: 45.75, latitude: 4.85) {
|
|
|
|
description,
|
|
|
|
geom
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"""
|
|
|
|
|
|
|
|
res =
|
|
|
|
conn
|
|
|
|
|> get("/api", AbsintheHelpers.query_skeleton(query, "address"))
|
|
|
|
|
|
|
|
assert json_response(res, 200)["data"]["reverseGeocode"] |> hd |> Map.get("description") ==
|
2019-11-08 18:37:14 +00:00
|
|
|
"10 rue Jangot, Lyon"
|
2019-03-14 17:31:14 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|