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.QuestionHandlingTest 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 "Mastodon Question activity" do
21 data = File.read!("test/fixtures/mastodon-question-activity.json") |> Poison.decode!()
23 {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
25 object = Object.normalize(activity, false)
27 assert object.data["url"] == "https://mastodon.sdf.org/@rinpatch/102070944809637304"
29 assert object.data["closed"] == "2019-05-11T09:03:36Z"
31 assert object.data["context"] == activity.data["context"]
33 assert object.data["context"] ==
34 "tag:mastodon.sdf.org,2019-05-10:objectId=15095122:objectType=Conversation"
36 assert object.data["context_id"]
38 assert object.data["anyOf"] == []
40 assert Enum.sort(object.data["oneOf"]) ==
43 "name" => "25 char limit is dumb",
44 "replies" => %{"totalItems" => 0, "type" => "Collection"},
49 "replies" => %{"totalItems" => 0, "type" => "Collection"},
53 "name" => "Everyone knows that!",
54 "replies" => %{"totalItems" => 1, "type" => "Collection"},
58 "name" => "I can't even fit a funny",
59 "replies" => %{"totalItems" => 1, "type" => "Collection"},
66 {:ok, reply_activity} = CommonAPI.post(user, %{status: "hewwo", in_reply_to_id: activity.id})
68 reply_object = Object.normalize(reply_activity, false)
70 assert reply_object.data["context"] == object.data["context"]
71 assert reply_object.data["context_id"] == object.data["context_id"]
74 test "Mastodon Question activity with HTML tags in plaintext" do
78 "name" => "<input type=\"date\">",
79 "replies" => %{"totalItems" => 0, "type" => "Collection"}
83 "name" => "<input type=\"date\"/>",
84 "replies" => %{"totalItems" => 0, "type" => "Collection"}
88 "name" => "<input type=\"date\" />",
89 "replies" => %{"totalItems" => 1, "type" => "Collection"}
93 "name" => "<input type=\"date\"></input>",
94 "replies" => %{"totalItems" => 1, "type" => "Collection"}
99 File.read!("test/fixtures/mastodon-question-activity.json")
101 |> Kernel.put_in(["object", "oneOf"], options)
103 {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
104 object = Object.normalize(activity, false)
106 assert Enum.sort(object.data["oneOf"]) == Enum.sort(options)
109 test "returns an error if received a second time" do
110 data = File.read!("test/fixtures/mastodon-question-activity.json") |> Poison.decode!()
112 assert {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
114 assert {:error, {:validate_object, {:error, _}}} = Transmogrifier.handle_incoming(data)
117 test "accepts a Question with no content" do
119 File.read!("test/fixtures/mastodon-question-activity.json")
121 |> Kernel.put_in(["object", "content"], "")
123 assert {:ok, %Activity{local: false}} = Transmogrifier.handle_incoming(data)