X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;f=test%2Fweb%2Ftwitter_api%2Fviews%2Factivity_view_test.exs;h=8aa9e3130dc4aaba2be6a972a6c6616442fa3bd6;hb=ebbe11f33b62cb248170ba25e5c9cd2e5b339b3a;hp=7615454daf4c5ff60a96b0f33e8bbd0ff62a9576;hpb=c1d529ee9491fc0040cd4327c783aabf76cb66a8;p=akkoma
diff --git a/test/web/twitter_api/views/activity_view_test.exs b/test/web/twitter_api/views/activity_view_test.exs
index 7615454da..8aa9e3130 100644
--- a/test/web/twitter_api/views/activity_view_test.exs
+++ b/test/web/twitter_api/views/activity_view_test.exs
@@ -8,13 +8,33 @@ 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
+ import Mock
+
+ test "a create activity with a html status" do
+ text = """
+ #Bike log - Commute Tuesday\nhttps://pla.bike/posts/20181211/\n#cycling #CHScycling #commute\nMVIMG_20181211_054020.jpg
+ """
+
+ {:ok, activity} = CommonAPI.post(insert(:user), %{"status" => text})
+
+ result = ActivityView.render("activity.json", activity: activity)
+
+ assert result["statusnet_html"] ==
+ "#Bike log - Commute Tuesday
https://pla.bike/posts/20181211/
#cycling #CHScycling #commute
MVIMG_20181211_054020.jpg"
+
+ assert result["text"] ==
+ "#Bike log - Commute Tuesday\nhttps://pla.bike/posts/20181211/\n#cycling #CHScycling #commute\nMVIMG_20181211_054020.jpg"
+ end
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)
@@ -32,6 +52,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,
@@ -39,16 +63,49 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
"repeated" => false,
"statusnet_conversation_id" => convo_id,
"statusnet_html" =>
- "Hey @shp!",
+ "Hey @shp!",
"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"})
@@ -71,6 +128,7 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
{:ok, like, _object} = CommonAPI.favorite(activity.id, other_user)
result = ActivityView.render("activity.json", activity: like)
+ activity = Pleroma.Activity.get_by_ap_id(activity.data["id"])
expected = %{
"activity_type" => "like",
@@ -80,6 +138,35 @@ defmodule Pleroma.Web.TwitterAPI.ActivityViewTest do
"in_reply_to_status_id" => activity.id,
"is_local" => true,
"is_post_verb" => false,
+ "favorited_status" => ActivityView.render("activity.json", activity: activity),
+ "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 "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,
+ "favorited_status" => nil,
"statusnet_html" => "shp favorited a status.",
"text" => "shp favorited a status.",
"uri" => "tag:#{like.data["id"]}:objectType=Favourite",
@@ -119,4 +206,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