Strip status data from Flag (when federating or closing/resolving report)
[akkoma] / test / web / ostatus / activity_representer_test.exs
index 8bf3bc775b9d8175fad8654df5c9b081016996b2..a8d5008909ecc11d3988af419dfca0f9244343e1 100644 (file)
@@ -1,12 +1,24 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
 defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
   use Pleroma.DataCase
 
-  alias Pleroma.Web.OStatus.ActivityRepresenter
-  alias Pleroma.{User, Activity, Object}
+  alias Pleroma.Activity
+  alias Pleroma.Object
+  alias Pleroma.User
   alias Pleroma.Web.ActivityPub.ActivityPub
   alias Pleroma.Web.OStatus
+  alias Pleroma.Web.OStatus.ActivityRepresenter
 
   import Pleroma.Factory
+  import Tesla.Mock
+
+  setup do
+    mock(fn env -> apply(HttpRequestMock, :request, [env]) end)
+    :ok
+  end
 
   test "an external note activity" do
     incoming = File.read!("test/fixtures/mastodon-note-cw.xml")
@@ -26,22 +38,23 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
 
   test "a note activity" do
     note_activity = insert(:note_activity)
+    object_data = Object.normalize(note_activity).data
 
     user = User.get_cached_by_ap_id(note_activity.data["actor"])
 
     expected = """
     <activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type>
     <activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
-    <id>#{note_activity.data["object"]["id"]}</id>
+    <id>#{object_data["id"]}</id>
     <title>New note by #{user.nickname}</title>
-    <content type="html">#{note_activity.data["object"]["content"]}</content>
-    <published>#{note_activity.data["object"]["published"]}</published>
-    <updated>#{note_activity.data["object"]["published"]}</updated>
+    <content type="html">#{object_data["content"]}</content>
+    <published>#{object_data["published"]}</published>
+    <updated>#{object_data["published"]}</updated>
     <ostatus:conversation ref="#{note_activity.data["context"]}">#{note_activity.data["context"]}</ostatus:conversation>
     <link ref="#{note_activity.data["context"]}" rel="ostatus:conversation" />
-    <summary>#{note_activity.data["object"]["summary"]}</summary>
-    <link type="application/atom+xml" href="#{note_activity.data["object"]["id"]}" rel="self" />
-    <link type="text/html" href="#{note_activity.data["object"]["id"]}" rel="alternate" />
+    <summary>#{object_data["summary"]}</summary>
+    <link type="application/atom+xml" href="#{object_data["id"]}" rel="self" />
+    <link type="text/html" href="#{object_data["id"]}" rel="alternate" />
     <category term="2hu"/>
     <link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/collection" href="http://activityschema.org/collection/public"/>
     <link name="2hu" rel="emoji" href="corndog.png" />
@@ -55,37 +68,31 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
   end
 
   test "a reply note" do
-    note = insert(:note_activity)
-    answer = insert(:note_activity)
-    object = answer.data["object"]
-    object = Map.put(object, "inReplyTo", note.data["object"]["id"])
-
-    data = %{answer.data | "object" => object}
-    answer = %{answer | data: data}
-
-    note_object = Object.get_by_ap_id(note.data["object"]["id"])
+    user = insert(:user)
+    note_object = insert(:note)
+    _note = insert(:note_activity, %{note: note_object})
+    object = insert(:note, %{data: %{"inReplyTo" => note_object.data["id"]}})
+    answer = insert(:note_activity, %{note: object})
 
     Repo.update!(
       Object.change(note_object, %{data: Map.put(note_object.data, "external_url", "someurl")})
     )
 
-    user = User.get_cached_by_ap_id(answer.data["actor"])
-
     expected = """
     <activity:object-type>http://activitystrea.ms/schema/1.0/note</activity:object-type>
     <activity:verb>http://activitystrea.ms/schema/1.0/post</activity:verb>
-    <id>#{answer.data["object"]["id"]}</id>
+    <id>#{object.data["id"]}</id>
     <title>New note by #{user.nickname}</title>
-    <content type="html">#{answer.data["object"]["content"]}</content>
-    <published>#{answer.data["object"]["published"]}</published>
-    <updated>#{answer.data["object"]["published"]}</updated>
+    <content type="html">#{object.data["content"]}</content>
+    <published>#{object.data["published"]}</published>
+    <updated>#{object.data["published"]}</updated>
     <ostatus:conversation ref="#{answer.data["context"]}">#{answer.data["context"]}</ostatus:conversation>
     <link ref="#{answer.data["context"]}" rel="ostatus:conversation" />
     <summary>2hu</summary>
-    <link type="application/atom+xml" href="#{answer.data["object"]["id"]}" rel="self" />
-    <link type="text/html" href="#{answer.data["object"]["id"]}" rel="alternate" />
+    <link type="application/atom+xml" href="#{object.data["id"]}" rel="self" />
+    <link type="text/html" href="#{object.data["id"]}" rel="alternate" />
     <category term="2hu"/>
-    <thr:in-reply-to ref="#{note.data["object"]["id"]}" href="someurl" />
+    <thr:in-reply-to ref="#{note_object.data["id"]}" href="someurl" />
     <link rel="mentioned" ostatus:object-type="http://activitystrea.ms/schema/1.0/collection" href="http://activityschema.org/collection/public"/>
     <link name="2hu" rel="emoji" href="corndog.png" />
     """
@@ -100,14 +107,14 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
   test "an announce activity" do
     note = insert(:note_activity)
     user = insert(:user)
-    object = Object.get_cached_by_ap_id(note.data["object"]["id"])
+    object = Object.normalize(note)
 
     {:ok, announce, _object} = ActivityPub.announce(user, object)
 
-    announce = Repo.get(Activity, announce.id)
+    announce = Activity.get_by_id(announce.id)
 
     note_user = User.get_cached_by_ap_id(note.data["actor"])
-    note = Repo.get(Activity, note.id)
+    note = Activity.get_by_id(note.id)
 
     note_xml =
       ActivityRepresenter.to_simple_form(note, note_user, true)
@@ -119,7 +126,7 @@ defmodule Pleroma.Web.OStatus.ActivityRepresenterTest do
     <activity:verb>http://activitystrea.ms/schema/1.0/share</activity:verb>
     <id>#{announce.data["id"]}</id>
     <title>#{user.nickname} repeated a notice</title>
-    <content type="html">RT #{note.data["object"]["content"]}</content>
+    <content type="html">RT #{object.data["content"]}</content>
     <published>#{announce.data["published"]}</published>
     <updated>#{announce.data["published"]}</updated>
     <ostatus:conversation ref="#{announce.data["context"]}">#{announce.data["context"]}</ostatus:conversation>