Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dataset#details : corrige nombre de ressources #3706

Merged
merged 1 commit into from
Jan 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions apps/transport/lib/transport_web/views/dataset_view.ex
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,14 @@ defmodule TransportWeb.DatasetView do
@gtfs_rt_validator_name Transport.Validators.GTFSRT.validator_name()

@doc """
Count the number of resources (official + community), excluding resources with a `documentation` type.
Count the number of resources, excluding:
- community resources
- resources with a `documentation` type.
"""
@spec count_resources(Dataset.t()) :: non_neg_integer
def count_resources(dataset) do
nb_resources = Enum.count(official_available_resources(dataset))
nb_community_resources = Enum.count(community_resources(dataset))
nb_resources + nb_community_resources - count_documentation_resources(dataset)
nb_official_resources = dataset |> official_available_resources() |> Enum.count()
nb_official_resources - count_documentation_resources(dataset)
end

@spec count_documentation_resources(Dataset.t()) :: non_neg_integer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,14 @@ defmodule TransportWeb.DatasetViewTest do
test "count_resources and count_documentation_resources" do
dataset = insert(:dataset)
insert(:resource, type: "documentation", url: "https://example.com/doc", dataset: dataset)
insert(:resource, type: "documentation", url: "https://example.com/more_doc", dataset: dataset)
insert(:resource, type: "main", url: "https://example.com/file", dataset: dataset)
insert(:resource, type: "main", url: "https://example.com/community", dataset: dataset, is_community_resource: true)

dataset = dataset |> DB.Repo.preload(:resources)

assert count_resources(dataset) == 2
assert count_documentation_resources(dataset) == 1
assert count_resources(dataset) == 1
assert count_documentation_resources(dataset) == 2
end

describe "licence_link" do
Expand Down
Loading