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["closed"] == "2019-05-11T09:03:36Z"
29 assert object.data["context"] == activity.data["context"]
31 assert object.data["context"] ==
32 "tag:mastodon.sdf.org,2019-05-10:objectId=15095122:objectType=Conversation"
34 assert object.data["context_id"]
36 assert object.data["anyOf"] == []
38 assert Enum.sort(object.data["oneOf"]) ==
41 "name" => "25 char limit is dumb",
42 "replies" => %{"totalItems" => 0, "type" => "Collection"},
47 "replies" => %{"totalItems" => 0, "type" => "Collection"},
51 "name" => "Everyone knows that!",
52 "replies" => %{"totalItems" => 1, "type" => "Collection"},
56 "name" => "I can't even fit a funny",
57 "replies" => %{"totalItems" => 1, "type" => "Collection"},
64 {:ok, reply_activity} = CommonAPI.post(user, %{status: "hewwo", in_reply_to_id: activity.id})
66 reply_object = Object.normalize(reply_activity, false)
68 assert reply_object.data["context"] == object.data["context"]
69 assert reply_object.data["context_id"] == object.data["context_id"]
72 test "Mastodon Question activity with HTML tags in plaintext" do
76 "name" => "<input type=\"date\">",
77 "replies" => %{"totalItems" => 0, "type" => "Collection"}
81 "name" => "<input type=\"date\"/>",
82 "replies" => %{"totalItems" => 0, "type" => "Collection"}
86 "name" => "<input type=\"date\" />",
87 "replies" => %{"totalItems" => 1, "type" => "Collection"}
91 "name" => "<input type=\"date\"></input>",
92 "replies" => %{"totalItems" => 1, "type" => "Collection"}
97 File.read!("test/fixtures/mastodon-question-activity.json")
99 |> Kernel.put_in(["object", "oneOf"], options)
101 {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
102 object = Object.normalize(activity, false)
104 assert Enum.sort(object.data["oneOf"]) == Enum.sort(options)
107 test "returns an error if received a second time" do
108 data = File.read!("test/fixtures/mastodon-question-activity.json") |> Poison.decode!()
110 assert {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
112 assert {:error, {:validate_object, {:error, _}}} = Transmogrifier.handle_incoming(data)
115 test "accepts a Question with no content" do
117 File.read!("test/fixtures/mastodon-question-activity.json")
119 |> Kernel.put_in(["object", "content"], "")
121 assert {:ok, %Activity{local: false}} = Transmogrifier.handle_incoming(data)