logo

pleroma

My custom branche(s) on git.pleroma.social/pleroma/pleroma git clone https://hacktivis.me/git/pleroma.git
commit: 987f44d81142e11b008659f3fbdf9baf69a1e9d8
parent f775a1931b4f5625ad61fce8fabeb089375a80ac
Author: lain <lain@soykaf.club>
Date:   Wed, 20 Mar 2024 13:26:47 +0000

Merge branch 'bookmark-folders' into 'develop'

Fix BookmarkFolderView, add test

See merge request pleroma/pleroma!4096

Diffstat:

Achangelog.d/bookmark-folders.skip0
Mlib/pleroma/web/pleroma_api/views/bookmark_folder_view.ex14++++++--------
Mtest/pleroma/web/pleroma_api/controllers/bookmark_folder_controller_test.exs25+++++++++++++++++++------
3 files changed, 25 insertions(+), 14 deletions(-)

diff --git a/changelog.d/bookmark-folders.skip b/changelog.d/bookmark-folders.skip diff --git a/lib/pleroma/web/pleroma_api/views/bookmark_folder_view.ex b/lib/pleroma/web/pleroma_api/views/bookmark_folder_view.ex @@ -13,10 +13,8 @@ defmodule Pleroma.Web.PleromaAPI.BookmarkFolderView do %{ id: folder.id |> to_string(), name: folder.name, - emoji: get_emoji(folder.emoji), - source: %{ - emoji: folder.emoji - } + emoji: folder.emoji, + emoji_url: get_emoji_url(folder.emoji) } end @@ -24,18 +22,18 @@ defmodule Pleroma.Web.PleromaAPI.BookmarkFolderView do render_many(folders, __MODULE__, "show.json", Map.delete(opts, :folders)) end - defp get_emoji(nil) do + defp get_emoji_url(nil) do nil end - defp get_emoji(emoji) do + defp get_emoji_url(emoji) do if Emoji.unicode?(emoji) do - emoji + nil else emoji = Emoji.get(emoji) if emoji != nil do - Endpoint.url() |> URI.merge(emoji.relative_url) |> to_string() + Endpoint.url() |> URI.merge(emoji.file) |> to_string() else nil end diff --git a/test/pleroma/web/pleroma_api/controllers/bookmark_folder_controller_test.exs b/test/pleroma/web/pleroma_api/controllers/bookmark_folder_controller_test.exs @@ -33,9 +33,7 @@ defmodule Pleroma.Web.PleromaAPI.BookmarkFolderControllerTest do "id" => ^folder_id, "name" => "Bookmark folder", "emoji" => nil, - "source" => %{ - "emoji" => nil - } + "emoji_url" => nil } ] = result end @@ -57,9 +55,24 @@ defmodule Pleroma.Web.PleromaAPI.BookmarkFolderControllerTest do assert %{ "name" => "Bookmark folder", "emoji" => "📁", - "source" => %{ - "emoji" => "📁" - } + "emoji_url" => nil + } = 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 end