1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2018 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ActivityPub.RelayTest do
10 alias Pleroma.Web.ActivityPub.ActivityPub
11 alias Pleroma.Web.ActivityPub.Relay
13 import Pleroma.Factory
15 test "gets an actor for the relay" do
16 user = Relay.get_actor()
17 assert user.ap_id == "#{Pleroma.Web.Endpoint.url()}/relay"
20 describe "follow/1" do
21 test "returns errors when user not found" do
22 assert Relay.follow("test-ap-id") == {:error, "Could not fetch by AP id"}
25 test "returns activity" do
27 service_actor = Relay.get_actor()
28 assert {:ok, %Activity{} = activity} = Relay.follow(user.ap_id)
29 assert activity.actor == "#{Pleroma.Web.Endpoint.url()}/relay"
30 assert user.ap_id in activity.recipients
31 assert activity.data["type"] == "Follow"
32 assert activity.data["actor"] == service_actor.ap_id
33 assert activity.data["object"] == user.ap_id
37 describe "unfollow/1" do
38 test "returns errors when user not found" do
39 assert Relay.unfollow("test-ap-id") == {:error, "Could not fetch by AP id"}
42 test "returns activity" do
44 service_actor = Relay.get_actor()
45 ActivityPub.follow(service_actor, user)
46 Pleroma.User.follow(service_actor, user)
47 assert "#{user.ap_id}/followers" in refresh_record(service_actor).following
48 assert {:ok, %Activity{} = activity} = Relay.unfollow(user.ap_id)
49 assert activity.actor == "#{Pleroma.Web.Endpoint.url()}/relay"
50 assert user.ap_id in activity.recipients
51 assert activity.data["type"] == "Undo"
52 assert activity.data["actor"] == service_actor.ap_id
53 assert activity.data["to"] == [user.ap_id]
54 refute "#{user.ap_id}/followers" in refresh_record(service_actor).following
58 describe "publish/1" do
59 test "returns error when activity not `Create` type" do
60 activity = insert(:like_activity)
61 assert Relay.publish(activity) == {:error, "Not implemented"}
64 test "returns error when activity not public" do
65 activity = insert(:direct_note_activity)
66 assert Relay.publish(activity) == {:error, false}
69 test "returns announce activity" do
70 service_actor = Relay.get_actor()
71 note = insert(:note_activity)
72 assert {:ok, %Activity{} = activity, %Object{} = obj} = Relay.publish(note)
73 assert activity.data["type"] == "Announce"
74 assert activity.data["actor"] == service_actor.ap_id
75 assert activity.data["object"] == obj.data["id"]