Skip to content

Commit

Permalink
API datasets: exclure les datasets experimentaux
Browse files Browse the repository at this point in the history
See #4275.
  • Loading branch information
ptitfred committed Oct 29, 2024
1 parent b06203f commit 6ec1731
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ defmodule TransportWeb.API.DatasetController do
def by_id(%Plug.Conn{} = conn, %{"id" => datagouv_id}) do
dataset =
Dataset
|> reject_experimental_datasets()
|> preload([:resources, :aom, :region, :communes, :legal_owners_aom, :legal_owners_region])
|> Repo.get_by(datagouv_id: datagouv_id)

Expand All @@ -95,6 +96,7 @@ defmodule TransportWeb.API.DatasetController do
@spec geojson_by_id(Plug.Conn.t(), map) :: Plug.Conn.t()
def geojson_by_id(%Plug.Conn{} = conn, %{"id" => id}) do
Dataset
|> reject_experimental_datasets()
|> Repo.get_by(datagouv_id: id)
|> Repo.preload([:aom, :region, :communes])
|> case do
Expand Down Expand Up @@ -374,6 +376,7 @@ defmodule TransportWeb.API.DatasetController do

%{}
|> Dataset.list_datasets()
|> reject_experimental_datasets()
|> preload([:resources, :aom, :region, :communes, :legal_owners_aom, :legal_owners_region])
|> Repo.all()
|> Enum.map(fn dataset ->
Expand Down Expand Up @@ -420,4 +423,9 @@ defmodule TransportWeb.API.DatasetController do

transform_dataset_with_detail(conn, dataset)
end

defp reject_experimental_datasets(queryable) do
queryable
|> where([d], "experimental" not in d.tags)
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,54 @@ defmodule TransportWeb.API.DatasetControllerTest do
assert_schema(json, "DatasetsResponse", TransportWeb.API.Spec.spec())
end

test "GET /api/datasets without the experimental tagged datasets", %{conn: conn} do
aom = insert(:aom, nom: "Angers Métropole", siren: "siren")

insert(:resource,
dataset:
insert(:dataset,
custom_title: "TC",
type: "public-transit",
licence: "lov2",
datagouv_id: "datagouv-1",
slug: "slug-1",
is_active: true,
created_at: ~U[2021-12-23 13:30:40.000000Z],
aom: aom,
tags: ["netex"]
),
url: "https://link.to/gbfs.json",
datagouv_id: "1",
type: "main",
format: "gbfs"
)

insert(:resource,
dataset:
insert(:dataset,
custom_title: "Tarifs (expérimental)",
type: "public-transit",
licence: "lov2",
datagouv_id: "datagouv-2",
slug: "slug-2",
is_active: true,
created_at: ~U[2021-12-23 13:30:40.000000Z],
aom: aom,
tags: ["netex", "experimental"]
),
url: "https://link.to/gbfs.json",
datagouv_id: "2",
type: "main",
format: "gbfs"
)

path = Helpers.dataset_path(conn, :datasets)

json = conn |> get(path) |> json_response(200)

assert [%{"title" => "TC"}] = json
end

test "GET /api/datasets/:id *without* history, multi_validation and resource_metadata", %{conn: conn} do
aom = insert(:aom, nom: "Angers Métropole", siren: "siren", id: 4242)
region = DB.Region |> Ecto.Query.where(insee: "52") |> DB.Repo.one!()
Expand Down Expand Up @@ -506,6 +554,35 @@ defmodule TransportWeb.API.DatasetControllerTest do
|> json_response(200)
end

test "GET /api/datasets/:id with a dataset tagged 'experimental'", %{conn: conn} do
setup_empty_history_resources()

%DB.Dataset{datagouv_id: visible_dataset_datagouv_id} =
insert(:dataset,
datagouv_id: "datagouv-1",
is_active: true,
created_at: ~U[2021-12-23 13:30:40.000000Z],
tags: ["netex"]
)

%DB.Dataset{datagouv_id: experimental_dataset_datagouv_id} =
insert(:dataset,
datagouv_id: "datagouv-2",
is_active: true,
created_at: ~U[2021-12-23 13:30:40.000000Z],
tags: ["netex", "experimental"]
)

assert %{"datagouv_id" => ^visible_dataset_datagouv_id} =
conn
|> get(Helpers.dataset_path(conn, :by_id, visible_dataset_datagouv_id))
|> json_response(200)

conn
|> get(Helpers.dataset_path(conn, :by_id, experimental_dataset_datagouv_id))
|> json_response(404)
end

test "gtfs-rt features are filled", %{conn: conn} do
dataset_1 = insert(:dataset, datagouv_id: datagouv_id_1 = Ecto.UUID.generate())
resource_1 = insert(:resource, dataset_id: dataset_1.id, format: "gtfs-rt")
Expand Down

0 comments on commit 6ec1731

Please sign in to comment.