summaryrefslogtreecommitdiff
path: root/test/web/activity_pub/publisher_test.exs
blob: 2b15b3edcccd30c481957bac254d69d571efd28a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# Pleroma: A lightweight social networking server
# Copyright © 2019 Pleroma Authors <https://pleroma.social/>
# SPDX-License-Identifier: AGPL-3.0-only

defmodule Pleroma.Web.ActivityPub.PublisherTest do
  use Pleroma.DataCase

  import Pleroma.Factory

  alias Pleroma.Activity
  alias Pleroma.Web.ActivityPub.Publisher

  @as_public "https://www.w3.org/ns/activitystreams#Public"

  describe "determine_inbox/2" do
    test "it returns sharedInbox for messages involving as:Public in to" do
      user =
        insert(:user, %{
          info: %{source_data: %{"endpoints" => %{"sharedInbox" => "http://example.com/inbox"}}}
        })

      activity = %Activity{
        data: %{"to" => [@as_public], "cc" => [user.follower_address]}
      }

      assert Publisher.determine_inbox(activity, user) == "http://example.com/inbox"
    end

    test "it returns sharedInbox for messages involving as:Public in cc" do
      user =
        insert(:user, %{
          info: %{source_data: %{"endpoints" => %{"sharedInbox" => "http://example.com/inbox"}}}
        })

      activity = %Activity{
        data: %{"cc" => [@as_public], "to" => [user.follower_address]}
      }

      assert Publisher.determine_inbox(activity, user) == "http://example.com/inbox"
    end

    test "it returns sharedInbox for messages involving multiple recipients in to" do
      user =
        insert(:user, %{
          info: %{source_data: %{"endpoints" => %{"sharedInbox" => "http://example.com/inbox"}}}
        })

      user_two = insert(:user)
      user_three = insert(:user)

      activity = %Activity{
        data: %{"cc" => [], "to" => [user.ap_id, user_two.ap_id, user_three.ap_id]}
      }

      assert Publisher.determine_inbox(activity, user) == "http://example.com/inbox"
    end

    test "it returns sharedInbox for messages involving multiple recipients in cc" do
      user =
        insert(:user, %{
          info: %{source_data: %{"endpoints" => %{"sharedInbox" => "http://example.com/inbox"}}}
        })

      user_two = insert(:user)
      user_three = insert(:user)

      activity = %Activity{
        data: %{"to" => [], "cc" => [user.ap_id, user_two.ap_id, user_three.ap_id]}
      }

      assert Publisher.determine_inbox(activity, user) == "http://example.com/inbox"
    end

    test "it returns sharedInbox for messages involving multiple recipients in total" do
      user =
        insert(:user, %{
          info: %{
            source_data: %{
              "inbox" => "http://example.com/personal-inbox",
              "endpoints" => %{"sharedInbox" => "http://example.com/inbox"}
            }
          }
        })

      user_two = insert(:user)

      activity = %Activity{
        data: %{"to" => [user_two.ap_id], "cc" => [user.ap_id]}
      }

      assert Publisher.determine_inbox(activity, user) == "http://example.com/inbox"
    end

    test "it returns inbox for messages involving single recipients in total" do
      user =
        insert(:user, %{
          info: %{
            source_data: %{
              "inbox" => "http://example.com/personal-inbox",
              "endpoints" => %{"sharedInbox" => "http://example.com/inbox"}
            }
          }
        })

      activity = %Activity{
        data: %{"to" => [user.ap_id], "cc" => []}
      }

      assert Publisher.determine_inbox(activity, user) == "http://example.com/personal-inbox"
    end
  end
end