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 "Mastodon Question activity with custom emojis" do
113 "name" => ":blobcat:",
114 "replies" => %{"totalItems" => 0, "type" => "Collection"}
118 "name" => ":blobfox:",
119 "replies" => %{"totalItems" => 0, "type" => "Collection"}
127 "url" => "https://blob.cat/emoji/custom/blobcats/blobcat.png"
129 "id" => "https://blob.cat/emoji/custom/blobcats/blobcat.png",
130 "name" => ":blobcat:",
132 "updated" => "1970-01-01T00:00:00Z"
135 "icon" => %{"type" => "Image", "url" => "https://blob.cat/emoji/blobfox/blobfox.png"},
136 "id" => "https://blob.cat/emoji/blobfox/blobfox.png",
137 "name" => ":blobfox:",
139 "updated" => "1970-01-01T00:00:00Z"
144 File.read!("test/fixtures/mastodon-question-activity.json")
146 |> Kernel.put_in(["object", "oneOf"], options)
147 |> Kernel.put_in(["object", "tag"], tag)
149 {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
150 object = Object.normalize(activity, false)
152 assert object.data["oneOf"] == options
154 assert object.data["emoji"] == %{
155 "blobcat" => "https://blob.cat/emoji/custom/blobcats/blobcat.png",
156 "blobfox" => "https://blob.cat/emoji/blobfox/blobfox.png"
160 test "returns same activity if received a second time" do
161 data = File.read!("test/fixtures/mastodon-question-activity.json") |> Poison.decode!()
163 assert {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
165 assert {:ok, ^activity} = Transmogrifier.handle_incoming(data)
168 test "accepts a Question with no content" do
170 File.read!("test/fixtures/mastodon-question-activity.json")
172 |> Kernel.put_in(["object", "content"], "")
174 assert {:ok, %Activity{local: false}} = Transmogrifier.handle_incoming(data)