Commit ea72ac54 authored by Maksim's avatar Maksim
Browse files

fix case when tags is invalid

parent d3ec09bb
......@@ -244,8 +244,10 @@ def render_content(object), do: object["content"] || ""
{"name": "nextcloud", "url": "/tag/nextcloud"}]
"""
@spec build_tags(list(String.t())) :: list(map())
@spec build_tags(list(any())) :: list(map())
def build_tags(object_tags) when is_list(object_tags) do
object_tags = for tag when is_binary(tag) <- object_tags, do: tag
Enum.reduce(object_tags, [], fn tag, tags ->
tags ++ [%{name: tag, url: "/tag/#{tag}"}]
end)
......
......@@ -159,7 +159,18 @@ test "a reblog" do
describe "build_tags/1" do
test "it returns a a dictionary tags" do
assert StatusView.build_tags(["fediverse", "mastodon", "nextcloud"]) == [
object_tags = [
"fediverse",
"mastodon",
"nextcloud",
%{
"href" => "https://kawen.space/users/lain",
"name" => "@lain@kawen.space",
"type" => "Mention"
}
]
assert StatusView.build_tags(object_tags) == [
%{name: "fediverse", url: "/tag/fediverse"},
%{name: "mastodon", url: "/tag/mastodon"},
%{name: "nextcloud", url: "/tag/nextcloud"}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment