diff options
Diffstat (limited to 'test/web/common_api')
| -rw-r--r-- | test/web/common_api/common_api_test.exs | 64 | ||||
| -rw-r--r-- | test/web/common_api/common_api_utils_test.exs | 6 | 
2 files changed, 66 insertions, 4 deletions
| diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs index f8963e42e..601c32954 100644 --- a/test/web/common_api/common_api_test.exs +++ b/test/web/common_api/common_api_test.exs @@ -68,6 +68,7 @@ defmodule Pleroma.Web.CommonAPITest do      har = insert(:user)      jafnhar = insert(:user)      tridi = insert(:user) +      Pleroma.Config.put([:instance, :safe_dm_mentions], true)      {:ok, activity} = @@ -238,7 +239,9 @@ defmodule Pleroma.Web.CommonAPITest do        assert reaction.data["actor"] == user.ap_id        assert reaction.data["content"] == "👍" -      # TODO: test error case. +      {:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"}) + +      {:error, _} = CommonAPI.react_with_emoji(activity.id, user, ".")      end      test "unreacting to a status with an emoji" do @@ -322,6 +325,21 @@ defmodule Pleroma.Web.CommonAPITest do        assert %User{pinned_activities: [^id]} = user      end +    test "pin poll", %{user: user} do +      {:ok, activity} = +        CommonAPI.post(user, %{ +          "status" => "How is fediverse today?", +          "poll" => %{"options" => ["Absolutely outstanding", "Not good"], "expires_in" => 20} +        }) + +      assert {:ok, ^activity} = CommonAPI.pin(activity.id, user) + +      id = activity.id +      user = refresh_record(user) + +      assert %User{pinned_activities: [^id]} = user +    end +      test "unlisted statuses can be pinned", %{user: user} do        {:ok, activity} = CommonAPI.post(user, %{"status" => "HI!!!", "visibility" => "unlisted"})        assert {:ok, ^activity} = CommonAPI.pin(activity.id, user) @@ -534,6 +552,50 @@ defmodule Pleroma.Web.CommonAPITest do        refute User.subscribed_to?(follower, followed)      end + +    test "cancels a pending follow for a local user" do +      follower = insert(:user) +      followed = insert(:user, locked: true) + +      assert {:ok, follower, followed, %{id: activity_id, data: %{"state" => "pending"}}} = +               CommonAPI.follow(follower, followed) + +      assert User.get_follow_state(follower, followed) == "pending" +      assert {:ok, follower} = CommonAPI.unfollow(follower, followed) +      assert User.get_follow_state(follower, followed) == nil + +      assert %{id: ^activity_id, data: %{"state" => "cancelled"}} = +               Pleroma.Web.ActivityPub.Utils.fetch_latest_follow(follower, followed) + +      assert %{ +               data: %{ +                 "type" => "Undo", +                 "object" => %{"type" => "Follow", "state" => "cancelled"} +               } +             } = Pleroma.Web.ActivityPub.Utils.fetch_latest_undo(follower) +    end + +    test "cancels a pending follow for a remote user" do +      follower = insert(:user) +      followed = insert(:user, locked: true, local: false, ap_enabled: true) + +      assert {:ok, follower, followed, %{id: activity_id, data: %{"state" => "pending"}}} = +               CommonAPI.follow(follower, followed) + +      assert User.get_follow_state(follower, followed) == "pending" +      assert {:ok, follower} = CommonAPI.unfollow(follower, followed) +      assert User.get_follow_state(follower, followed) == nil + +      assert %{id: ^activity_id, data: %{"state" => "cancelled"}} = +               Pleroma.Web.ActivityPub.Utils.fetch_latest_follow(follower, followed) + +      assert %{ +               data: %{ +                 "type" => "Undo", +                 "object" => %{"type" => "Follow", "state" => "cancelled"} +               } +             } = Pleroma.Web.ActivityPub.Utils.fetch_latest_undo(follower) +    end    end    describe "accept_follow_request/2" do diff --git a/test/web/common_api/common_api_utils_test.exs b/test/web/common_api/common_api_utils_test.exs index 4b761e039..848300ef3 100644 --- a/test/web/common_api/common_api_utils_test.exs +++ b/test/web/common_api/common_api_utils_test.exs @@ -575,11 +575,11 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do    end    describe "maybe_add_attachments/3" do -    test "returns parsed results when no_links is true" do +    test "returns parsed results when attachment_links is false" do        assert Utils.maybe_add_attachments(                 {"test", [], ["tags"]},                 [], -               true +               false               ) == {"test", [], ["tags"]}      end @@ -589,7 +589,7 @@ defmodule Pleroma.Web.CommonAPI.UtilsTest do        assert Utils.maybe_add_attachments(                 {"test", [], ["tags"]},                 [attachment], -               false +               true               ) == {                 "test<br><a href=\"SakuraPM.png\" class='attachment'>SakuraPM.png</a>",                 [], | 
