total rebase
[anni] / test / pleroma / web / activity_pub / mrf / force_mention_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2024 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ActivityPub.MRF.ForceMentionTest do
6   use Pleroma.DataCase
7   require Pleroma.Constants
8
9   alias Pleroma.Web.ActivityPub.MRF.ForceMention
10
11   import Pleroma.Factory
12
13   test "adds mention to a reply" do
14     lain =
15       insert(:user, ap_id: "https://lain.com/users/lain", nickname: "lain@lain.com", local: false)
16
17     niobleoum =
18       insert(:user,
19         ap_id: "https://www.minds.com/api/activitypub/users/1198929502760083472",
20         nickname: "niobleoum@minds.com",
21         local: false
22       )
23
24     status = File.read!("test/fixtures/minds-pleroma-mentioned-post.json") |> Jason.decode!()
25
26     status_activity = %{
27       "type" => "Create",
28       "actor" => lain.ap_id,
29       "object" => status
30     }
31
32     Pleroma.Web.ActivityPub.Transmogrifier.handle_incoming(status_activity)
33
34     reply = File.read!("test/fixtures/minds-invalid-mention-post.json") |> Jason.decode!()
35
36     reply_activity = %{
37       "type" => "Create",
38       "actor" => niobleoum.ap_id,
39       "object" => reply
40     }
41
42     {:ok, %{"object" => %{"tag" => tag}}} = ForceMention.filter(reply_activity)
43
44     assert Enum.find(tag, fn %{"href" => href} -> href == lain.ap_id end)
45   end
46
47   test "adds mention to a quote" do
48     user1 = insert(:user, ap_id: "https://misskey.io/users/83ssedkv53")
49     user2 = insert(:user, ap_id: "https://misskey.io/users/7rkrarq81i")
50
51     status = File.read!("test/fixtures/tesla_mock/misskey.io_8vs6wxufd0.json") |> Jason.decode!()
52
53     status_activity = %{
54       "type" => "Create",
55       "actor" => user1.ap_id,
56       "object" => status
57     }
58
59     Pleroma.Web.ActivityPub.Transmogrifier.handle_incoming(status_activity)
60
61     quote_post = File.read!("test/fixtures/quote_post/misskey_quote_post.json") |> Jason.decode!()
62
63     quote_activity = %{
64       "type" => "Create",
65       "actor" => user2.ap_id,
66       "object" => quote_post
67     }
68
69     {:ok, %{"object" => %{"tag" => tag}}} = ForceMention.filter(quote_activity)
70
71     assert Enum.find(tag, fn %{"href" => href} -> href == user1.ap_id end)
72   end
73 end