2020-06-19 21:31:19 +00:00
|
|
|
# Pleroma: A lightweight social networking server
|
2021-01-13 06:49:20 +00:00
|
|
|
# Copyright © 2017-2021 Pleroma Authors <https://pleroma.social/>
|
2020-06-19 21:31:19 +00:00
|
|
|
# SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
|
|
|
|
defmodule Pleroma.Web.ActivityPub.Transmogrifier.AnswerHandlingTest do
|
|
|
|
use Pleroma.DataCase
|
|
|
|
|
|
|
|
alias Pleroma.Activity
|
|
|
|
alias Pleroma.Object
|
|
|
|
alias Pleroma.Web.ActivityPub.Transmogrifier
|
|
|
|
alias Pleroma.Web.CommonAPI
|
|
|
|
|
|
|
|
import Pleroma.Factory
|
|
|
|
|
|
|
|
setup_all do
|
|
|
|
Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
|
|
|
|
:ok
|
|
|
|
end
|
|
|
|
|
|
|
|
test "incoming, rewrites Note to Answer and increments vote counters" do
|
|
|
|
user = insert(:user)
|
|
|
|
|
|
|
|
{:ok, activity} =
|
|
|
|
CommonAPI.post(user, %{
|
|
|
|
status: "suya...",
|
|
|
|
poll: %{options: ["suya", "suya.", "suya.."], expires_in: 10}
|
|
|
|
})
|
|
|
|
|
2021-01-04 12:38:31 +00:00
|
|
|
object = Object.normalize(activity, fetch: false)
|
2020-11-02 04:43:06 +00:00
|
|
|
assert object.data["repliesCount"] == nil
|
2020-06-19 21:31:19 +00:00
|
|
|
|
|
|
|
data =
|
|
|
|
File.read!("test/fixtures/mastodon-vote.json")
|
2020-11-23 19:28:55 +00:00
|
|
|
|> Jason.decode!()
|
2020-06-19 21:31:19 +00:00
|
|
|
|> Kernel.put_in(["to"], user.ap_id)
|
|
|
|
|> Kernel.put_in(["object", "inReplyTo"], object.data["id"])
|
|
|
|
|> Kernel.put_in(["object", "to"], user.ap_id)
|
|
|
|
|
|
|
|
{:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
|
2021-01-04 12:38:31 +00:00
|
|
|
answer_object = Object.normalize(activity, fetch: false)
|
2020-06-19 21:31:19 +00:00
|
|
|
assert answer_object.data["type"] == "Answer"
|
|
|
|
assert answer_object.data["inReplyTo"] == object.data["id"]
|
|
|
|
|
|
|
|
new_object = Object.get_by_ap_id(object.data["id"])
|
2020-11-02 04:43:06 +00:00
|
|
|
assert new_object.data["repliesCount"] == nil
|
2020-06-19 21:31:19 +00:00
|
|
|
|
|
|
|
assert Enum.any?(
|
|
|
|
new_object.data["oneOf"],
|
|
|
|
fn
|
|
|
|
%{"name" => "suya..", "replies" => %{"totalItems" => 1}} -> true
|
|
|
|
_ -> false
|
|
|
|
end
|
|
|
|
)
|
|
|
|
end
|
|
|
|
|
|
|
|
test "outgoing, rewrites Answer to Note" do
|
|
|
|
user = insert(:user)
|
|
|
|
|
|
|
|
{:ok, poll_activity} =
|
|
|
|
CommonAPI.post(user, %{
|
|
|
|
status: "suya...",
|
|
|
|
poll: %{options: ["suya", "suya.", "suya.."], expires_in: 10}
|
|
|
|
})
|
|
|
|
|
2021-01-04 12:38:31 +00:00
|
|
|
poll_object = Object.normalize(poll_activity, fetch: false)
|
2020-06-19 21:31:19 +00:00
|
|
|
# TODO: Replace with CommonAPI vote creation when implemented
|
|
|
|
data =
|
|
|
|
File.read!("test/fixtures/mastodon-vote.json")
|
2020-11-23 19:28:55 +00:00
|
|
|
|> Jason.decode!()
|
2020-06-19 21:31:19 +00:00
|
|
|
|> Kernel.put_in(["to"], user.ap_id)
|
|
|
|
|> Kernel.put_in(["object", "inReplyTo"], poll_object.data["id"])
|
|
|
|
|> Kernel.put_in(["object", "to"], user.ap_id)
|
|
|
|
|
|
|
|
{:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
|
|
|
|
{:ok, data} = Transmogrifier.prepare_outgoing(activity.data)
|
|
|
|
|
|
|
|
assert data["object"]["type"] == "Note"
|
|
|
|
end
|
|
|
|
end
|