1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 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, fetch: false)
30 assert object.data["repliesCount"] == nil
33 File.read!("test/fixtures/mastodon-vote.json")
35 |> Kernel.put_in(["to"], user.ap_id)
36 |> Kernel.put_in(["object", "inReplyTo"], object.data["id"])
37 |> Kernel.put_in(["object", "to"], user.ap_id)
39 {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
40 answer_object = Object.normalize(activity, fetch: false)
41 assert answer_object.data["type"] == "Answer"
42 assert answer_object.data["inReplyTo"] == object.data["id"]
44 new_object = Object.get_by_ap_id(object.data["id"])
45 assert new_object.data["repliesCount"] == nil
48 new_object.data["oneOf"],
50 %{"name" => "suya..", "replies" => %{"totalItems" => 1}} -> true
56 test "outgoing, rewrites Answer to Note" do
59 {:ok, poll_activity} =
60 CommonAPI.post(user, %{
62 poll: %{options: ["suya", "suya.", "suya.."], expires_in: 10}
65 poll_object = Object.normalize(poll_activity, fetch: false)
66 # TODO: Replace with CommonAPI vote creation when implemented
68 File.read!("test/fixtures/mastodon-vote.json")
70 |> Kernel.put_in(["to"], user.ap_id)
71 |> Kernel.put_in(["object", "inReplyTo"], poll_object.data["id"])
72 |> Kernel.put_in(["object", "to"], user.ap_id)
74 {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
75 {:ok, data} = Transmogrifier.prepare_outgoing(activity.data)
77 assert data["object"]["type"] == "Note"