Skip to content

Commit

Permalink
Fix flaky test in TransportWeb.API.GeoQueryControllerTest (#3671)
Browse files Browse the repository at this point in the history
  • Loading branch information
AntoineAugusti authored Dec 19, 2023
1 parent fcc46f0 commit c7e2a04
Showing 1 changed file with 85 additions and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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",
Expand Down

0 comments on commit c7e2a04

Please sign in to comment.