1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ActivityPub.Transmogrifier.AddRemoveHandlingTest do
6 use Oban.Testing, repo: Pleroma.Repo
7 use Pleroma.DataCase, async: true
9 require Pleroma.Constants
11 import Pleroma.Factory
14 alias Pleroma.Web.ActivityPub.Transmogrifier
16 test "it accepts Add/Remove activities" do
18 "test/fixtures/users_mock/user.json"
20 |> String.replace("{{nickname}}", "lain")
22 object_id = "c61d6733-e256-4fe1-ab13-1e369789423f"
25 "test/fixtures/statuses/note.json"
27 |> String.replace("{{nickname}}", "lain")
28 |> String.replace("{{object_id}}", object_id)
30 object_url = "https://example.com/objects/#{object_id}"
32 actor = "https://example.com/users/lain"
42 headers: [{"content-type", "application/activity+json"}]
52 headers: [{"content-type", "application/activity+json"}]
55 %{method: :get, url: "https://example.com/users/lain/collections/featured"} ->
59 "test/fixtures/users_mock/masto_featured.json"
61 |> String.replace("{{domain}}", "example.com")
62 |> String.replace("{{nickname}}", "lain"),
63 headers: [{"content-type", "application/activity+json"}]
68 "id" => "https://example.com/objects/d61d6733-e256-4fe1-ab13-1e369789423f",
70 "object" => object_url,
71 "target" => "https://example.com/users/lain/collections/featured",
73 "to" => [Pleroma.Constants.as_public()],
74 "cc" => ["https://example.com/users/lain/followers"],
79 assert {:ok, activity} = Transmogrifier.handle_incoming(message)
80 assert activity.data == message
81 user = User.get_cached_by_ap_id(actor)
82 assert user.pinned_objects[object_url]
85 "id" => "http://localhost:400/objects/d61d6733-e256-4fe1-ab13-1e369789423d",
87 "object" => object_url,
88 "target" => "https://example.com/users/lain/collections/featured",
90 "to" => [Pleroma.Constants.as_public()],
91 "cc" => ["https://example.com/users/lain/followers"],
96 assert {:ok, activity} = Transmogrifier.handle_incoming(remove)
97 assert activity.data == remove
99 user = refresh_record(user)
100 refute user.pinned_objects[object_url]
103 test "Add/Remove activities for remote users without featured address" do
104 user = insert(:user, local: false, domain: "example.com")
108 |> Ecto.Changeset.change(featured_address: nil)
111 %{host: host} = URI.parse(user.ap_id)
114 "test/fixtures/users_mock/user.json"
116 |> String.replace("{{nickname}}", user.nickname)
118 object_id = "c61d6733-e256-4fe1-ab13-1e369789423f"
121 "test/fixtures/statuses/note.json"
123 |> String.replace("{{nickname}}", user.nickname)
124 |> String.replace("{{object_id}}", object_id)
126 object_url = "https://#{host}/objects/#{object_id}"
128 actor = "https://#{host}/users/#{user.nickname}"
130 featured = "https://#{host}/users/#{user.nickname}/collections/featured"
140 headers: [{"content-type", "application/activity+json"}]
150 headers: [{"content-type", "application/activity+json"}]
153 %{method: :get, url: ^featured} ->
157 "test/fixtures/users_mock/masto_featured.json"
159 |> String.replace("{{domain}}", "#{host}")
160 |> String.replace("{{nickname}}", user.nickname),
161 headers: [{"content-type", "application/activity+json"}]
166 "id" => "https://#{host}/objects/d61d6733-e256-4fe1-ab13-1e369789423f",
168 "object" => object_url,
169 "target" => "https://#{host}/users/#{user.nickname}/collections/featured",
171 "to" => [Pleroma.Constants.as_public()],
172 "cc" => ["https://#{host}/users/#{user.nickname}/followers"],
177 assert {:ok, activity} = Transmogrifier.handle_incoming(message)
178 assert activity.data == message
179 user = User.get_cached_by_ap_id(actor)
180 assert user.pinned_objects[object_url]