transmogrifier tests: Move & enhance in specialised modules
[akkoma] / test / web / activity_pub / transmogrifier / question_handling_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Web.ActivityPub.Transmogrifier.QuestionHandlingTest do
6 use Pleroma.DataCase
7
8 alias Pleroma.Activity
9 alias Pleroma.Object
10 alias Pleroma.Web.ActivityPub.Transmogrifier
11
12 setup_all do
13 Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
14 :ok
15 end
16
17 test "Mastodon Question activity" do
18 data = File.read!("test/fixtures/mastodon-question-activity.json") |> Poison.decode!()
19
20 {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
21
22 object = Object.normalize(activity, false)
23
24 assert object.data["closed"] == "2019-05-11T09:03:36Z"
25
26 assert object.data["context"] ==
27 "tag:mastodon.sdf.org,2019-05-10:objectId=15095122:objectType=Conversation"
28
29 assert object.data["context_id"]
30
31 assert object.data["anyOf"] == []
32
33 assert Enum.sort(object.data["oneOf"]) ==
34 Enum.sort([
35 %{
36 "name" => "25 char limit is dumb",
37 "replies" => %{"totalItems" => 0, "type" => "Collection"},
38 "type" => "Note"
39 },
40 %{
41 "name" => "Dunno",
42 "replies" => %{"totalItems" => 0, "type" => "Collection"},
43 "type" => "Note"
44 },
45 %{
46 "name" => "Everyone knows that!",
47 "replies" => %{"totalItems" => 1, "type" => "Collection"},
48 "type" => "Note"
49 },
50 %{
51 "name" => "I can't even fit a funny",
52 "replies" => %{"totalItems" => 1, "type" => "Collection"},
53 "type" => "Note"
54 }
55 ])
56 end
57
58 test "returns an error if received a second time" do
59 data = File.read!("test/fixtures/mastodon-question-activity.json") |> Poison.decode!()
60
61 assert {:ok, %Activity{local: false} = activity} = Transmogrifier.handle_incoming(data)
62
63 assert {:error, {:validate_object, {:error, _}}} = Transmogrifier.handle_incoming(data)
64 end
65 end