diff options
| author | rinpatch <rinpatch@sdf.org> | 2020-01-30 22:16:55 +0300 | 
|---|---|---|
| committer | rinpatch <rinpatch@sdf.org> | 2020-01-30 22:16:55 +0300 | 
| commit | 5b62acf6e9a38f8d14a9fb37cc85e646fb0169e3 (patch) | |
| tree | 6677ba80418ffd34a78cba75498f2c1ab48ba14c /test/web/activity_pub | |
| parent | 45180d4c6058f790475d8ff28018c912db105082 (diff) | |
| parent | 946de2299cccebac6718e3a132397ff5c06c67ee (diff) | |
| download | pleroma-5b62acf6e9a38f8d14a9fb37cc85e646fb0169e3.tar.gz pleroma-5b62acf6e9a38f8d14a9fb37cc85e646fb0169e3.zip  | |
Merge branch 'develop' into fix/disable-rate-limiter-for-socket-localhost
Diffstat (limited to 'test/web/activity_pub')
| -rw-r--r-- | test/web/activity_pub/activity_pub_test.exs | 58 | ||||
| -rw-r--r-- | test/web/activity_pub/publisher_test.exs | 21 | ||||
| -rw-r--r-- | test/web/activity_pub/transmogrifier/follow_handling_test.exs | 2 | ||||
| -rw-r--r-- | test/web/activity_pub/utils_test.exs | 13 | 
4 files changed, 91 insertions, 3 deletions
diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index 1520c8a9b..ff4604a52 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -867,6 +867,8 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do      test "adds an emoji reaction activity to the db" do        user = insert(:user)        reactor = insert(:user) +      third_user = insert(:user) +      fourth_user = insert(:user)        {:ok, activity} = CommonAPI.post(user, %{"status" => "YASSSS queen slay"})        assert object = Object.normalize(activity) @@ -881,7 +883,21 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do        assert reaction_activity.data["to"] == [User.ap_followers(reactor), activity.data["actor"]]        assert reaction_activity.data["context"] == object.data["context"]        assert object.data["reaction_count"] == 1 -      assert object.data["reactions"]["🔥"] == [reactor.ap_id] +      assert object.data["reactions"] == [["🔥", [reactor.ap_id]]] + +      {:ok, _reaction_activity, object} = ActivityPub.react_with_emoji(third_user, object, "☕") + +      assert object.data["reaction_count"] == 2 +      assert object.data["reactions"] == [["🔥", [reactor.ap_id]], ["☕", [third_user.ap_id]]] + +      {:ok, _reaction_activity, object} = ActivityPub.react_with_emoji(fourth_user, object, "🔥") + +      assert object.data["reaction_count"] == 3 + +      assert object.data["reactions"] == [ +               ["🔥", [fourth_user.ap_id, reactor.ap_id]], +               ["☕", [third_user.ap_id]] +             ]      end    end @@ -919,7 +935,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do        object = Object.get_by_ap_id(object.data["id"])        assert object.data["reaction_count"] == 0 -      assert object.data["reactions"] == %{} +      assert object.data["reactions"] == []      end    end @@ -1623,6 +1639,44 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do        assert follow_info.following_count == 32        assert follow_info.hide_follows == true      end + +    test "doesn't crash when follower and following counters are hidden" do +      mock(fn env -> +        case env.url do +          "http://localhost:4001/users/masto_hidden_counters/following" -> +            json(%{ +              "@context" => "https://www.w3.org/ns/activitystreams", +              "id" => "http://localhost:4001/users/masto_hidden_counters/followers" +            }) + +          "http://localhost:4001/users/masto_hidden_counters/following?page=1" -> +            %Tesla.Env{status: 403, body: ""} + +          "http://localhost:4001/users/masto_hidden_counters/followers" -> +            json(%{ +              "@context" => "https://www.w3.org/ns/activitystreams", +              "id" => "http://localhost:4001/users/masto_hidden_counters/following" +            }) + +          "http://localhost:4001/users/masto_hidden_counters/followers?page=1" -> +            %Tesla.Env{status: 403, body: ""} +        end +      end) + +      user = +        insert(:user, +          local: false, +          follower_address: "http://localhost:4001/users/masto_hidden_counters/followers", +          following_address: "http://localhost:4001/users/masto_hidden_counters/following" +        ) + +      {:ok, follow_info} = ActivityPub.fetch_follow_information_for_user(user) + +      assert follow_info.hide_followers == true +      assert follow_info.follower_count == 0 +      assert follow_info.hide_follows == true +      assert follow_info.following_count == 0 +    end    end    describe "fetch_favourites/3" do diff --git a/test/web/activity_pub/publisher_test.exs b/test/web/activity_pub/publisher_test.exs index e885e5a5a..015af19ab 100644 --- a/test/web/activity_pub/publisher_test.exs +++ b/test/web/activity_pub/publisher_test.exs @@ -23,6 +23,27 @@ defmodule Pleroma.Web.ActivityPub.PublisherTest do      :ok    end +  describe "gather_webfinger_links/1" do +    test "it returns links" do +      user = insert(:user) + +      expected_links = [ +        %{"href" => user.ap_id, "rel" => "self", "type" => "application/activity+json"}, +        %{ +          "href" => user.ap_id, +          "rel" => "self", +          "type" => "application/ld+json; profile=\"https://www.w3.org/ns/activitystreams\"" +        }, +        %{ +          "rel" => "http://ostatus.org/schema/1.0/subscribe", +          "template" => "#{Pleroma.Web.base_url()}/ostatus_subscribe?acct={uri}" +        } +      ] + +      assert expected_links == Publisher.gather_webfinger_links(user) +    end +  end +    describe "determine_inbox/2" do      test "it returns sharedInbox for messages involving as:Public in to" do        user = diff --git a/test/web/activity_pub/transmogrifier/follow_handling_test.exs b/test/web/activity_pub/transmogrifier/follow_handling_test.exs index 7d6d0814d..1c88b05c2 100644 --- a/test/web/activity_pub/transmogrifier/follow_handling_test.exs +++ b/test/web/activity_pub/transmogrifier/follow_handling_test.exs @@ -78,7 +78,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.FollowHandlingTest do          )          |> Repo.all() -      assert length(accepts) == 0 +      assert Enum.empty?(accepts)      end      test "it works for follow requests when you are already followed, creating a new accept activity" do diff --git a/test/web/activity_pub/utils_test.exs b/test/web/activity_pub/utils_test.exs index 586eb1d2f..211fa6c95 100644 --- a/test/web/activity_pub/utils_test.exs +++ b/test/web/activity_pub/utils_test.exs @@ -636,4 +636,17 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do        assert updated_object.data["announcement_count"] == 1      end    end + +  describe "get_cached_emoji_reactions/1" do +    test "returns the data or an emtpy list" do +      object = insert(:note) +      assert Utils.get_cached_emoji_reactions(object) == [] + +      object = insert(:note, data: %{"reactions" => [["x", ["lain"]]]}) +      assert Utils.get_cached_emoji_reactions(object) == [["x", ["lain"]]] + +      object = insert(:note, data: %{"reactions" => %{}}) +      assert Utils.get_cached_emoji_reactions(object) == [] +    end +  end  end  | 
