Merge branch 'develop' of https://git.pleroma.social/pleroma/pleroma into develop
[akkoma] / test / pleroma / web / activity_pub / mrf / ensure_re_prepended_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ActivityPub.MRF.EnsureRePrependedTest do
6 use Pleroma.DataCase, async: true
7
8 alias Pleroma.Activity
9 alias Pleroma.Object
10 alias Pleroma.Web.ActivityPub.MRF.EnsureRePrepended
11
12 describe "rewrites summary" do
13 test "it adds `re:` to summary object when child summary and parent summary equal" do
14 message = %{
15 "type" => "Create",
16 "object" => %{
17 "summary" => "object-summary",
18 "inReplyTo" => %Activity{object: %Object{data: %{"summary" => "object-summary"}}}
19 }
20 }
21
22 assert {:ok, res} = EnsureRePrepended.filter(message)
23 assert res["object"]["summary"] == "re: object-summary"
24 end
25
26 test "it adds `re:` to summary object when child summary containts re-subject of parent summary " do
27 message = %{
28 "type" => "Create",
29 "object" => %{
30 "summary" => "object-summary",
31 "inReplyTo" => %Activity{object: %Object{data: %{"summary" => "re: object-summary"}}}
32 }
33 }
34
35 assert {:ok, res} = EnsureRePrepended.filter(message)
36 assert res["object"]["summary"] == "re: object-summary"
37 end
38 end
39
40 describe "skip filter" do
41 test "it skip if type isn't 'Create'" do
42 message = %{
43 "type" => "Annotation",
44 "object" => %{"summary" => "object-summary"}
45 }
46
47 assert {:ok, res} = EnsureRePrepended.filter(message)
48 assert res == message
49 end
50
51 test "it skip if summary is empty" do
52 message = %{
53 "type" => "Create",
54 "object" => %{
55 "inReplyTo" => %Activity{object: %Object{data: %{"summary" => "summary"}}}
56 }
57 }
58
59 assert {:ok, res} = EnsureRePrepended.filter(message)
60 assert res == message
61 end
62
63 test "it skip if inReplyTo is empty" do
64 message = %{"type" => "Create", "object" => %{"summary" => "summary"}}
65 assert {:ok, res} = EnsureRePrepended.filter(message)
66 assert res == message
67 end
68
69 test "it skip if parent and child summary isn't equal" do
70 message = %{
71 "type" => "Create",
72 "object" => %{
73 "summary" => "object-summary",
74 "inReplyTo" => %Activity{object: %Object{data: %{"summary" => "summary"}}}
75 }
76 }
77
78 assert {:ok, res} = EnsureRePrepended.filter(message)
79 assert res == message
80 end
81
82 test "it skips if the object is only a reference" do
83 message = %{
84 "type" => "Create",
85 "object" => "somereference"
86 }
87
88 assert {:ok, res} = EnsureRePrepended.filter(message)
89 assert res == message
90 end
91 end
92 end