1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.Web.ActivityPub.Transmogrifier.AnswerHandlingTest do
10 alias Pleroma.Web.ActivityPub.Transmogrifier
11 alias Pleroma.Web.CommonAPI
13 import Pleroma.Factory
16 Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
20 test "incoming, rewrites Note to Answer and increments vote counters" do
24 CommonAPI.post(user, %{
26 poll: %{options: ["suya", "suya.", "suya.."], expires_in: 10}
29 object = Object.normalize(activity)
32 File.read!("test/fixtures/mastodon-vote.json")
34 |> Kernel.put_in(["to"], user.ap_id)
35 |> Kernel.put_in(["object", "inReplyTo"], object.data["id"])
36 |> Kernel.put_in(["object", "to"], user.ap_id)
38 {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
39 answer_object = Object.normalize(activity)
40 assert answer_object.data["type"] == "Answer"
41 assert answer_object.data["inReplyTo"] == object.data["id"]
43 new_object = Object.get_by_ap_id(object.data["id"])
44 assert new_object.data["replies_count"] == object.data["replies_count"]
47 new_object.data["oneOf"],
49 %{"name" => "suya..", "replies" => %{"totalItems" => 1}} -> true
55 test "outgoing, rewrites Answer to Note" do
58 {:ok, poll_activity} =
59 CommonAPI.post(user, %{
61 poll: %{options: ["suya", "suya.", "suya.."], expires_in: 10}
64 poll_object = Object.normalize(poll_activity)
65 # TODO: Replace with CommonAPI vote creation when implemented
67 File.read!("test/fixtures/mastodon-vote.json")
69 |> Kernel.put_in(["to"], user.ap_id)
70 |> Kernel.put_in(["object", "inReplyTo"], poll_object.data["id"])
71 |> Kernel.put_in(["object", "to"], user.ap_id)
73 {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
74 {:ok, data} = Transmogrifier.prepare_outgoing(activity.data)
76 assert data["object"]["type"] == "Note"