Allow for url to be a list #718

Merged
floatingghost merged 1 commit from helge/akkoma:develop into develop 2024-04-12 17:39:39 +00:00
2 changed files with 27 additions and 0 deletions

View file

@ -53,6 +53,14 @@ def cast_data(data) do
defp fix_url(%{"url" => url} = data) when is_bitstring(url), do: data defp fix_url(%{"url" => url} = data) when is_bitstring(url), do: data
defp fix_url(%{"url" => url} = data) when is_map(url), do: Map.put(data, "url", url["href"]) defp fix_url(%{"url" => url} = data) when is_map(url), do: Map.put(data, "url", url["href"])
defp fix_url(%{"url" => url} = data) when is_list(url) do
if is_map(List.first(url)) do
Map.put(data, "url", List.first(url)["href"])
else
Map.put(data, "url", List.first(url))
end
end
defp fix_url(data), do: data defp fix_url(data), do: data
defp fix_tag(%{"tag" => tag} = data) when is_list(tag) do defp fix_tag(%{"tag" => tag} = data) when is_list(tag) do

View file

@ -39,6 +39,25 @@ test "a basic note validates", %{note: note} do
%{valid?: true} = ArticleNotePageValidator.cast_and_validate(note) %{valid?: true} = ArticleNotePageValidator.cast_and_validate(note)
end end
test "note with url validates", %{note: note} do
note = Map.put(note, "url", "https://remote.example/link")
%{valid?: true} = ArticleNotePageValidator.cast_and_validate(note)
end
test "note with url array validates", %{note: note} do
note = Map.put(note, "url", ["https://remote.example/link"])
%{valid?: true} = ArticleNotePageValidator.cast_and_validate(note)
end
test "note with url array validates if contains a link object", %{note: note} do
note = Map.put(note, "url", [%{
"type" => "Link",
"href" => "https://remote.example/link"
}])
%{valid?: true} = ArticleNotePageValidator.cast_and_validate(note)
end
test "a note with a language validates" do test "a note with a language validates" do
insert(:user, %{ap_id: "https://mastodon.social/users/akkoma_ap_integration_tester"}) insert(:user, %{ap_id: "https://mastodon.social/users/akkoma_ap_integration_tester"})
note = File.read!("test/fixtures/mastodon/note_with_language.json") |> Jason.decode!() note = File.read!("test/fixtures/mastodon/note_with_language.json") |> Jason.decode!()