Save remote user bio and update if we see new data.
[akkoma] / test / web / ostatus / ostatus_test.exs
index e8f81aae69922a60e49c27e9b0aea1c0535106ae..e40fae78cc3a1d22f5386ab7cc6a998b236f0db5 100644 (file)
@@ -46,6 +46,13 @@ defmodule Pleroma.Web.OStatusTest do
     assert activity.data["object"]["attachment"] |> length == 2
   end
 
+  test "handle incoming notes with tags" do
+    incoming = File.read!("test/fixtures/ostatus_incoming_post_tag.xml")
+    {:ok, [activity]} = OStatus.handle_incoming(incoming)
+
+    assert activity.data["object"]["tag"] == ["nsfw"]
+  end
+
   test "handle incoming notes - Mastodon, salmon, reply" do
     # It uses the context of the replied to object
     Repo.insert!(%Object{
@@ -72,6 +79,13 @@ defmodule Pleroma.Web.OStatusTest do
     assert String.contains?(activity.data["object"]["content"], "technologic")
   end
 
+  test "handle incoming retweets - Mastodon, with CW" do
+    incoming = File.read!("test/fixtures/cw_retweet.xml")
+    {:ok, [[activity, retweeted_activity]]} = OStatus.handle_incoming(incoming)
+
+    assert String.contains?(retweeted_activity.data["object"]["content"], "Hey.")
+  end
+
   test "handle incoming notes - GS, subscription, reply" do
     incoming = File.read!("test/fixtures/ostatus_incoming_reply.xml")
     {:ok, [activity]} = OStatus.handle_incoming(incoming)
@@ -99,6 +113,7 @@ defmodule Pleroma.Web.OStatusTest do
     refute retweeted_activity.local
     assert retweeted_activity.data["object"]["announcement_count"] == 1
     assert String.contains?(retweeted_activity.data["object"]["content"], "mastodon")
+    refute String.contains?(retweeted_activity.data["object"]["content"], "Test account")
   end
 
   test "handle incoming retweets - GS, subscription - local message" do
@@ -138,6 +153,7 @@ defmodule Pleroma.Web.OStatusTest do
     assert retweeted_activity.data["type"] == "Create"
     assert retweeted_activity.data["actor"] == "https://pleroma.soykaf.com/users/lain"
     refute retweeted_activity.local
+    refute String.contains?(retweeted_activity.data["object"]["content"], "Test account")
   end
 
   test "handle incoming favorites - GS, websub" do
@@ -192,8 +208,8 @@ defmodule Pleroma.Web.OStatusTest do
     assert activity.data["object"] == "https://pawoo.net/users/pekorino"
     refute activity.local
 
-    follower = User.get_cached_by_ap_id(activity.data["actor"])
-    followed = User.get_cached_by_ap_id(activity.data["object"])
+    follower = User.get_by_ap_id(activity.data["actor"])
+    followed = User.get_by_ap_id(activity.data["object"])
 
     assert User.following?(follower, followed)
   end
@@ -217,6 +233,7 @@ defmodule Pleroma.Web.OStatusTest do
       assert user.local == false
       assert user.info["uri"] == uri
       assert user.ap_id == uri
+      assert user.bio == "Call me Deacon Blues."
       assert user.avatar["type"] == "Image"
 
       {:ok, user_again} = OStatus.find_or_make_user(uri)
@@ -228,7 +245,9 @@ defmodule Pleroma.Web.OStatusTest do
       uri = "https://social.heldscal.la/user/23211"
 
       {:ok, user} = OStatus.find_or_make_user(uri)
-      change = Ecto.Changeset.change(user, %{avatar: nil})
+      old_name = user.name
+      old_bio = user.bio
+      change = Ecto.Changeset.change(user, %{avatar: nil, bio: nil, old_name: nil})
 
       {:ok, user} = Repo.update(change)
       refute user.avatar
@@ -237,6 +256,8 @@ defmodule Pleroma.Web.OStatusTest do
       [author] = :xmerl_xpath.string('//author[1]', doc)
       {:ok, user} = OStatus.find_make_or_update_user(author)
       assert user.avatar["type"] == "Image"
+      assert user.name == old_name
+      assert user.bio == old_bio
 
       {:ok, user_again} = OStatus.find_make_or_update_user(author)
       assert user_again == user
@@ -261,6 +282,7 @@ defmodule Pleroma.Web.OStatusTest do
         "uri" => "https://social.heldscal.la/user/29191",
         "host" => "social.heldscal.la",
         "fqn" => user,
+        "bio" => "cofe",
         "avatar" => %{"type" => "Image", "url" => [%{"href" => "https://social.heldscal.la/avatar/29191-original-20170421154949.jpeg", "mediaType" => "image/jpeg", "type" => "Link"}]}
       }
       assert data == expected
@@ -283,6 +305,7 @@ defmodule Pleroma.Web.OStatusTest do
         "uri" => "https://social.heldscal.la/user/29191",
         "host" => "social.heldscal.la",
         "fqn" => user,
+        "bio" => "cofe",
         "avatar" => %{"type" => "Image", "url" => [%{"href" => "https://social.heldscal.la/avatar/29191-original-20170421154949.jpeg", "mediaType" => "image/jpeg", "type" => "Link"}]}
       }
       assert data == expected