2019-07-10 05:12:21 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2020-03-04 06:41:23 +00:00
|
|
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
2019-07-10 05:12:21 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.ActivityPub.MRF.EnsureRePrependedTest do
|
|
|
|
use Pleroma.DataCase
|
|
|
|
|
|
|
|
alias Pleroma.Activity
|
|
|
|
alias Pleroma.Object
|
|
|
|
alias Pleroma.Web.ActivityPub.MRF.EnsureRePrepended
|
|
|
|
|
|
|
|
describe "rewrites summary" do
|
|
|
|
test "it adds `re:` to summary object when child summary and parent summary equal" do
|
|
|
|
message = %{
|
|
|
|
"type" => "Create",
|
|
|
|
"object" => %{
|
|
|
|
"summary" => "object-summary",
|
|
|
|
"inReplyTo" => %Activity{object: %Object{data: %{"summary" => "object-summary"}}}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert {:ok, res} = EnsureRePrepended.filter(message)
|
|
|
|
assert res["object"]["summary"] == "re: object-summary"
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it adds `re:` to summary object when child summary containts re-subject of parent summary " do
|
|
|
|
message = %{
|
|
|
|
"type" => "Create",
|
|
|
|
"object" => %{
|
|
|
|
"summary" => "object-summary",
|
|
|
|
"inReplyTo" => %Activity{object: %Object{data: %{"summary" => "re: object-summary"}}}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert {:ok, res} = EnsureRePrepended.filter(message)
|
|
|
|
assert res["object"]["summary"] == "re: object-summary"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe "skip filter" do
|
|
|
|
test "it skip if type isn't 'Create'" do
|
|
|
|
message = %{
|
|
|
|
"type" => "Annotation",
|
|
|
|
"object" => %{"summary" => "object-summary"}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert {:ok, res} = EnsureRePrepended.filter(message)
|
|
|
|
assert res == message
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it skip if summary is empty" do
|
|
|
|
message = %{
|
|
|
|
"type" => "Create",
|
|
|
|
"object" => %{
|
|
|
|
"inReplyTo" => %Activity{object: %Object{data: %{"summary" => "summary"}}}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert {:ok, res} = EnsureRePrepended.filter(message)
|
|
|
|
assert res == message
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it skip if inReplyTo is empty" do
|
|
|
|
message = %{"type" => "Create", "object" => %{"summary" => "summary"}}
|
|
|
|
assert {:ok, res} = EnsureRePrepended.filter(message)
|
|
|
|
assert res == message
|
|
|
|
end
|
|
|
|
|
|
|
|
test "it skip if parent and child summary isn't equal" do
|
|
|
|
message = %{
|
|
|
|
"type" => "Create",
|
|
|
|
"object" => %{
|
|
|
|
"summary" => "object-summary",
|
|
|
|
"inReplyTo" => %Activity{object: %Object{data: %{"summary" => "summary"}}}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
assert {:ok, res} = EnsureRePrepended.filter(message)
|
|
|
|
assert res == message
|
|
|
|
end
|
2020-07-29 08:53:08 +00:00
|
|
|
|
|
|
|
test "it skips if the object is only a reference" do
|
|
|
|
message = %{
|
|
|
|
"type" => "Create",
|
|
|
|
"object" => "somereference"
|
|
|
|
}
|
|
|
|
|
|
|
|
assert {:ok, res} = EnsureRePrepended.filter(message)
|
|
|
|
assert res == message
|
|
|
|
end
|
2019-07-10 05:12:21 +00:00
|
|
|
end
|
|
|
|
end
|