diff options
Diffstat (limited to 'test/web/common_api')
-rw-r--r-- | test/web/common_api/common_api_test.exs | 40 | ||||
-rw-r--r-- | test/web/common_api/common_api_utils_test.exs | 50 |
2 files changed, 89 insertions, 1 deletions
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs index c3674711a..eb69ea4b2 100644 --- a/test/web/common_api/common_api_test.exs +++ b/test/web/common_api/common_api_test.exs @@ -1,5 +1,5 @@ # Pleroma: A lightweight social networking server -# Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/> +# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/> # SPDX-License-Identifier: AGPL-3.0-only defmodule Pleroma.Web.CommonAPI.Test do @@ -96,4 +96,42 @@ defmodule Pleroma.Web.CommonAPI.Test do {:error, _} = CommonAPI.favorite(activity.id, user) end end + + describe "pinned statuses" do + setup do + Pleroma.Config.put([:instance, :max_pinned_statuses], 1) + + user = insert(:user) + {:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"}) + + [user: user, activity: activity] + end + + test "pin status", %{user: user, activity: activity} do + assert {:ok, ^activity} = CommonAPI.pin(activity.id, user) + end + + test "only self-authored can be pinned", %{activity: activity} do + user = insert(:user) + + assert {:error, "Could not pin"} = CommonAPI.pin(activity.id, user) + end + + test "max pinned statuses", %{user: user, activity: activity_one} do + {:ok, activity_two} = CommonAPI.post(user, %{"status" => "HI!!!"}) + + assert {:ok, ^activity_one} = CommonAPI.pin(activity_one.id, user) + + user = refresh_record(user) + + assert {:error, "You have already pinned the maximum number of statuses"} = + CommonAPI.pin(activity_two.id, user) + end + + test "unpin status", %{user: user, activity: activity} do + {:ok, activity} = CommonAPI.pin(activity.id, user) + + assert {:ok, ^activity} = CommonAPI.unpin(activity.id, user) + end + end end diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs index fc89e3116..754bc7255 100644 --- a/test/web/common_api/common_api_utils_test.exs +++ b/test/web/common_api/common_api_utils_test.exs @@ -56,4 +56,54 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do assert expected == Utils.emoji_from_profile(user) end + + describe "format_input/4" do + test "works for bare text/plain" do + text = "hello world!" + expected = "hello world!" + + output = Utils.format_input(text, [], [], "text/plain") + + assert output == expected + + text = "hello world!\n\nsecond paragraph!" + expected = "hello world!<br><br>second paragraph!" + + output = Utils.format_input(text, [], [], "text/plain") + + assert output == expected + end + + test "works for bare text/html" do + text = "<p>hello world!</p>" + expected = "<p>hello world!</p>" + + output = Utils.format_input(text, [], [], "text/html") + + assert output == expected + + text = "<p>hello world!</p>\n\n<p>second paragraph</p>" + expected = "<p>hello world!</p>\n\n<p>second paragraph</p>" + + output = Utils.format_input(text, [], [], "text/html") + + assert output == expected + end + + test "works for bare text/markdown" do + text = "**hello world**" + expected = "<p><strong>hello world</strong></p>\n" + + output = Utils.format_input(text, [], [], "text/markdown") + + assert output == expected + + text = "**hello world**\n\n*another paragraph*" + expected = "<p><strong>hello world</strong></p>\n<p><em>another paragraph</em></p>\n" + + output = Utils.format_input(text, [], [], "text/markdown") + + assert output == expected + end + end end |