Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.1KB

  1. # Pleroma: A lightweight social networking server
  2. # Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
  3. # SPDX-License-Identifier: AGPL-3.0-only
  4. defmodule Mix.Tasks.Pleroma.RelayTest do
  5. alias Pleroma.Activity
  6. alias Pleroma.Web.ActivityPub.ActivityPub
  7. alias Pleroma.Web.ActivityPub.Utils
  8. alias Pleroma.Web.ActivityPub.Relay
  9. alias Pleroma.User
  10. use Pleroma.DataCase
  11. setup_all do
  12. Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
  13. Mix.shell(Mix.Shell.Process)
  14. on_exit(fn ->
  15. Mix.shell(Mix.Shell.IO)
  16. end)
  17. :ok
  18. end
  19. describe "running follow" do
  20. test "relay is followed" do
  21. target_instance = "http://mastodon.example.org/users/admin"
  22. Mix.Tasks.Pleroma.Relay.run(["follow", target_instance])
  23. local_user = Relay.get_actor()
  24. assert local_user.ap_id =~ "/relay"
  25. target_user = User.get_by_ap_id(target_instance)
  26. refute target_user.local
  27. activity = Utils.fetch_latest_follow(local_user, target_user)
  28. assert activity.data["type"] == "Follow"
  29. assert activity.data["actor"] == local_user.ap_id
  30. assert activity.data["object"] == target_user.ap_id
  31. end
  32. end
  33. describe "running unfollow" do
  34. test "relay is unfollowed" do
  35. target_instance = "http://mastodon.example.org/users/admin"
  36. Mix.Tasks.Pleroma.Relay.run(["follow", target_instance])
  37. %User{ap_id: follower_id} = local_user = Relay.get_actor()
  38. target_user = User.get_by_ap_id(target_instance)
  39. follow_activity = Utils.fetch_latest_follow(local_user, target_user)
  40. Mix.Tasks.Pleroma.Relay.run(["unfollow", target_instance])
  41. cancelled_activity = Activity.get_by_ap_id(follow_activity.data["id"])
  42. assert cancelled_activity.data["state"] == "cancelled"
  43. [undo_activity] =
  44. ActivityPub.fetch_activities([], %{
  45. "type" => "Undo",
  46. "actor_id" => follower_id,
  47. "limit" => 1
  48. })
  49. assert undo_activity.data["type"] == "Undo"
  50. assert undo_activity.data["actor"] == local_user.ap_id
  51. assert undo_activity.data["object"] == cancelled_activity.data
  52. end
  53. end
  54. end