From 1ca080c8628d261cdb95145331aa36e631e90a3f Mon Sep 17 00:00:00 2001
From: eal
Date: Fri, 14 Dec 2018 07:56:49 +0200
Subject: Prevent accidental double RTs or favorites
---
test/web/common_api/common_api_test.exs | 39 +++++++++++++++++++++++++++++++++
1 file changed, 39 insertions(+)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 8fc65f4c0..0b5a235f8 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -2,6 +2,7 @@ defmodule Pleroma.Web.CommonAPI.Test do
use Pleroma.DataCase
alias Pleroma.Web.CommonAPI
alias Pleroma.User
+ alias Pleroma.Activity
import Pleroma.Factory
@@ -53,4 +54,42 @@ defmodule Pleroma.Web.CommonAPI.Test do
assert content == "2hu
alert('xss')"
end
end
+
+ describe "reactions" do
+ test "repeating a status" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
+
+ {:ok, %Activity{}, _} = CommonAPI.repeat(activity.id, user)
+ end
+
+ test "favoriting a status" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
+
+ {:ok, %Activity{}, _} = CommonAPI.favorite(activity.id, user)
+ end
+
+ test "retweeting a status twice returns an error" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
+ {:ok, %Activity{}, _object} = CommonAPI.repeat(activity.id, user)
+ {:error, _} = CommonAPI.repeat(activity.id, user)
+ end
+
+ test "favoriting a status twice returns an error" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"})
+ {:ok, %Activity{}, _object} = CommonAPI.favorite(activity.id, user)
+ {:error, _} = CommonAPI.favorite(activity.id, user)
+ end
+ end
end
--
cgit v1.2.3
From 3c08d229db423052d0dd88b8a36fb39b0ae81ead Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Sun, 23 Dec 2018 20:11:29 +0000
Subject: tests: add legal boilerplate
---
test/web/common_api/common_api_test.exs | 4 ++++
test/web/common_api/common_api_utils_test.exs | 4 ++++
2 files changed, 8 insertions(+)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 0b5a235f8..c3674711a 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.CommonAPI.Test do
use Pleroma.DataCase
alias Pleroma.Web.CommonAPI
diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs
index b01ce04f8..fc89e3116 100644
--- a/test/web/common_api/common_api_utils_test.exs
+++ b/test/web/common_api/common_api_utils_test.exs
@@ -1,3 +1,7 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2018 Pleroma Authors
+# SPDX-License-Identifier: AGPL-3.0-only
+
defmodule Pleroma.Web.CommonAPI.UtilsTest do
alias Pleroma.Web.CommonAPI.Utils
alias Pleroma.Web.Endpoint
--
cgit v1.2.3
From 380e9fba21123467b41629828f97d5f2c257a128 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Mon, 7 Jan 2019 20:45:33 +0700
Subject: add pinned posts
---
test/web/common_api/common_api_test.exs | 36 +++++++++++++++++++++++++++++++++
1 file changed, 36 insertions(+)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index c3674711a..59beb3120 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -96,4 +96,40 @@ defmodule Pleroma.Web.CommonAPI.Test do
{:error, _} = CommonAPI.favorite(activity.id, user)
end
end
+
+ describe "pinned posts" do
+ test "pin post" do
+ Pleroma.Config.put([:instance, :max_pinned_posts], 1)
+ user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
+
+ assert {:ok, ^activity} = CommonAPI.pin(activity.id, user)
+ end
+
+ test "max pinned posts" do
+ Pleroma.Config.put([:instance, :max_pinned_posts], 1)
+ user = insert(:user)
+
+ {:ok, activity_one} = CommonAPI.post(user, %{"status" => "HI!!!"})
+ {:ok, activity_two} = CommonAPI.post(user, %{"status" => "HI!!!"})
+
+ assert {:ok, ^activity_one} = CommonAPI.pin(activity_one.id, user)
+
+ user = User.get_by_ap_id(user.ap_id)
+
+ assert {:error, "You have already pinned the maximum number of toots"} =
+ CommonAPI.pin(activity_two.id, user)
+ end
+
+ test "unpin post" do
+ Pleroma.Config.put([:instance, :max_pinned_posts], 1)
+ user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
+ {:ok, activity} = CommonAPI.pin(activity.id, user)
+
+ assert {:ok, ^activity} = CommonAPI.unpin(activity.id, user)
+ end
+ end
end
--
cgit v1.2.3
From 63dbd875684b192e57d356a194c5d07ad98bd810 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Tue, 8 Jan 2019 15:25:50 +0700
Subject: rename `post` to `status`
---
test/web/common_api/common_api_test.exs | 14 +++++++-------
1 file changed, 7 insertions(+), 7 deletions(-)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 59beb3120..652b53099 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -97,9 +97,9 @@ defmodule Pleroma.Web.CommonAPI.Test do
end
end
- describe "pinned posts" do
- test "pin post" do
- Pleroma.Config.put([:instance, :max_pinned_posts], 1)
+ describe "pinned statuses" do
+ test "pin status" do
+ Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
@@ -107,8 +107,8 @@ defmodule Pleroma.Web.CommonAPI.Test do
assert {:ok, ^activity} = CommonAPI.pin(activity.id, user)
end
- test "max pinned posts" do
- Pleroma.Config.put([:instance, :max_pinned_posts], 1)
+ test "max pinned statuses" do
+ Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
user = insert(:user)
{:ok, activity_one} = CommonAPI.post(user, %{"status" => "HI!!!"})
@@ -122,8 +122,8 @@ defmodule Pleroma.Web.CommonAPI.Test do
CommonAPI.pin(activity_two.id, user)
end
- test "unpin post" do
- Pleroma.Config.put([:instance, :max_pinned_posts], 1)
+ test "unpin status" do
+ Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
--
cgit v1.2.3
From db6f4496ebb5dbcb680104b2df80410b9dcb8407 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Tue, 8 Jan 2019 15:32:06 +0700
Subject: fix test
---
test/web/common_api/common_api_test.exs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 652b53099..24e5e56f4 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -118,7 +118,7 @@ defmodule Pleroma.Web.CommonAPI.Test do
user = User.get_by_ap_id(user.ap_id)
- assert {:error, "You have already pinned the maximum number of toots"} =
+ assert {:error, "You have already pinned the maximum number of statuses"} =
CommonAPI.pin(activity_two.id, user)
end
--
cgit v1.2.3
From 7b6c5f0a9d02785bee3e4c2585fea1f8983e61b0 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Tue, 8 Jan 2019 16:01:35 +0700
Subject: improve test readability
---
test/web/common_api/common_api_test.exs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 24e5e56f4..7d5ceb398 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -116,7 +116,7 @@ defmodule Pleroma.Web.CommonAPI.Test do
assert {:ok, ^activity_one} = CommonAPI.pin(activity_one.id, user)
- user = User.get_by_ap_id(user.ap_id)
+ user = refresh_record(user)
assert {:error, "You have already pinned the maximum number of statuses"} =
CommonAPI.pin(activity_two.id, user)
--
cgit v1.2.3
From 1b06e6fdf3d879422d6cb0fe57cfcef223b54196 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Wed, 9 Jan 2019 17:40:15 +0700
Subject: only non-reblogs, self-authored, public statuses can be pinned
---
test/web/common_api/common_api_test.exs | 10 ++++++++++
1 file changed, 10 insertions(+)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 7d5ceb398..84b264439 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -107,6 +107,16 @@ defmodule Pleroma.Web.CommonAPI.Test do
assert {:ok, ^activity} = CommonAPI.pin(activity.id, user)
end
+ test "only self-authored can be pinned" do
+ Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
+ user_one = insert(:user)
+ user_two = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(user_one, %{"status" => "HI!!!"})
+
+ assert {:error, "Could not pin"} = CommonAPI.pin(activity.id, user_two)
+ end
+
test "max pinned statuses" do
Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
user = insert(:user)
--
cgit v1.2.3
From 6cbe63726d298ae85a75efa7591a54394469525e Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Wed, 9 Jan 2019 19:54:37 +0700
Subject: improve tests
---
test/web/common_api/common_api_test.exs | 32 ++++++++++++--------------------
1 file changed, 12 insertions(+), 20 deletions(-)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 84b264439..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
+# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.CommonAPI.Test do
@@ -98,30 +98,26 @@ defmodule Pleroma.Web.CommonAPI.Test do
end
describe "pinned statuses" do
- test "pin status" do
+ setup do
Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
- user = insert(:user)
+ user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
- assert {:ok, ^activity} = CommonAPI.pin(activity.id, user)
+ [user: user, activity: activity]
end
- test "only self-authored can be pinned" do
- Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
- user_one = insert(:user)
- user_two = insert(:user)
-
- {:ok, activity} = CommonAPI.post(user_one, %{"status" => "HI!!!"})
-
- assert {:error, "Could not pin"} = CommonAPI.pin(activity.id, user_two)
+ test "pin status", %{user: user, activity: activity} do
+ assert {:ok, ^activity} = CommonAPI.pin(activity.id, user)
end
- test "max pinned statuses" do
- Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
+ test "only self-authored can be pinned", %{activity: activity} do
user = insert(:user)
- {:ok, activity_one} = CommonAPI.post(user, %{"status" => "HI!!!"})
+ 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)
@@ -132,11 +128,7 @@ defmodule Pleroma.Web.CommonAPI.Test do
CommonAPI.pin(activity_two.id, user)
end
- test "unpin status" do
- Pleroma.Config.put([:instance, :max_pinned_statuses], 1)
- user = insert(:user)
-
- {:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!"})
+ test "unpin status", %{user: user, activity: activity} do
{:ok, activity} = CommonAPI.pin(activity.id, user)
assert {:ok, ^activity} = CommonAPI.unpin(activity.id, user)
--
cgit v1.2.3
From 490c80bc9651f93b61dfe4ae531bc0072a35d044 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Thu, 10 Jan 2019 03:46:34 +0000
Subject: test: common api: add tests for format_input/4
---
test/web/common_api/common_api_utils_test.exs | 50 +++++++++++++++++++++++++++
1 file changed, 50 insertions(+)
(limited to 'test/web/common_api')
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!
second paragraph!"
+
+ output = Utils.format_input(text, [], [], "text/plain")
+
+ assert output == expected
+ end
+
+ test "works for bare text/html" do
+ text = "hello world!
"
+ expected = "hello world!
"
+
+ output = Utils.format_input(text, [], [], "text/html")
+
+ assert output == expected
+
+ text = "hello world!
\n\nsecond paragraph
"
+ expected = "hello world!
\n\nsecond paragraph
"
+
+ output = Utils.format_input(text, [], [], "text/html")
+
+ assert output == expected
+ end
+
+ test "works for bare text/markdown" do
+ text = "**hello world**"
+ expected = "hello world
\n"
+
+ output = Utils.format_input(text, [], [], "text/markdown")
+
+ assert output == expected
+
+ text = "**hello world**\n\n*another paragraph*"
+ expected = "hello world
\nanother paragraph
\n"
+
+ output = Utils.format_input(text, [], [], "text/markdown")
+
+ assert output == expected
+ end
+ end
end
--
cgit v1.2.3
From b594a54d0caf0f91dd9188157cb34e01ee9ea794 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Fri, 11 Jan 2019 12:31:31 +0700
Subject: unpin when deleting a status
---
test/web/common_api/common_api_test.exs | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index eb69ea4b2..a3aff5897 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -109,6 +109,11 @@ defmodule Pleroma.Web.CommonAPI.Test do
test "pin status", %{user: user, activity: activity} do
assert {:ok, ^activity} = CommonAPI.pin(activity.id, user)
+
+ id = activity.id
+ user = refresh_record(user)
+
+ assert %User{info: %{pinned_activities: [^id]}} = user
end
test "only self-authored can be pinned", %{activity: activity} do
@@ -131,7 +136,25 @@ defmodule Pleroma.Web.CommonAPI.Test do
test "unpin status", %{user: user, activity: activity} do
{:ok, activity} = CommonAPI.pin(activity.id, user)
+ user = refresh_record(user)
+
assert {:ok, ^activity} = CommonAPI.unpin(activity.id, user)
+
+ user = refresh_record(user)
+
+ assert %User{info: %{pinned_activities: []}} = user
+ end
+
+ test "should unpin status when deleting a status", %{user: user, activity: activity} do
+ {:ok, activity} = CommonAPI.pin(activity.id, user)
+
+ user = refresh_record(user)
+
+ assert {:ok, _} = CommonAPI.delete(activity.id, user)
+
+ user = refresh_record(user)
+
+ assert %User{info: %{pinned_activities: []}} = user
end
end
end
--
cgit v1.2.3
From 728587fdaabbf8db8ee0d3626ab706044f0249f7 Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Fri, 11 Jan 2019 12:47:44 +0700
Subject: typo
---
test/web/common_api/common_api_test.exs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index a3aff5897..9ac805f24 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -145,7 +145,7 @@ defmodule Pleroma.Web.CommonAPI.Test do
assert %User{info: %{pinned_activities: []}} = user
end
- test "should unpin status when deleting a status", %{user: user, activity: activity} do
+ test "should unpin when deleting a status", %{user: user, activity: activity} do
{:ok, activity} = CommonAPI.pin(activity.id, user)
user = refresh_record(user)
--
cgit v1.2.3
From be0fb5dec47e5dc69aaef5f9c4f6910eba92b48a Mon Sep 17 00:00:00 2001
From: lain
Date: Sun, 20 Jan 2019 11:48:53 +0100
Subject: Add a test to ensure #39 is fixed.
---
test/web/common_api/common_api_test.exs | 7 +++++++
1 file changed, 7 insertions(+)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 9ac805f24..a7d9e6161 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -17,6 +17,13 @@ defmodule Pleroma.Web.CommonAPI.Test do
assert activity.data["object"]["tag"] == ["2hu"]
end
+ test "it adds emoji in the object" do
+ user = insert(:user)
+ {:ok, activity} = CommonAPI.post(user, %{"status" => ":moominmamma:"})
+
+ assert activity.data["object"]["emoji"]["moominmamma"]
+ end
+
test "it adds emoji when updating profiles" do
user = insert(:user, %{name: ":karjalanpiirakka:"})
--
cgit v1.2.3
From 8bb7e19b3814e261e66c2d3592d146f72d4ce623 Mon Sep 17 00:00:00 2001
From: "Haelwenn (lanodan) Monnier"
Date: Sun, 10 Feb 2019 22:57:38 +0100
Subject: test: de-group alias/es
---
test/web/common_api/common_api_utils_test.exs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs
index 754bc7255..faed6b685 100644
--- a/test/web/common_api/common_api_utils_test.exs
+++ b/test/web/common_api/common_api_utils_test.exs
@@ -5,7 +5,7 @@
defmodule Pleroma.Web.CommonAPI.UtilsTest do
alias Pleroma.Web.CommonAPI.Utils
alias Pleroma.Web.Endpoint
- alias Pleroma.Builders.{UserBuilder}
+ alias Pleroma.Builders.UserBuilder
use Pleroma.DataCase
test "it adds attachment links to a given text and attachment set" do
--
cgit v1.2.3
From c01ef574c192488c2643a20b4064439757613449 Mon Sep 17 00:00:00 2001
From: Karen Konou
Date: Mon, 11 Feb 2019 11:59:51 +0100
Subject: Refactor as per Rin's suggestions, add endpoint tests
---
test/web/common_api/common_api_test.exs | 26 ++++++++++++++++++++++++++
1 file changed, 26 insertions(+)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index a7d9e6161..d26b6e49c 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -164,4 +164,30 @@ defmodule Pleroma.Web.CommonAPI.Test do
assert %User{info: %{pinned_activities: []}} = user
end
end
+
+ describe "mute tests" do
+ setup do
+ user = insert(:user)
+
+ activity = insert(:note_activity)
+
+ [user: user, activity: activity]
+ end
+
+ test "add mute", %{user: user, activity: activity} do
+ {:ok, _} = CommonAPI.add_mute(user, activity)
+ assert CommonAPI.thread_muted?(user, activity)
+ end
+
+ test "remove mute", %{user: user, activity: activity} do
+ CommonAPI.add_mute(user, activity)
+ {:ok, _} = CommonAPI.remove_mute(user, activity)
+ refute CommonAPI.thread_muted?(user, activity)
+ end
+
+ test "check that mutes can't be duplicate", %{user: user, activity: activity} do
+ CommonAPI.add_mute(user, activity)
+ {:error, _} = CommonAPI.add_mute(user, activity)
+ end
+ end
end
--
cgit v1.2.3
From 71c8c60ded8dce402dbe69545afebd55c63927e5 Mon Sep 17 00:00:00 2001
From: lain
Date: Sun, 17 Feb 2019 17:47:24 +0100
Subject: More speedup, test fixes.
---
test/web/common_api/common_api_test.exs | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index d26b6e49c..870648fb5 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -2,7 +2,7 @@
# Copyright © 2017-2019 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
-defmodule Pleroma.Web.CommonAPI.Test do
+defmodule Pleroma.Web.CommonAPITest do
use Pleroma.DataCase
alias Pleroma.Web.CommonAPI
alias Pleroma.User
--
cgit v1.2.3
From bff9eb5ef7ad446376f68807d4e51db5f2de9515 Mon Sep 17 00:00:00 2001
From: Egor
Date: Wed, 20 Feb 2019 16:51:25 +0000
Subject: Reports
---
test/web/common_api/common_api_test.exs | 31 +++++++++++++++++++++++++++++++
1 file changed, 31 insertions(+)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 870648fb5..9ba320f59 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -190,4 +190,35 @@ defmodule Pleroma.Web.CommonAPITest do
{:error, _} = CommonAPI.add_mute(user, activity)
end
end
+
+ describe "reports" do
+ test "creates a report" do
+ reporter = insert(:user)
+ target_user = insert(:user)
+
+ {:ok, activity} = CommonAPI.post(target_user, %{"status" => "foobar"})
+
+ reporter_ap_id = reporter.ap_id
+ target_ap_id = target_user.ap_id
+ activity_ap_id = activity.data["id"]
+ comment = "foobar"
+
+ report_data = %{
+ "account_id" => target_user.id,
+ "comment" => comment,
+ "status_ids" => [activity.id]
+ }
+
+ assert {:ok, flag_activity} = CommonAPI.report(reporter, report_data)
+
+ assert %Activity{
+ actor: ^reporter_ap_id,
+ data: %{
+ "type" => "Flag",
+ "content" => ^comment,
+ "object" => [^target_ap_id, ^activity_ap_id]
+ }
+ } = flag_activity
+ end
+ end
end
--
cgit v1.2.3
From c3ac9424d2affe87df82c14dc243f507fa639343 Mon Sep 17 00:00:00 2001
From: Egor
Date: Tue, 26 Feb 2019 23:32:26 +0000
Subject: AutoLinker
---
test/web/common_api/common_api_utils_test.exs | 32 +++++++++++++++++++++------
1 file changed, 25 insertions(+), 7 deletions(-)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs
index faed6b685..dc7b4c229 100644
--- a/test/web/common_api/common_api_utils_test.exs
+++ b/test/web/common_api/common_api_utils_test.exs
@@ -57,19 +57,19 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
assert expected == Utils.emoji_from_profile(user)
end
- describe "format_input/4" do
+ describe "format_input/3" do
test "works for bare text/plain" do
text = "hello world!"
expected = "hello world!"
- output = Utils.format_input(text, [], [], "text/plain")
+ {output, [], []} = Utils.format_input(text, "text/plain")
assert output == expected
text = "hello world!\n\nsecond paragraph!"
expected = "hello world!
second paragraph!"
- output = Utils.format_input(text, [], [], "text/plain")
+ {output, [], []} = Utils.format_input(text, "text/plain")
assert output == expected
end
@@ -78,14 +78,14 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
text = "hello world!
"
expected = "hello world!
"
- output = Utils.format_input(text, [], [], "text/html")
+ {output, [], []} = Utils.format_input(text, "text/html")
assert output == expected
text = "hello world!
\n\nsecond paragraph
"
expected = "hello world!
\n\nsecond paragraph
"
- output = Utils.format_input(text, [], [], "text/html")
+ {output, [], []} = Utils.format_input(text, "text/html")
assert output == expected
end
@@ -94,14 +94,32 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
text = "**hello world**"
expected = "hello world
\n"
- output = Utils.format_input(text, [], [], "text/markdown")
+ {output, [], []} = Utils.format_input(text, "text/markdown")
assert output == expected
text = "**hello world**\n\n*another paragraph*"
expected = "hello world
\nanother paragraph
\n"
- output = Utils.format_input(text, [], [], "text/markdown")
+ {output, [], []} = Utils.format_input(text, "text/markdown")
+
+ assert output == expected
+ end
+
+ test "works for text/markdown with mentions" do
+ {:ok, user} =
+ UserBuilder.insert(%{nickname: "user__test", ap_id: "http://foo.com/user__test"})
+
+ text = "**hello world**\n\n*another @user__test and @user__test google.com paragraph*"
+
+ expected =
+ "hello world
\nanother @user__test and @user__test google.com paragraph
\n"
+
+ {output, _, _} = Utils.format_input(text, "text/markdown")
assert output == expected
end
--
cgit v1.2.3
From 5d961d536cd190c8201d53624680a6f3384ffd9b Mon Sep 17 00:00:00 2001
From: Egor Kislitsyn
Date: Wed, 27 Feb 2019 15:40:30 +0700
Subject: fix formatter
---
test/web/common_api/common_api_utils_test.exs | 18 +++++++++++++++---
1 file changed, 15 insertions(+), 3 deletions(-)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs
index dc7b4c229..684f2a23f 100644
--- a/test/web/common_api/common_api_utils_test.exs
+++ b/test/web/common_api/common_api_utils_test.exs
@@ -104,6 +104,18 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
{output, [], []} = Utils.format_input(text, "text/markdown")
assert output == expected
+
+ text = """
+ > cool quote
+
+ by someone
+ """
+
+ expected = "cool quote
\n
\nby someone
\n"
+
+ {output, [], []} = Utils.format_input(text, "text/markdown")
+
+ assert output == expected
end
test "works for text/markdown with mentions" do
@@ -113,11 +125,11 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
text = "**hello world**\n\n*another @user__test and @user__test google.com paragraph*"
expected =
- "hello world
\nanother @user__test and @user__test google.com paragraph
\n"
+ }\" class=\"u-url mention\" href=\"http://foo.com/user__test\">@user__test google.com paragraph
\n"
{output, _, _} = Utils.format_input(text, "text/markdown")
--
cgit v1.2.3
From a3a9cec4835738216800d2cebd295fb8dbf10f34 Mon Sep 17 00:00:00 2001
From: "Haelwenn (lanodan) Monnier"
Date: Tue, 5 Mar 2019 03:52:23 +0100
Subject: [Credo] fix Credo.Check.Readability.AliasOrder
---
test/web/common_api/common_api_test.exs | 4 ++--
test/web/common_api/common_api_utils_test.exs | 2 +-
2 files changed, 3 insertions(+), 3 deletions(-)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 9ba320f59..181813c76 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -4,9 +4,9 @@
defmodule Pleroma.Web.CommonAPITest do
use Pleroma.DataCase
- alias Pleroma.Web.CommonAPI
- alias Pleroma.User
alias Pleroma.Activity
+ alias Pleroma.User
+ alias Pleroma.Web.CommonAPI
import Pleroma.Factory
diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs
index 684f2a23f..4c97b0d62 100644
--- a/test/web/common_api/common_api_utils_test.exs
+++ b/test/web/common_api/common_api_utils_test.exs
@@ -3,9 +3,9 @@
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.CommonAPI.UtilsTest do
+ alias Pleroma.Builders.UserBuilder
alias Pleroma.Web.CommonAPI.Utils
alias Pleroma.Web.Endpoint
- alias Pleroma.Builders.UserBuilder
use Pleroma.DataCase
test "it adds attachment links to a given text and attachment set" do
--
cgit v1.2.3
From da53c079db91ce5d7ba14809f5e99b10d3ae307a Mon Sep 17 00:00:00 2001
From: Karen Konou
Date: Fri, 15 Mar 2019 14:06:58 +0100
Subject: Refactor to store user ap_id, add tests
---
test/web/common_api/common_api_test.exs | 23 +++++++++++++++++++++++
1 file changed, 23 insertions(+)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index 181813c76..f83f80b40 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -221,4 +221,27 @@ defmodule Pleroma.Web.CommonAPITest do
} = flag_activity
end
end
+
+ describe "reblog muting" do
+ setup do
+ muter = insert(:user)
+
+ muted = insert(:user)
+
+ [muter: muter, muted: muted]
+ end
+
+ test "add a reblog mute", %{muter: muter, muted: muted} do
+ {:ok, muter} = CommonAPI.hide_reblogs(muter, muted)
+
+ assert Pleroma.User.showing_reblogs?(muter, muted) == false
+ end
+
+ test "remove a reblog mute", %{muter: muter, muted: muted} do
+ {:ok, muter} = CommonAPI.hide_reblogs(muter, muted)
+ {:ok, muter} = CommonAPI.show_reblogs(muter, muted)
+
+ assert Pleroma.User.showing_reblogs?(muter, muted) == true
+ end
+ end
end
--
cgit v1.2.3
From 8468f3f6d48693d2a27a257e5555aa71decff3df Mon Sep 17 00:00:00 2001
From: lain
Date: Wed, 20 Mar 2019 21:09:36 +0100
Subject: Add safe dm mode option.
---
test/web/common_api/common_api_test.exs | 18 ++++++++++++++++++
1 file changed, 18 insertions(+)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index f83f80b40..34aa5bf18 100644
--- a/test/web/common_api/common_api_test.exs
+++ b/test/web/common_api/common_api_test.exs
@@ -10,6 +10,24 @@ defmodule Pleroma.Web.CommonAPITest do
import Pleroma.Factory
+ test "with the safe_dm_mention option set, it does not mention people beyond the initial tags" do
+ har = insert(:user)
+ jafnhar = insert(:user)
+ tridi = insert(:user)
+ option = Pleroma.Config.get([:instance, :safe_dm_mentions])
+ Pleroma.Config.put([:instance, :safe_dm_mentions], true)
+
+ {:ok, activity} =
+ CommonAPI.post(har, %{
+ "status" => "@#{jafnhar.nickname} hey, i never want to see @#{tridi.nickname} again",
+ "visibility" => "direct"
+ })
+
+ refute tridi.ap_id in activity.recipients
+ assert jafnhar.ap_id in activity.recipients
+ Pleroma.Config.put([:instance, :safe_dm_mentions], option)
+ end
+
test "it de-duplicates tags" do
user = insert(:user)
{:ok, activity} = CommonAPI.post(user, %{"status" => "#2hu #2HU"})
--
cgit v1.2.3
From fea36967999fed5399ab3533e806e4cbc990ad05 Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Thu, 21 Mar 2019 23:17:53 +0000
Subject: common api: move context functions from twitterapi
---
test/web/common_api/common_api_utils_test.exs | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs
index 4c97b0d62..d095762ab 100644
--- a/test/web/common_api/common_api_utils_test.exs
+++ b/test/web/common_api/common_api_utils_test.exs
@@ -136,4 +136,20 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
assert output == expected
end
end
+
+ describe "context_to_conversation_id" do
+ test "creates a mapping object" do
+ conversation_id = Utils.context_to_conversation_id("random context")
+ object = Object.get_by_ap_id("random context")
+
+ assert conversation_id == object.id
+ end
+
+ test "returns an existing mapping for an existing object" do
+ {:ok, object} = Object.context_mapping("random context") |> Repo.insert()
+ conversation_id = Utils.context_to_conversation_id("random context")
+
+ assert conversation_id == object.id
+ end
+ end
end
--
cgit v1.2.3
From a223e65f35da158ef79f05f65316920dcecaa54b Mon Sep 17 00:00:00 2001
From: William Pitcock
Date: Thu, 21 Mar 2019 23:37:00 +0000
Subject: tests: fixup
---
test/web/common_api/common_api_utils_test.exs | 1 +
1 file changed, 1 insertion(+)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs
index d095762ab..e04b9f9b5 100644
--- a/test/web/common_api/common_api_utils_test.exs
+++ b/test/web/common_api/common_api_utils_test.exs
@@ -4,6 +4,7 @@
defmodule Pleroma.Web.CommonAPI.UtilsTest do
alias Pleroma.Builders.UserBuilder
+ alias Pleroma.Object
alias Pleroma.Web.CommonAPI.Utils
alias Pleroma.Web.Endpoint
use Pleroma.DataCase
--
cgit v1.2.3
From b6f9f7b8aa659c10049b8c43326e58a4b1b18664 Mon Sep 17 00:00:00 2001
From: Sergey Suprunenko
Date: Mon, 1 Apr 2019 22:40:48 +0200
Subject: Handle dates in the Unix timestamp format (Fixes #763)
---
test/web/common_api/common_api_utils_test.exs | 37 +++++++++++++++++++++++++++
1 file changed, 37 insertions(+)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs
index e04b9f9b5..0f8b28d9c 100644
--- a/test/web/common_api/common_api_utils_test.exs
+++ b/test/web/common_api/common_api_utils_test.exs
@@ -153,4 +153,41 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
assert conversation_id == object.id
end
end
+
+ describe "formats date to asctime" do
+ test "when date is an integer Unix timestamp" do
+ date = DateTime.utc_now() |> DateTime.to_unix()
+
+ expected =
+ date
+ |> DateTime.from_unix!()
+ |> Calendar.Strftime.strftime!("%a %b %d %H:%M:%S %z %Y")
+
+ assert Utils.date_to_asctime(date) == expected
+ end
+
+ test "when date is a float Unix timestamp" do
+ date = 1_553_808_404.602961
+
+ expected =
+ date
+ |> trunc()
+ |> DateTime.from_unix!()
+ |> Calendar.Strftime.strftime!("%a %b %d %H:%M:%S %z %Y")
+
+ assert Utils.date_to_asctime(date) == expected
+ end
+
+ test "when date is in ISO 8601 format" do
+ date = DateTime.utc_now() |> DateTime.to_iso8601()
+
+ expected =
+ date
+ |> DateTime.from_iso8601()
+ |> elem(1)
+ |> Calendar.Strftime.strftime!("%a %b %d %H:%M:%S %z %Y")
+
+ assert Utils.date_to_asctime(date) == expected
+ end
+ end
end
--
cgit v1.2.3
From 3db923515057b7da23e4bb58a1696cd14df7ed52 Mon Sep 17 00:00:00 2001
From: Sergey Suprunenko
Date: Tue, 2 Apr 2019 11:25:51 +0200
Subject: Ignore dates in wrong formats
---
test/web/common_api/common_api_utils_test.exs | 33 +++++++++++++--------------
1 file changed, 16 insertions(+), 17 deletions(-)
(limited to 'test/web/common_api')
diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs
index 0f8b28d9c..f0c59d5c3 100644
--- a/test/web/common_api/common_api_utils_test.exs
+++ b/test/web/common_api/common_api_utils_test.exs
@@ -155,39 +155,38 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do
end
describe "formats date to asctime" do
- test "when date is an integer Unix timestamp" do
- date = DateTime.utc_now() |> DateTime.to_unix()
+ test "when date is in ISO 8601 format" do
+ date = DateTime.utc_now() |> DateTime.to_iso8601()
expected =
date
- |> DateTime.from_unix!()
+ |> DateTime.from_iso8601()
+ |> elem(1)
|> Calendar.Strftime.strftime!("%a %b %d %H:%M:%S %z %Y")
assert Utils.date_to_asctime(date) == expected
end
- test "when date is a float Unix timestamp" do
- date = 1_553_808_404.602961
+ test "when date is a binary in wrong format" do
+ date = DateTime.utc_now()
- expected =
- date
- |> trunc()
- |> DateTime.from_unix!()
- |> Calendar.Strftime.strftime!("%a %b %d %H:%M:%S %z %Y")
+ expected = ""
assert Utils.date_to_asctime(date) == expected
end
- test "when date is in ISO 8601 format" do
- date = DateTime.utc_now() |> DateTime.to_iso8601()
+ test "when date is a Unix timestamp" do
+ date = DateTime.utc_now() |> DateTime.to_unix()
- expected =
- date
- |> DateTime.from_iso8601()
- |> elem(1)
- |> Calendar.Strftime.strftime!("%a %b %d %H:%M:%S %z %Y")
+ expected = ""
assert Utils.date_to_asctime(date) == expected
end
+
+ test "when date is nil" do
+ expected = ""
+
+ assert Utils.date_to_asctime(nil) == expected
+ end
end
end
--
cgit v1.2.3