1 defmodule Pleroma.Web.ActivityPub.Transmogrifier.AddRemoveHandlingTest do
2 use Oban.Testing, repo: Pleroma.Repo
3 use Pleroma.DataCase, async: true
5 require Pleroma.Constants
10 alias Pleroma.Web.ActivityPub.Transmogrifier
12 test "it accepts Add/Remove activities" do
14 "test/fixtures/users_mock/user.json"
16 |> String.replace("{{nickname}}", "lain")
18 object_id = "c61d6733-e256-4fe1-ab13-1e369789423f"
21 "test/fixtures/statuses/note.json"
23 |> String.replace("{{nickname}}", "lain")
24 |> String.replace("{{object_id}}", object_id)
26 object_url = "https://example.com/objects/#{object_id}"
28 actor = "https://example.com/users/lain"
38 headers: [{"content-type", "application/activity+json"}]
48 headers: [{"content-type", "application/activity+json"}]
51 %{method: :get, url: "https://example.com/users/lain/collections/featured"} ->
55 "test/fixtures/users_mock/masto_featured.json"
57 |> String.replace("{{domain}}", "example.com")
58 |> String.replace("{{nickname}}", "lain"),
59 headers: [{"content-type", "application/activity+json"}]
64 "id" => "https://example.com/objects/d61d6733-e256-4fe1-ab13-1e369789423f",
66 "object" => object_url,
67 "target" => "https://example.com/users/lain/collections/featured",
69 "to" => [Pleroma.Constants.as_public()],
70 "cc" => ["https://example.com/users/lain/followers"],
75 assert {:ok, activity} = Transmogrifier.handle_incoming(message)
76 assert activity.data == message
77 user = User.get_cached_by_ap_id(actor)
78 assert user.pinned_objects[object_url]
81 "id" => "http://localhost:400/objects/d61d6733-e256-4fe1-ab13-1e369789423d",
83 "object" => object_url,
84 "target" => "https://example.com/users/lain/collections/featured",
86 "to" => [Pleroma.Constants.as_public()],
87 "cc" => ["https://example.com/users/lain/followers"],
92 assert {:ok, activity} = Transmogrifier.handle_incoming(remove)
93 assert activity.data == remove
95 user = refresh_record(user)
96 refute user.pinned_objects[object_url]
99 test "Add/Remove activities for remote users without featured address" do
100 user = insert(:user, local: false, domain: "example.com")
104 |> Ecto.Changeset.change(featured_address: nil)
107 %{host: host} = URI.parse(user.ap_id)
110 "test/fixtures/users_mock/user.json"
112 |> String.replace("{{nickname}}", user.nickname)
114 object_id = "c61d6733-e256-4fe1-ab13-1e369789423f"
117 "test/fixtures/statuses/note.json"
119 |> String.replace("{{nickname}}", user.nickname)
120 |> String.replace("{{object_id}}", object_id)
122 object_url = "https://#{host}/objects/#{object_id}"
124 actor = "https://#{host}/users/#{user.nickname}"
126 featured = "https://#{host}/users/#{user.nickname}/collections/featured"
136 headers: [{"content-type", "application/activity+json"}]
146 headers: [{"content-type", "application/activity+json"}]
149 %{method: :get, url: ^featured} ->
153 "test/fixtures/users_mock/masto_featured.json"
155 |> String.replace("{{domain}}", "#{host}")
156 |> String.replace("{{nickname}}", user.nickname),
157 headers: [{"content-type", "application/activity+json"}]
162 "id" => "https://#{host}/objects/d61d6733-e256-4fe1-ab13-1e369789423f",
164 "object" => object_url,
165 "target" => "https://#{host}/users/#{user.nickname}/collections/featured",
167 "to" => [Pleroma.Constants.as_public()],
168 "cc" => ["https://#{host}/users/#{user.nickname}/followers"],
173 assert {:ok, activity} = Transmogrifier.handle_incoming(message)
174 assert activity.data == message
175 user = User.get_cached_by_ap_id(actor)
176 assert user.pinned_objects[object_url]