2019-07-09 23:12:21 -06:00
|
|
|
# Pleroma: A lightweight social networking server
|
2020-03-03 23:41:23 -07:00
|
|
|
# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
|
2019-07-09 23:12:21 -06: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
|
|
|
|
end
|
|
|
|
end
|