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 30, 2024
1 parent 45f0c29 commit ba686e6
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 0 deletions.
6 changes: 6 additions & 0 deletions apps/transport/lib/db/dataset.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ defmodule DB.Dataset do
@licences_ouvertes ["fr-lo", "lov2"]
@licence_mobilités_tag "licence-mobilités"
@hidden_dataset_custom_tag_value "masqué"
@experimental_tag "experimental"

typed_schema "dataset" do
field(:datagouv_id, :string)
Expand Down Expand Up @@ -1125,4 +1126,9 @@ defmodule DB.Dataset do
@spec full_logo(__MODULE__.t()) :: binary()
def full_logo(%__MODULE__{full_logo: full_logo, custom_full_logo: custom_full_logo}),
do: custom_full_logo || full_logo

def reject_experimental_datasets(queryable) do
queryable
|> where([d], @experimental_tag not in d.tags)
end
end
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
|> 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
|> 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()
|> Dataset.reject_experimental_datasets()
|> preload([:resources, :aom, :region, :communes, :legal_owners_aom, :legal_owners_region])
|> Repo.all()
|> Enum.map(fn dataset ->
Expand Down
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 ba686e6

Please sign in to comment.