1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.CommonAPI.UtilsTest do
6 alias Pleroma.Web.CommonAPI.Utils
7 alias Pleroma.Web.Endpoint
8 alias Pleroma.Builders.UserBuilder
11 test "it adds attachment links to a given text and attachment set" do
13 "Sakura%20Mana%20%E2%80%93%20Turned%20on%20by%20a%20Senior%20OL%20with%20a%20Temptating%20Tight%20Skirt-s%20Full%20Hipline%20and%20Panty%20Shot-%20Beautiful%20Thick%20Thighs-%20and%20Erotic%20Ass-%20-2015-%20--%20Oppaitime%208-28-2017%206-50-33%20PM.png"
16 "url" => [%{"href" => name}]
19 res = Utils.add_attachments("", [attachment])
22 "<br><a href=\"#{name}\" class='attachment'>Sakura Mana – Turned on by a Se…</a>"
25 describe "it confirms the password given is the current users password" do
26 test "incorrect password given" do
27 {:ok, user} = UserBuilder.insert()
29 assert Utils.confirm_current_password(user, "") == {:error, "Invalid password."}
32 test "correct password given" do
33 {:ok, user} = UserBuilder.insert()
34 assert Utils.confirm_current_password(user, "test") == {:ok, user}
38 test "parses emoji from name and bio" do
39 {:ok, user} = UserBuilder.insert(%{name: ":karjalanpiirakka:", bio: ":perkele:"})
44 "icon" => %{"type" => "Image", "url" => "#{Endpoint.url()}/finmoji/128px/perkele-128.png"},
51 "url" => "#{Endpoint.url()}/finmoji/128px/karjalanpiirakka-128.png"
53 "name" => ":karjalanpiirakka:"
57 assert expected == Utils.emoji_from_profile(user)
60 describe "format_input/3" do
61 test "works for bare text/plain" do
63 expected = "hello world!"
65 {output, [], []} = Utils.format_input(text, "text/plain")
67 assert output == expected
69 text = "hello world!\n\nsecond paragraph!"
70 expected = "hello world!<br><br>second paragraph!"
72 {output, [], []} = Utils.format_input(text, "text/plain")
74 assert output == expected
77 test "works for bare text/html" do
78 text = "<p>hello world!</p>"
79 expected = "<p>hello world!</p>"
81 {output, [], []} = Utils.format_input(text, "text/html")
83 assert output == expected
85 text = "<p>hello world!</p>\n\n<p>second paragraph</p>"
86 expected = "<p>hello world!</p>\n\n<p>second paragraph</p>"
88 {output, [], []} = Utils.format_input(text, "text/html")
90 assert output == expected
93 test "works for bare text/markdown" do
94 text = "**hello world**"
95 expected = "<p><strong>hello world</strong></p>\n"
97 {output, [], []} = Utils.format_input(text, "text/markdown")
99 assert output == expected
101 text = "**hello world**\n\n*another paragraph*"
102 expected = "<p><strong>hello world</strong></p>\n<p><em>another paragraph</em></p>\n"
104 {output, [], []} = Utils.format_input(text, "text/markdown")
106 assert output == expected
114 expected = "<blockquote><p>cool quote</p>\n</blockquote>\n<p>by someone</p>\n"
116 {output, [], []} = Utils.format_input(text, "text/markdown")
118 assert output == expected
121 test "works for text/markdown with mentions" do
123 UserBuilder.insert(%{nickname: "user__test", ap_id: "http://foo.com/user__test"})
125 text = "**hello world**\n\n*another @user__test and @user__test google.com paragraph*"
128 "<p><strong>hello world</strong></p>\n<p><em>another <span class=\"h-card\"><a data-user=\"#{
130 }\" class=\"u-url mention\" href=\"http://foo.com/user__test\">@<span>user__test</span></a></span> and <span class=\"h-card\"><a data-user=\"#{
132 }\" class=\"u-url mention\" href=\"http://foo.com/user__test\">@<span>user__test</span></a></span> <a href=\"http://google.com\">google.com</a> paragraph</em></p>\n"
134 {output, _, _} = Utils.format_input(text, "text/markdown")
136 assert output == expected