Skip to content

Commit

Permalink
Correctifs pour OTP 26+ (#4286)
Browse files Browse the repository at this point in the history
* Fix test for OTP 27

* Fix test for OTP 27

* Fix test for OTP 27 (too brittle now)

* Fix test for OTP 27

* Fix code for OTP 27 (order is not guaranteed anymore)

* Fix test for OTP 27

* mix format

* Update gbfs_validator_test.exs

* Make test clearer
  • Loading branch information
thbar authored Nov 12, 2024
1 parent a5a7897 commit 2ade6bd
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 17 deletions.
7 changes: 6 additions & 1 deletion apps/datagouvfr/test/datagouvfr/client/discussions_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ defmodule Datagouvfr.Client.DiscussionTest do
{"content-type", "application/json"}
]

assert body == ~s({"comment":"#{comment}","subject":{"class":"Dataset","id":"#{datagouv_id}"},"title":"#{title}"})
assert Jason.decode!(body) == %{
"comment" => comment,
"subject" => %{"class" => "Dataset", "id" => datagouv_id},
"title" => title
}

json(%{"title" => title, "discussion" => [%{"content" => comment}]}, status: 201)
end)

Expand Down
32 changes: 20 additions & 12 deletions apps/shared/test/validation/gbfs_validator_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,25 @@ defmodule GBFSValidatorTest do
assert logs =~ "impossible to query GBFS Validator"
end

test "can encode summary" do
assert """
{"errors_count":0,"has_errors":false,"validator":"validator_module","validator_version":"31c5325","version_detected":"1.1","version_validated":"1.1"}\
""" ==
Jason.encode!(%Summary{
errors_count: 0,
has_errors: false,
version_detected: "1.1",
version_validated: "1.1",
validator_version: "31c5325",
validator: :validator_module
})
test "can encode and decode summary" do
encoded_summary =
Jason.encode!(%Summary{
errors_count: 0,
has_errors: false,
version_detected: "1.1",
version_validated: "1.1",
validator_version: "31c5325",
validator: :validator_module
})

assert Jason.decode!(encoded_summary) == %{
"errors_count" => 0,
"has_errors" => false,
# NOTE: the serialized atom does not come back as an atom
"validator" => "validator_module",
"validator_version" => "31c5325",
"version_detected" => "1.1",
"version_validated" => "1.1"
}
end
end
5 changes: 4 additions & 1 deletion apps/transport/lib/jobs/gtfs_rt_metadata.ex
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,10 @@ defmodule Transport.Jobs.GTFSRTMetadataJob do
["service_alerts", "vehicle_positions"]
"""
def present_entities(count_entities) do
count_entities |> Map.filter(fn {_, v} -> v > 0 end) |> Enum.map(fn {k, _} -> Atom.to_string(k) end)
count_entities
|> Map.filter(fn {_, v} -> v > 0 end)
|> Enum.map(fn {k, _} -> Atom.to_string(k) end)
|> Enum.sort()
end

@spec process_feed({:error, any} | {:ok, TransitRealtime.FeedMessage.t()}, DB.Resource.t()) :: any
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@ defmodule TransportWeb.Backoffice.CacheLiveTest do
%{"Clé" => "foo", "TTL" => "Pas de TTL"}
] = extract_data_from_html(render(view))

assert_in_delta ttl |> String.replace([" ", "ms"], "") |> String.to_integer(), ttl_ms, 10
assert_in_delta ttl |> String.replace([" ", "ms"], "") |> String.to_integer(), ttl_ms, 30
end
end
2 changes: 1 addition & 1 deletion apps/unlock/test/enforce_ttl_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ defmodule Unlock.EnforceTTLTest do
cache_put("no_prefix")

# initially, the list of proxy cache keys should include only 2 entries
assert ["resource:with_ttl", "resource:no_ttl"] == cache_keys()
assert ["resource:no_ttl", "resource:with_ttl"] == cache_keys() |> Enum.sort()

# this is expected to remove bogus entries (the ones without a TTL),
# which would otherwise remain "available but stale" forever
Expand Down
2 changes: 1 addition & 1 deletion apps/unlock/test/shared_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,6 @@ defmodule Unlock.SharedTest do
cache_put(cache_key("no_ttl"))
cache_put("no_prefix")

assert ["resource:with_ttl", "resource:no_ttl"] == cache_keys()
assert ["resource:no_ttl", "resource:with_ttl"] == cache_keys() |> Enum.sort()
end
end

0 comments on commit 2ade6bd

Please sign in to comment.