1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2021 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") |> Jason.decode!()
23 {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
25 object = Object.normalize(activity, fetch: 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["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, fetch: false)
68 assert reply_object.data["context"] == object.data["context"]
71 test "Mastodon Question activity with HTML tags in plaintext" do
75 "name" => "<input type=\"date\">",
76 "replies" => %{"totalItems" => 0, "type" => "Collection"}
80 "name" => "<input type=\"date\"/>",
81 "replies" => %{"totalItems" => 0, "type" => "Collection"}
85 "name" => "<input type=\"date\" />",
86 "replies" => %{"totalItems" => 1, "type" => "Collection"}
90 "name" => "<input type=\"date\"></input>",
91 "replies" => %{"totalItems" => 1, "type" => "Collection"}
96 File.read!("test/fixtures/mastodon-question-activity.json")
98 |> Kernel.put_in(["object", "oneOf"], options)
100 {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
101 object = Object.normalize(activity, fetch: false)
103 assert Enum.sort(object.data["oneOf"]) == Enum.sort(options)
106 test "Mastodon Question activity with custom emojis" do
110 "name" => ":blobcat:",
111 "replies" => %{"totalItems" => 0, "type" => "Collection"}
115 "name" => ":blobfox:",
116 "replies" => %{"totalItems" => 0, "type" => "Collection"}
124 "url" => "https://blob.cat/emoji/custom/blobcats/blobcat.png"
126 "id" => "https://blob.cat/emoji/custom/blobcats/blobcat.png",
127 "name" => ":blobcat:",
129 "updated" => "1970-01-01T00:00:00Z"
132 "icon" => %{"type" => "Image", "url" => "https://blob.cat/emoji/blobfox/blobfox.png"},
133 "id" => "https://blob.cat/emoji/blobfox/blobfox.png",
134 "name" => ":blobfox:",
136 "updated" => "1970-01-01T00:00:00Z"
141 File.read!("test/fixtures/mastodon-question-activity.json")
143 |> Kernel.put_in(["object", "oneOf"], options)
144 |> Kernel.put_in(["object", "tag"], tag)
146 {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
147 object = Object.normalize(activity, fetch: false)
149 assert object.data["oneOf"] == options
151 assert object.data["emoji"] == %{
152 "blobcat" => "https://blob.cat/emoji/custom/blobcats/blobcat.png",
153 "blobfox" => "https://blob.cat/emoji/blobfox/blobfox.png"
157 test "returns same activity if received a second time" do
158 data = File.read!("test/fixtures/mastodon-question-activity.json") |> Jason.decode!()
160 assert {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
162 assert {:ok, ^activity} = Transmogrifier.handle_incoming(data)
165 test "accepts a Question with no content" do
167 File.read!("test/fixtures/mastodon-question-activity.json")
169 |> Kernel.put_in(["object", "content"], "")
171 assert {:ok, %Activity{local: false}} = Transmogrifier.handle_incoming(data)