Merge branch 'bookmark-folders' into 'develop'
Fix BookmarkFolderView, add test See merge request pleroma/pleroma!4096
This commit is contained in:
commit
987f44d811
0
changelog.d/bookmark-folders.skip
Normal file
0
changelog.d/bookmark-folders.skip
Normal file
@ -13,10 +13,8 @@ defmodule Pleroma.Web.PleromaAPI.BookmarkFolderView do
|
|||||||
%{
|
%{
|
||||||
id: folder.id |> to_string(),
|
id: folder.id |> to_string(),
|
||||||
name: folder.name,
|
name: folder.name,
|
||||||
emoji: get_emoji(folder.emoji),
|
emoji: folder.emoji,
|
||||||
source: %{
|
emoji_url: get_emoji_url(folder.emoji)
|
||||||
emoji: folder.emoji
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -24,18 +22,18 @@ defmodule Pleroma.Web.PleromaAPI.BookmarkFolderView do
|
|||||||
render_many(folders, __MODULE__, "show.json", Map.delete(opts, :folders))
|
render_many(folders, __MODULE__, "show.json", Map.delete(opts, :folders))
|
||||||
end
|
end
|
||||||
|
|
||||||
defp get_emoji(nil) do
|
defp get_emoji_url(nil) do
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
defp get_emoji(emoji) do
|
defp get_emoji_url(emoji) do
|
||||||
if Emoji.unicode?(emoji) do
|
if Emoji.unicode?(emoji) do
|
||||||
emoji
|
nil
|
||||||
else
|
else
|
||||||
emoji = Emoji.get(emoji)
|
emoji = Emoji.get(emoji)
|
||||||
|
|
||||||
if emoji != nil do
|
if emoji != nil do
|
||||||
Endpoint.url() |> URI.merge(emoji.relative_url) |> to_string()
|
Endpoint.url() |> URI.merge(emoji.file) |> to_string()
|
||||||
else
|
else
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
@ -33,9 +33,7 @@ defmodule Pleroma.Web.PleromaAPI.BookmarkFolderControllerTest do
|
|||||||
"id" => ^folder_id,
|
"id" => ^folder_id,
|
||||||
"name" => "Bookmark folder",
|
"name" => "Bookmark folder",
|
||||||
"emoji" => nil,
|
"emoji" => nil,
|
||||||
"source" => %{
|
"emoji_url" => nil
|
||||||
"emoji" => nil
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
] = result
|
] = result
|
||||||
end
|
end
|
||||||
@ -57,9 +55,24 @@ defmodule Pleroma.Web.PleromaAPI.BookmarkFolderControllerTest do
|
|||||||
assert %{
|
assert %{
|
||||||
"name" => "Bookmark folder",
|
"name" => "Bookmark folder",
|
||||||
"emoji" => "📁",
|
"emoji" => "📁",
|
||||||
"source" => %{
|
"emoji_url" => nil
|
||||||
"emoji" => "📁"
|
} = result
|
||||||
}
|
end
|
||||||
|
|
||||||
|
test "it creates a bookmark folder with custom emoji", %{conn: conn} do
|
||||||
|
result =
|
||||||
|
conn
|
||||||
|
|> put_req_header("content-type", "application/json")
|
||||||
|
|> post("/api/v1/pleroma/bookmark_folders", %{
|
||||||
|
name: "Bookmark folder",
|
||||||
|
emoji: ":firefox:"
|
||||||
|
})
|
||||||
|
|> json_response_and_validate_schema(200)
|
||||||
|
|
||||||
|
assert %{
|
||||||
|
"name" => "Bookmark folder",
|
||||||
|
"emoji" => ":firefox:",
|
||||||
|
"emoji_url" => "http://localhost:4001/emoji/Firefox.gif"
|
||||||
} = result
|
} = result
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user