tests: twitterapi: add additional fields
[akkoma] / test / web / twitter_api / views / activity_view_test.exs
index eca69cdfe655fec59624eab14df058f02241ccd9..5cef06f882e7017c3c473685a978d92fa96bcacd 100644 (file)
@@ -10,13 +10,15 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
   alias Pleroma.Activity
   alias Pleroma.User
   alias Pleroma.Web.ActivityPub.ActivityPub
+
   import Pleroma.Factory
+  import Mock
 
   test "a create activity with a note" do
     user = insert(:user)
     other_user = insert(:user, %{nickname: "shp"})
 
-    {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
+    {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!", "visibility" => "direct"})
 
     result = ActivityView.render("activity.json", activity: activity)
 
@@ -34,6 +36,10 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
       "favorited" => false,
       "id" => activity.id,
       "in_reply_to_status_id" => nil,
+      "in_reply_to_screen_name" => nil,
+      "in_reply_to_user_id" => nil,
+      "in_reply_to_profileurl" => nil,
+      "in_reply_to_ostatus_uri" => nil,
       "is_local" => true,
       "is_post_verb" => true,
       "possibly_sensitive" => false,
@@ -45,12 +51,45 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
       "tags" => [],
       "text" => "Hey @shp!",
       "uri" => activity.data["object"]["id"],
-      "user" => UserView.render("show.json", %{user: user})
+      "user" => UserView.render("show.json", %{user: user}),
+      "visibility" => "direct",
+      "summary" => nil
     }
 
     assert result == expected
   end
 
+  test "a list of activities" do
+    user = insert(:user)
+    other_user = insert(:user, %{nickname: "shp"})
+    {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
+
+    convo_id = TwitterAPI.context_to_conversation_id(activity.data["object"]["context"])
+
+    mocks = [
+      {
+        TwitterAPI,
+        [],
+        [context_to_conversation_id: fn _ -> false end]
+      },
+      {
+        User,
+        [:passthrough],
+        [get_cached_by_ap_id: fn _ -> nil end]
+      }
+    ]
+
+    with_mocks mocks do
+      [result] = ActivityView.render("index.json", activities: [activity])
+
+      assert result["statusnet_conversation_id"] == convo_id
+      assert result["user"]
+      refute called(TwitterAPI.context_to_conversation_id(:_))
+      refute called(User.get_cached_by_ap_id(user.ap_id))
+      refute called(User.get_cached_by_ap_id(other_user.ap_id))
+    end
+  end
+
   test "an activity that is a reply" do
     user = insert(:user)
     other_user = insert(:user, %{nickname: "shp"})
@@ -91,6 +130,33 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
     assert result == expected
   end
 
+  test "a like activity for deleted post" do
+    user = insert(:user)
+    other_user = insert(:user, %{nickname: "shp"})
+
+    {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
+    {:ok, like, _object} = CommonAPI.favorite(activity.id, other_user)
+    CommonAPI.delete(activity.id, user)
+
+    result = ActivityView.render("activity.json", activity: like)
+
+    expected = %{
+      "activity_type" => "like",
+      "created_at" => like.data["published"] |> Utils.date_to_asctime(),
+      "external_url" => like.data["id"],
+      "id" => like.id,
+      "in_reply_to_status_id" => nil,
+      "is_local" => true,
+      "is_post_verb" => false,
+      "statusnet_html" => "shp favorited a status.",
+      "text" => "shp favorited a status.",
+      "uri" => "tag:#{like.data["id"]}:objectType=Favourite",
+      "user" => UserView.render("show.json", user: other_user)
+    }
+
+    assert result == expected
+  end
+
   test "an announce activity" do
     user = insert(:user)
     other_user = insert(:user, %{nickname: "shp"})
@@ -126,7 +192,6 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
     user = insert(:user)
     other_user = insert(:user, %{nickname: "shp"})
 
-    {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
     {:ok, follower} = User.follow(user, other_user)
     {:ok, follow} = ActivityPub.follow(follower, other_user)
 
@@ -148,4 +213,30 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
 
     assert result == expected
   end
+
+  test "a delete activity" do
+    user = insert(:user)
+
+    {:ok, activity} = CommonAPI.post(user, %{"status" => "Hey @shp!"})
+    {:ok, delete} = CommonAPI.delete(activity.id, user)
+
+    result = ActivityView.render("activity.json", activity: delete)
+
+    expected = %{
+      "activity_type" => "delete",
+      "attentions" => [],
+      "created_at" => delete.data["published"] |> Utils.date_to_asctime(),
+      "external_url" => delete.data["id"],
+      "id" => delete.id,
+      "in_reply_to_status_id" => nil,
+      "is_local" => true,
+      "is_post_verb" => false,
+      "statusnet_html" => "deleted notice {{tag",
+      "text" => "deleted notice {{tag",
+      "uri" => delete.data["object"],
+      "user" => UserView.render("show.json", user: user)
+    }
+
+    assert result == expected
+  end
 end