X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Fweb%2Fcommon_api%2Fcommon_api_test.exs;h=a7d9e61613b6f94785e3cf3298dcc5e4de4cc1e2;hb=501fba33d6bb02cca586cfeeac9fdcfec5c7436d;hp=c3674711aee7e7cfd5daa65bd7c53856790ca089;hpb=b73a1a33de76dc848037a5d0e951866bd21f92c4;p=akkoma
diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs
index c3674711a..a7d9e6161 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
@@ -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:"})
@@ -96,4 +103,65 @@ 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)
+
+ 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
+ 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)
+
+ 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 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