From 653d605e14d25658d398148748335dc58f9f2229 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Thu, 13 Apr 2017 16:19:07 +0200 Subject: Add favoriting to twitter api. --- test/web/twitter_api/representers/activity_representer_test.exs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) (limited to 'test/web/twitter_api/representers') diff --git a/test/web/twitter_api/representers/activity_representer_test.exs b/test/web/twitter_api/representers/activity_representer_test.exs index f1f2b4c9c..70df79a77 100644 --- a/test/web/twitter_api/representers/activity_representer_test.exs +++ b/test/web/twitter_api/representers/activity_representer_test.exs @@ -45,7 +45,8 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do "statusnetConversationId" => 4711, "attachment" => [ object - ] + ], + "like_count" => 5 }, "published" => date } @@ -68,7 +69,8 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do ], "attentions" => [ UserRepresenter.to_map(mentioned_user, %{for: follower}) - ] + ], + "fave_num" => 5 } assert ActivityRepresenter.to_map(activity, %{user: user, for: follower, mentioned: [mentioned_user]}) == expected_status -- cgit v1.2.3 From d0da40dc81f5db2b3d335fb47d00d0ac52c2cba3 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Thu, 13 Apr 2017 17:05:53 +0200 Subject: Display like activities. --- .../twitter_api/representers/activity_representer_test.exs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test/web/twitter_api/representers') diff --git a/test/web/twitter_api/representers/activity_representer_test.exs b/test/web/twitter_api/representers/activity_representer_test.exs index 70df79a77..5673c1f0d 100644 --- a/test/web/twitter_api/representers/activity_representer_test.exs +++ b/test/web/twitter_api/representers/activity_representer_test.exs @@ -2,7 +2,21 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do use Pleroma.DataCase alias Pleroma.{User, Activity, Object} alias Pleroma.Web.TwitterAPI.Representers.{UserRepresenter, ActivityRepresenter, ObjectRepresenter} + alias Pleroma.Web.ActivityPub.ActivityPub alias Pleroma.Builders.UserBuilder + import Pleroma.Factory + + test "a like activity" do + user = insert(:user) + note_activity = insert(:note_activity) + object = Object.get_by_ap_id(note_activity.data["object"]["id"]) + + {:ok, like_activity, object} = ActivityPub.like(user, object) + status = ActivityRepresenter.to_map(like_activity, %{user: user, liked_activity: note_activity}) + + assert status["id"] == like_activity.id + assert status["in_reply_to_status_id"] == note_activity.id + end test "an activity" do {:ok, user} = UserBuilder.insert -- cgit v1.2.3 From fa0c279139f384f6c97bce217be4131b255f00b1 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Fri, 14 Apr 2017 15:07:24 +0200 Subject: Favorite changes. - Add 'likes' to activity, collection of ids of people who liked it. - show if you favorited something or not. - Don't allow double favorites - Address favorites to the followers of the liked activity's author. --- .../web/twitter_api/representers/activity_representer_test.exs | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'test/web/twitter_api/representers') diff --git a/test/web/twitter_api/representers/activity_representer_test.exs b/test/web/twitter_api/representers/activity_representer_test.exs index 5673c1f0d..d1f9e00c8 100644 --- a/test/web/twitter_api/representers/activity_representer_test.exs +++ b/test/web/twitter_api/representers/activity_representer_test.exs @@ -11,11 +11,16 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do note_activity = insert(:note_activity) object = Object.get_by_ap_id(note_activity.data["object"]["id"]) - {:ok, like_activity, object} = ActivityPub.like(user, object) + {:ok, like_activity, _object} = ActivityPub.like(user, object) status = ActivityRepresenter.to_map(like_activity, %{user: user, liked_activity: note_activity}) assert status["id"] == like_activity.id assert status["in_reply_to_status_id"] == note_activity.id + + note_activity = Activity.get_by_ap_id(note_activity.data["id"]) + activity_actor = Repo.get_by(User, ap_id: note_activity.data["actor"]) + liked_status = ActivityRepresenter.to_map(note_activity, %{user: activity_actor, for: user}) + assert liked_status["favorited"] == true end test "an activity" do @@ -84,7 +89,8 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do "attentions" => [ UserRepresenter.to_map(mentioned_user, %{for: follower}) ], - "fave_num" => 5 + "fave_num" => 5, + "favorited" => false } assert ActivityRepresenter.to_map(activity, %{user: user, for: follower, mentioned: [mentioned_user]}) == expected_status -- cgit v1.2.3 From 60c60de330fe8fe03594da89831351099c8c9037 Mon Sep 17 00:00:00 2001 From: Roger Braun Date: Sat, 15 Apr 2017 13:54:46 +0200 Subject: Add announcements / retweets to TwAPI. --- .../representers/activity_representer_test.exs | 27 ++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'test/web/twitter_api/representers') diff --git a/test/web/twitter_api/representers/activity_representer_test.exs b/test/web/twitter_api/representers/activity_representer_test.exs index d1f9e00c8..a9129bccc 100644 --- a/test/web/twitter_api/representers/activity_representer_test.exs +++ b/test/web/twitter_api/representers/activity_representer_test.exs @@ -6,6 +6,26 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do alias Pleroma.Builders.UserBuilder import Pleroma.Factory + test "an announce activity" do + user = insert(:user) + note_activity = insert(:note_activity) + activity_actor = Repo.get_by(User, ap_id: note_activity.data["actor"]) + object = Object.get_by_ap_id(note_activity.data["object"]["id"]) + + {:ok, announce_activity, _object} = ActivityPub.announce(user, object) + note_activity = Activity.get_by_ap_id(note_activity.data["id"]) + + status = ActivityRepresenter.to_map(announce_activity, %{users: [user, activity_actor], announced_activity: note_activity, for: user}) + + assert status["id"] == announce_activity.id + assert status["user"] == UserRepresenter.to_map(user, %{for: user}) + + retweeted_status = ActivityRepresenter.to_map(note_activity, %{user: activity_actor, for: user}) + assert retweeted_status["repeated"] == true + + assert status["retweeted_status"] == retweeted_status + end + test "a like activity" do user = insert(:user) note_activity = insert(:note_activity) @@ -65,7 +85,8 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do "attachment" => [ object ], - "like_count" => 5 + "like_count" => 5, + "announcement_count" => 3 }, "published" => date } @@ -90,7 +111,9 @@ defmodule Pleroma.Web.TwitterAPI.Representers.ActivityRepresenterTest do UserRepresenter.to_map(mentioned_user, %{for: follower}) ], "fave_num" => 5, - "favorited" => false + "repeat_num" => 3, + "favorited" => false, + "repeated" => false } assert ActivityRepresenter.to_map(activity, %{user: user, for: follower, mentioned: [mentioned_user]}) == expected_status -- cgit v1.2.3