aeef91cda85ad1f53bccb9850c1c424e0606d689
[akkoma] / test / web / activity_pub / relay_test.exs
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
5 defmodule Pleroma.Web.ActivityPub.RelayTest do
6 use Pleroma.DataCase
7
8 alias Pleroma.Activity
9 alias Pleroma.Object
10 alias Pleroma.Web.ActivityPub.ActivityPub
11 alias Pleroma.Web.ActivityPub.Relay
12
13 import Pleroma.Factory
14
15 test "gets an actor for the relay" do
16 user = Relay.get_actor()
17 assert user.ap_id == "#{Pleroma.Web.Endpoint.url()}/relay"
18 end
19
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"}
23 end
24
25 test "returns activity" do
26 user = insert(:user)
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
34 end
35 end
36
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"}
40 end
41
42 test "returns activity" do
43 user = insert(:user)
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
55 end
56 end
57
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"}
62 end
63
64 test "returns error when activity not public" do
65 activity = insert(:direct_note_activity)
66 assert Relay.publish(activity) == {:error, false}
67 end
68
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"]
76 end
77 end
78 end