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 assert {:ok, %Activity{} = activity} = Relay.unfollow(user.ap_id)
47 assert activity.actor == "#{Pleroma.Web.Endpoint.url()}/relay"
48 assert user.ap_id in activity.recipients
49 assert activity.data["type"] == "Undo"
50 assert activity.data["actor"] == service_actor.ap_id
51 assert activity.data["to"] == [user.ap_id]
55 describe "publish/1" do
56 test "returns error when activity not `Create` type" do
57 activity = insert(:like_activity)
58 assert Relay.publish(activity) == {:error, "Not implemented"}
61 test "returns error when activity not public" do
62 activity = insert(:direct_note_activity)
63 assert Relay.publish(activity) == {:error, false}
66 test "returns announce activity" do
67 service_actor = Relay.get_actor()
68 note = insert(:note_activity)
69 assert {:ok, %Activity{} = activity, %Object{} = obj} = Relay.publish(note)
70 assert activity.data["type"] == "Announce"
71 assert activity.data["actor"] == service_actor.ap_id
72 assert activity.data["object"] == obj.data["id"]