diff --git a/apps/transport/test/transport_web/controllers/api/geo_query_controller_test.exs b/apps/transport/test/transport_web/controllers/api/geo_query_controller_test.exs index feb79cee1f..038d6fd8f0 100644 --- a/apps/transport/test/transport_web/controllers/api/geo_query_controller_test.exs +++ b/apps/transport/test/transport_web/controllers/api/geo_query_controller_test.exs @@ -26,23 +26,21 @@ defmodule TransportWeb.API.GeoQueryControllerTest do insert(:geo_data, %{geo_data_import_id: geo_data_import_id_ko, geom: point2, payload: %{"nom_lieu" => "Bastia"}}) - conn = conn |> get(TransportWeb.API.Router.Helpers.geo_query_path(conn, :index, data: "bnlc")) - - assert json_response(conn, 200) == %{ - "type" => "FeatureCollection", - "features" => [ - %{ - "geometry" => %{"coordinates" => [1, 1], "type" => "Point"}, - "properties" => %{"nom_lieu" => "Ajaccio"}, - "type" => "Feature" - }, - %{ - "geometry" => %{"coordinates" => [2, 2], "type" => "Point"}, - "properties" => %{"nom_lieu" => "Coti-Chiavari"}, - "type" => "Feature" - } - ] - } + assert_expected_geojson(conn, + data: "bnlc", + expected_features: [ + %{ + "geometry" => %{"coordinates" => [1, 1], "type" => "Point"}, + "properties" => %{"nom_lieu" => "Ajaccio"}, + "type" => "Feature" + }, + %{ + "geometry" => %{"coordinates" => [2, 2], "type" => "Point"}, + "properties" => %{"nom_lieu" => "Coti-Chiavari"}, + "type" => "Feature" + } + ] + ) end test "a parkings relais geo query", %{conn: conn} do @@ -77,23 +75,21 @@ defmodule TransportWeb.API.GeoQueryControllerTest do payload: %{"nom" => "Rouen", "nb_pr" => 50} }) - conn = conn |> get(TransportWeb.API.Router.Helpers.geo_query_path(conn, :index, data: "parkings-relais")) - - assert json_response(conn, 200) == %{ - "type" => "FeatureCollection", - "features" => [ - %{ - "geometry" => %{"coordinates" => [1, 1], "type" => "Point"}, - "properties" => %{"nom" => "Nuits-Saint-Georges", "nb_pr" => 22}, - "type" => "Feature" - }, - %{ - "geometry" => %{"coordinates" => [2, 2], "type" => "Point"}, - "properties" => %{"nom" => "Gevrey-Chambertin", "nb_pr" => 23}, - "type" => "Feature" - } - ] - } + assert_expected_geojson(conn, + data: "parkings-relais", + expected_features: [ + %{ + "geometry" => %{"coordinates" => [1, 1], "type" => "Point"}, + "properties" => %{"nom" => "Nuits-Saint-Georges", "nb_pr" => 22}, + "type" => "Feature" + }, + %{ + "geometry" => %{"coordinates" => [2, 2], "type" => "Point"}, + "properties" => %{"nom" => "Gevrey-Chambertin", "nb_pr" => 23}, + "type" => "Feature" + } + ] + ) end test "a ZFE geo query", %{conn: conn} do @@ -128,29 +124,27 @@ defmodule TransportWeb.API.GeoQueryControllerTest do payload: %{} }) - conn = conn |> get(TransportWeb.API.Router.Helpers.geo_query_path(conn, :index, data: "zfe")) - - assert json_response(conn, 200) == %{ - "features" => [ - %{ - "geometry" => %{ - "coordinates" => [[[102, 2], [103, 2], [103, 3], [102, 3], [102, 2]]], - "type" => "Polygon" - }, - "properties" => %{}, - "type" => "Feature" - }, - %{ - "geometry" => %{ - "coordinates" => [[[42, 2], [103, 2], [103, 3], [42, 3], [42, 2]]], - "type" => "Polygon" - }, - "properties" => %{}, - "type" => "Feature" - } - ], - "type" => "FeatureCollection" - } + assert_expected_geojson(conn, + data: "zfe", + expected_features: [ + %{ + "geometry" => %{ + "coordinates" => [[[102, 2], [103, 2], [103, 3], [102, 3], [102, 2]]], + "type" => "Polygon" + }, + "properties" => %{}, + "type" => "Feature" + }, + %{ + "geometry" => %{ + "coordinates" => [[[42, 2], [103, 2], [103, 3], [42, 3], [42, 2]]], + "type" => "Polygon" + }, + "properties" => %{}, + "type" => "Feature" + } + ] + ) end test "a IRVE geo query", %{conn: conn} do @@ -187,33 +181,31 @@ defmodule TransportWeb.API.GeoQueryControllerTest do } }) - conn = conn |> get(TransportWeb.API.Router.Helpers.geo_query_path(conn, :index, data: "irve")) - - assert json_response(conn, 200) == %{ - "type" => "FeatureCollection", - "features" => [ - %{ - "geometry" => %{"coordinates" => [1, 1], "type" => "Point"}, - "properties" => %{ - "nom_enseigne" => "Recharge Super 95", - "id_station_itinerance" => "FRELCPEYSPC", - "nom_station" => "Dehaven Centre", - "nbre_pdc" => "2" - }, - "type" => "Feature" - }, - %{ - "geometry" => %{"coordinates" => [2, 2], "type" => "Point"}, - "properties" => %{ - "nom_enseigne" => "Recharge Super 95", - "id_station_itinerance" => "FRELCPBLOHM", - "nom_station" => "Gemina Port", - "nbre_pdc" => "3" - }, - "type" => "Feature" - } - ] - } + assert_expected_geojson(conn, + data: "irve", + expected_features: [ + %{ + "geometry" => %{"coordinates" => [1, 1], "type" => "Point"}, + "properties" => %{ + "nom_enseigne" => "Recharge Super 95", + "id_station_itinerance" => "FRELCPEYSPC", + "nom_station" => "Dehaven Centre", + "nbre_pdc" => "2" + }, + "type" => "Feature" + }, + %{ + "geometry" => %{"coordinates" => [2, 2], "type" => "Point"}, + "properties" => %{ + "nom_enseigne" => "Recharge Super 95", + "id_station_itinerance" => "FRELCPBLOHM", + "nom_station" => "Gemina Port", + "nbre_pdc" => "3" + }, + "type" => "Feature" + } + ] + ) end test "404 cases", %{conn: conn} do @@ -231,6 +223,15 @@ defmodule TransportWeb.API.GeoQueryControllerTest do |> json_response(404) end + defp assert_expected_geojson(%Plug.Conn{} = conn, data: data, expected_features: expected_features) do + %{"type" => "FeatureCollection", "features" => features} = + conn + |> get(TransportWeb.API.Router.Helpers.geo_query_path(conn, :index, data: data)) + |> json_response(200) + + assert MapSet.new(features) == MapSet.new(expected_features) + end + defp insert_bnlc_dataset do insert(:dataset, %{ type: "carpooling-areas",