Merge branch 'fix-107' into 'develop'
[akkoma] / test / web / twitter_api / views / activity_view_test.exs
index 7615454daf4c5ff60a96b0f33e8bbd0ff62a9576..cb8f60fcf2df45c9620ac574d69b5b1f0f6b4505 100644 (file)
@@ -8,6 +8,8 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
   alias Pleroma.Web.TwitterAPI.TwitterAPI
   alias Pleroma.Repo
   alias Pleroma.Activity
+  alias Pleroma.User
+  alias Pleroma.Web.ActivityPub.ActivityPub
   import Pleroma.Factory
 
   test "a create activity with a note" do
@@ -119,4 +121,56 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
 
     assert result == expected
   end
+
+  test "A follow activity" do
+    user = insert(:user)
+    other_user = insert(:user, %{nickname: "shp"})
+
+    {:ok, follower} = User.follow(user, other_user)
+    {:ok, follow} = ActivityPub.follow(follower, other_user)
+
+    result = ActivityView.render("activity.json", activity: follow)
+
+    expected = %{
+      "activity_type" => "follow",
+      "attentions" => [],
+      "created_at" => follow.data["published"] |> Utils.date_to_asctime(),
+      "external_url" => follow.data["id"],
+      "id" => follow.id,
+      "in_reply_to_status_id" => nil,
+      "is_local" => true,
+      "is_post_verb" => false,
+      "statusnet_html" => "#{user.nickname} started following shp",
+      "text" => "#{user.nickname} started following shp",
+      "user" => UserView.render("show.json", user: user)
+    }
+
+    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