diff options
| author | lain <lain@soykaf.club> | 2019-04-08 14:10:51 +0200 | 
|---|---|---|
| committer | lain <lain@soykaf.club> | 2019-04-08 14:10:51 +0200 | 
| commit | a9f805c87100fd2ee1d8426460b81af4a235d574 (patch) | |
| tree | 70179175f0ff84f3f4c7399f63694766aaa65b35 /test/web/activity_pub | |
| parent | 5d871173d189a0019fda0ee76f8a324d90a163ee (diff) | |
| parent | 4977e96fa408e8148a355b3c759af34ae3ca312d (diff) | |
| download | pleroma-a9f805c87100fd2ee1d8426460b81af4a235d574.tar.gz pleroma-a9f805c87100fd2ee1d8426460b81af4a235d574.zip | |
Merge remote-tracking branch 'origin/develop' into features/mastoapi/2.6.0-conversations
Diffstat (limited to 'test/web/activity_pub')
| -rw-r--r-- | test/web/activity_pub/activity_pub_controller_test.exs | 9 | ||||
| -rw-r--r-- | test/web/activity_pub/activity_pub_test.exs | 40 | ||||
| -rw-r--r-- | test/web/activity_pub/transmogrifier_test.exs | 31 | ||||
| -rw-r--r-- | test/web/activity_pub/utils_test.exs | 36 | 
4 files changed, 69 insertions, 47 deletions
| diff --git a/test/web/activity_pub/activity_pub_controller_test.exs b/test/web/activity_pub/activity_pub_controller_test.exs index a1e83b380..8dd8e7e0a 100644 --- a/test/web/activity_pub/activity_pub_controller_test.exs +++ b/test/web/activity_pub/activity_pub_controller_test.exs @@ -8,7 +8,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do    alias Pleroma.Activity    alias Pleroma.Instances    alias Pleroma.Object -  alias Pleroma.Repo    alias Pleroma.User    alias Pleroma.Web.ActivityPub.ObjectView    alias Pleroma.Web.ActivityPub.UserView @@ -51,7 +50,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do          |> put_req_header("accept", "application/json")          |> get("/users/#{user.nickname}") -      user = Repo.get(User, user.id) +      user = User.get_by_id(user.id)        assert json_response(conn, 200) == UserView.render("user.json", %{user: user})      end @@ -66,7 +65,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do          |> put_req_header("accept", "application/activity+json")          |> get("/users/#{user.nickname}") -      user = Repo.get(User, user.id) +      user = User.get_by_id(user.id)        assert json_response(conn, 200) == UserView.render("user.json", %{user: user})      end @@ -84,7 +83,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do          )          |> get("/users/#{user.nickname}") -      user = Repo.get(User, user.id) +      user = User.get_by_id(user.id)        assert json_response(conn, 200) == UserView.render("user.json", %{user: user})      end @@ -543,7 +542,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubControllerTest do        user = insert(:user)        Enum.each(1..15, fn _ -> -        user = Repo.get(User, user.id) +        user = User.get_by_id(user.id)          other_user = insert(:user)          User.follow(user, other_user)        end) diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index ac5fbe0a9..17fec05b1 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -218,18 +218,18 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do        user = insert(:user)        {:ok, _} = -        CommonAPI.post(Repo.get(User, user.id), %{"status" => "1", "visibility" => "public"}) +        CommonAPI.post(User.get_by_id(user.id), %{"status" => "1", "visibility" => "public"})        {:ok, _} = -        CommonAPI.post(Repo.get(User, user.id), %{"status" => "2", "visibility" => "unlisted"}) +        CommonAPI.post(User.get_by_id(user.id), %{"status" => "2", "visibility" => "unlisted"})        {:ok, _} = -        CommonAPI.post(Repo.get(User, user.id), %{"status" => "2", "visibility" => "private"}) +        CommonAPI.post(User.get_by_id(user.id), %{"status" => "2", "visibility" => "private"})        {:ok, _} = -        CommonAPI.post(Repo.get(User, user.id), %{"status" => "3", "visibility" => "direct"}) +        CommonAPI.post(User.get_by_id(user.id), %{"status" => "3", "visibility" => "direct"}) -      user = Repo.get(User, user.id) +      user = User.get_by_id(user.id)        assert user.info.note_count == 2      end @@ -322,7 +322,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do      {:ok, user} = User.block(user, %{ap_id: activity_three.data["actor"]})      {:ok, _announce, %{data: %{"id" => id}}} = CommonAPI.repeat(activity_three.id, booster)      %Activity{} = boost_activity = Activity.get_create_by_object_ap_id(id) -    activity_three = Repo.get(Activity, activity_three.id) +    activity_three = Activity.get_by_id(activity_three.id)      activities =        ActivityPub.fetch_activities([], %{"blocking_user" => user, "skip_preload" => true}) @@ -380,7 +380,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do      {:ok, user} = User.mute(user, %User{ap_id: activity_three.data["actor"]})      {:ok, _announce, %{data: %{"id" => id}}} = CommonAPI.repeat(activity_three.id, booster)      %Activity{} = boost_activity = Activity.get_create_by_object_ap_id(id) -    activity_three = Repo.get(Activity, activity_three.id) +    activity_three = Activity.get_by_id(activity_three.id)      activities =        ActivityPub.fetch_activities([], %{"muting_user" => user, "skip_preload" => true}) @@ -559,7 +559,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do        {:ok, _, _, object} = ActivityPub.unlike(user, object)        assert object.data["like_count"] == 0 -      assert Repo.get(Activity, like_activity.id) == nil +      assert Activity.get_by_id(like_activity.id) == nil      end    end @@ -610,7 +610,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do        assert unannounce_activity.data["actor"] == user.ap_id        assert unannounce_activity.data["context"] == announce_activity.data["context"] -      assert Repo.get(Activity, announce_activity.id) == nil +      assert Activity.get_by_id(announce_activity.id) == nil      end    end @@ -635,16 +635,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do      end    end -  describe "fetch the latest Follow" do -    test "fetches the latest Follow activity" do -      %Activity{data: %{"type" => "Follow"}} = activity = insert(:follow_activity) -      follower = Repo.get_by(User, ap_id: activity.data["actor"]) -      followed = Repo.get_by(User, ap_id: activity.data["object"]) - -      assert activity == Utils.fetch_latest_follow(follower, followed) -    end -  end -    describe "fetching an object" do      test "it fetches an object" do        {:ok, object} = @@ -749,7 +739,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do        assert delete.data["actor"] == note.data["actor"]        assert delete.data["object"] == note.data["object"]["id"] -      assert Repo.get(Activity, delete.id) != nil +      assert Activity.get_by_id(delete.id) != nil        assert Repo.get(Object, object.id).data["type"] == "Tombstone"      end @@ -758,23 +748,23 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do        user = insert(:user, info: %{note_count: 10})        {:ok, a1} = -        CommonAPI.post(Repo.get(User, user.id), %{"status" => "yeah", "visibility" => "public"}) +        CommonAPI.post(User.get_by_id(user.id), %{"status" => "yeah", "visibility" => "public"})        {:ok, a2} = -        CommonAPI.post(Repo.get(User, user.id), %{"status" => "yeah", "visibility" => "unlisted"}) +        CommonAPI.post(User.get_by_id(user.id), %{"status" => "yeah", "visibility" => "unlisted"})        {:ok, a3} = -        CommonAPI.post(Repo.get(User, user.id), %{"status" => "yeah", "visibility" => "private"}) +        CommonAPI.post(User.get_by_id(user.id), %{"status" => "yeah", "visibility" => "private"})        {:ok, a4} = -        CommonAPI.post(Repo.get(User, user.id), %{"status" => "yeah", "visibility" => "direct"}) +        CommonAPI.post(User.get_by_id(user.id), %{"status" => "yeah", "visibility" => "direct"})        {:ok, _} = a1.data["object"]["id"] |> Object.get_by_ap_id() |> ActivityPub.delete()        {:ok, _} = a2.data["object"]["id"] |> Object.get_by_ap_id() |> ActivityPub.delete()        {:ok, _} = a3.data["object"]["id"] |> Object.get_by_ap_id() |> ActivityPub.delete()        {:ok, _} = a4.data["object"]["id"] |> Object.get_by_ap_id() |> ActivityPub.delete() -      user = Repo.get(User, user.id) +      user = User.get_by_id(user.id)        assert user.info.note_count == 10      end diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index 50e8e40bd..47cffe257 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -461,7 +461,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do        {:ok, %Activity{local: false}} = Transmogrifier.handle_incoming(data) -      refute Repo.get(Activity, activity.id) +      refute Activity.get_by_id(activity.id)      end      test "it fails for incoming deletes with spoofed origin" do @@ -481,7 +481,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do        :error = Transmogrifier.handle_incoming(data) -      assert Repo.get(Activity, activity.id) +      assert Activity.get_by_id(activity.id)      end      test "it works for incoming unannounces with an existing notice" do @@ -639,7 +639,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do        assert activity.data["object"] == follow_activity.data["id"] -      follower = Repo.get(User, follower.id) +      follower = User.get_by_id(follower.id)        assert User.following?(follower, followed) == true      end @@ -661,7 +661,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do        {:ok, activity} = Transmogrifier.handle_incoming(accept_data)        assert activity.data["object"] == follow_activity.data["id"] -      follower = Repo.get(User, follower.id) +      follower = User.get_by_id(follower.id)        assert User.following?(follower, followed) == true      end @@ -681,7 +681,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do        {:ok, activity} = Transmogrifier.handle_incoming(accept_data)        assert activity.data["object"] == follow_activity.data["id"] -      follower = Repo.get(User, follower.id) +      follower = User.get_by_id(follower.id)        assert User.following?(follower, followed) == true      end @@ -700,7 +700,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do        :error = Transmogrifier.handle_incoming(accept_data) -      follower = Repo.get(User, follower.id) +      follower = User.get_by_id(follower.id)        refute User.following?(follower, followed) == true      end @@ -719,7 +719,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do        :error = Transmogrifier.handle_incoming(accept_data) -      follower = Repo.get(User, follower.id) +      follower = User.get_by_id(follower.id)        refute User.following?(follower, followed) == true      end @@ -744,7 +744,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do        {:ok, activity} = Transmogrifier.handle_incoming(reject_data)        refute activity.local -      follower = Repo.get(User, follower.id) +      follower = User.get_by_id(follower.id)        assert User.following?(follower, followed) == false      end @@ -766,7 +766,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do        {:ok, %Activity{data: _}} = Transmogrifier.handle_incoming(reject_data) -      follower = Repo.get(User, follower.id) +      follower = User.get_by_id(follower.id)        assert User.following?(follower, followed) == false      end @@ -1020,7 +1020,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do        {:ok, unrelated_activity} = CommonAPI.post(user_two, %{"status" => "test"})        assert "http://localhost:4001/users/rye@niu.moe/followers" in activity.recipients -      user = Repo.get(User, user.id) +      user = User.get_by_id(user.id)        assert user.info.note_count == 1        {:ok, user} = Transmogrifier.upgrade_user_from_ap_id("https://niu.moe/users/rye") @@ -1028,13 +1028,10 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do        assert user.info.note_count == 1        assert user.follower_address == "https://niu.moe/users/rye/followers" -      # Wait for the background task -      :timer.sleep(1000) - -      user = Repo.get(User, user.id) +      user = User.get_by_id(user.id)        assert user.info.note_count == 1 -      activity = Repo.get(Activity, activity.id) +      activity = Activity.get_by_id(activity.id)        assert user.follower_address in activity.recipients        assert %{ @@ -1057,10 +1054,10 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do        refute "..." in activity.recipients -      unrelated_activity = Repo.get(Activity, unrelated_activity.id) +      unrelated_activity = Activity.get_by_id(unrelated_activity.id)        refute user.follower_address in unrelated_activity.recipients -      user_two = Repo.get(User, user_two.id) +      user_two = User.get_by_id(user_two.id)        assert user.follower_address in user_two.following        refute "..." in user_two.following      end diff --git a/test/web/activity_pub/utils_test.exs b/test/web/activity_pub/utils_test.exs index 2bd3ddf93..758214e68 100644 --- a/test/web/activity_pub/utils_test.exs +++ b/test/web/activity_pub/utils_test.exs @@ -1,10 +1,34 @@  defmodule Pleroma.Web.ActivityPub.UtilsTest do    use Pleroma.DataCase +  alias Pleroma.Activity +  alias Pleroma.Repo +  alias Pleroma.User +  alias Pleroma.Web.ActivityPub.ActivityPub    alias Pleroma.Web.ActivityPub.Utils    alias Pleroma.Web.CommonAPI    import Pleroma.Factory +  describe "fetch the latest Follow" do +    test "fetches the latest Follow activity" do +      %Activity{data: %{"type" => "Follow"}} = activity = insert(:follow_activity) +      follower = Repo.get_by(User, ap_id: activity.data["actor"]) +      followed = Repo.get_by(User, ap_id: activity.data["object"]) + +      assert activity == Utils.fetch_latest_follow(follower, followed) +    end +  end + +  describe "fetch the latest Block" do +    test "fetches the latest Block activity" do +      blocker = insert(:user) +      blocked = insert(:user) +      {:ok, activity} = ActivityPub.block(blocker, blocked) + +      assert activity == Utils.fetch_latest_block(blocker, blocked) +    end +  end +    describe "determine_explicit_mentions()" do      test "works with an object that has mentions" do        object = %{ @@ -169,4 +193,16 @@ defmodule Pleroma.Web.ActivityPub.UtilsTest do        assert Utils.fetch_ordered_collection("http://example.com/outbox", 5) == [0, 1]      end    end + +  test "make_json_ld_header/0" do +    assert Utils.make_json_ld_header() == %{ +             "@context" => [ +               "https://www.w3.org/ns/activitystreams", +               "http://localhost:4001/schemas/litepub-0.1.jsonld", +               %{ +                 "@language" => "und" +               } +             ] +           } +  end  end | 
