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
13 Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
17 test "Mastodon Question activity" do
18 data = File.read!("test/fixtures/mastodon-question-activity.json") |> Poison.decode!()
20 {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
22 object = Object.normalize(activity, false)
24 assert object.data["closed"] == "2019-05-11T09:03:36Z"
26 assert object.data["context"] ==
27 "tag:mastodon.sdf.org,2019-05-10:objectId=15095122:objectType=Conversation"
29 assert object.data["context_id"]
31 assert object.data["anyOf"] == []
33 assert Enum.sort(object.data["oneOf"]) ==
36 "name" => "25 char limit is dumb",
37 "replies" => %{"totalItems" => 0, "type" => "Collection"},
42 "replies" => %{"totalItems" => 0, "type" => "Collection"},
46 "name" => "Everyone knows that!",
47 "replies" => %{"totalItems" => 1, "type" => "Collection"},
51 "name" => "I can't even fit a funny",
52 "replies" => %{"totalItems" => 1, "type" => "Collection"},
58 test "returns an error if received a second time" do
59 data = File.read!("test/fixtures/mastodon-question-activity.json") |> Poison.decode!()
61 assert {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
63 assert {:error, {:validate_object, {:error, _}}} = Transmogrifier.handle_incoming(data)