Quote posting (#113)
[akkoma] / test / pleroma / web / activity_pub / mrf / inline_quote_policy_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ActivityPub.MRF.InlineQuotePolicyTest do
6 alias Pleroma.Web.ActivityPub.MRF.InlineQuotePolicy
7 use Pleroma.DataCase
8
9 test "adds quote URL to post content" do
10 quote_url = "https://example.com/objects/1234"
11
12 activity = %{
13 "type" => "Create",
14 "actor" => "https://example.com/users/alex",
15 "object" => %{
16 "type" => "Note",
17 "content" => "<p>Nice post</p>",
18 "quoteUri" => quote_url
19 }
20 }
21
22 {:ok, %{"object" => %{"content" => filtered}}} = InlineQuotePolicy.filter(activity)
23
24 assert filtered ==
25 "<p>Nice post<span class=\"quote-inline\"><br/><br/>RE: <a href=\"https://example.com/objects/1234\">https://example.com/objects/1234</a></span></p>"
26 end
27
28 test "ignores Misskey quote posts" do
29 object = File.read!("test/fixtures/quote_post/misskey_quote_post.json") |> Jason.decode!()
30
31 activity = %{
32 "type" => "Create",
33 "actor" => "https://misskey.io/users/7rkrarq81i",
34 "object" => object
35 }
36
37 {:ok, filtered} = InlineQuotePolicy.filter(activity)
38 assert filtered == activity
39 end
40
41 test "ignores Fedibird quote posts" do
42 object = File.read!("test/fixtures/quote_post/fedibird_quote_post.json") |> Jason.decode!()
43
44 # Normally the ObjectValidator will fix this before it reaches MRF
45 object = Map.put(object, "quoteUrl", object["quoteURL"])
46
47 activity = %{
48 "type" => "Create",
49 "actor" => "https://fedibird.com/users/noellabo",
50 "object" => object
51 }
52
53 {:ok, filtered} = InlineQuotePolicy.filter(activity)
54 assert filtered == activity
55 end
56 end