summaryrefslogtreecommitdiff
path: root/test/web/twitter_api/views
diff options
context:
space:
mode:
authoreal <eal@waifu.club>2018-04-19 21:46:59 +0300
committereal <eal@waifu.club>2018-04-19 21:46:59 +0300
commitfa37acfcc75d069aaaea0b00e619f716e5d6a19a (patch)
treee10e5a098b641969da97ab95a4d4ef3d19787106 /test/web/twitter_api/views
parent7b96a756fbcc6f814e70ad1b9ad6bd45844ea734 (diff)
downloadpleroma-fa37acfcc75d069aaaea0b00e619f716e5d6a19a.tar.gz
pleroma-fa37acfcc75d069aaaea0b00e619f716e5d6a19a.zip
TwitterAPI: Add Qvitter notification endpoint.
Diffstat (limited to 'test/web/twitter_api/views')
-rw-r--r--test/web/twitter_api/views/notification_view_test.exs100
1 files changed, 100 insertions, 0 deletions
diff --git a/test/web/twitter_api/views/notification_view_test.exs b/test/web/twitter_api/views/notification_view_test.exs
new file mode 100644
index 000000000..33aaa89e1
--- /dev/null
+++ b/test/web/twitter_api/views/notification_view_test.exs
@@ -0,0 +1,100 @@
+defmodule Pleroma.Web.TwitterAPI.NotificationViewTest do
+ use Pleroma.DataCase
+
+ alias Pleroma.{User, Notification}
+ alias Pleroma.Web.TwitterAPI.TwitterAPI
+ alias Pleroma.Web.TwitterAPI.NotificationView
+ alias Pleroma.Web.TwitterAPI.UserView
+ alias Pleroma.Web.TwitterAPI.ActivityView
+ alias Pleroma.Web.CommonAPI.Utils
+ alias Pleroma.Web.ActivityPub.ActivityPub
+ alias Pleroma.Builders.UserBuilder
+
+ import Pleroma.Factory
+
+ setup do
+ user = insert(:user, bio: "<span>Here's some html</span>")
+ [user: user]
+ end
+
+ test "A follow notification" do
+ note_activity = insert(:note_activity)
+ user = User.get_cached_by_ap_id(note_activity.data["actor"])
+ follower = insert(:user)
+
+ {:ok, follower} = User.follow(follower, user)
+ {:ok, activity} = ActivityPub.follow(follower, user)
+ Cachex.set(:user_cache, "user_info:#{user.id}", User.user_info(Repo.get!(User, user.id)))
+ [follow_notif] = Notification.for_user(user)
+
+ represented = %{
+ "created_at" => follow_notif.inserted_at |> Utils.format_naive_asctime(),
+ "from_profile" => UserView.render("show.json", %{user: follower, for: user}),
+ "id" => follow_notif.id,
+ "is_seen" => 0,
+ "notice" => ActivityView.render("activity.json", %{activity: activity, for: user}),
+ "ntype" => "follow"
+ }
+
+ assert represented == NotificationView.render("notification.json", %{notification: follow_notif, for: user})
+ end
+
+ test "A mention notification" do
+ user = insert(:user)
+ other_user = insert(:user)
+
+ {:ok, activity} = TwitterAPI.create_status(other_user, %{"status" => "Päivää, @#{user.nickname}"})
+ [notification] = Notification.for_user(user)
+
+ represented = %{
+ "created_at" => notification.inserted_at |> Utils.format_naive_asctime(),
+ "from_profile" => UserView.render("show.json", %{user: other_user, for: user}),
+ "id" => notification.id,
+ "is_seen" => 0,
+ "notice" => ActivityView.render("activity.json", %{activity: activity, for: user}),
+ "ntype" => "mention"
+ }
+
+ assert represented == NotificationView.render("notification.json", %{notification: notification, for: user})
+ end
+
+ test "A retweet notification" do
+ note_activity = insert(:note_activity)
+ user = User.get_cached_by_ap_id(note_activity.data["actor"])
+ repeater = insert(:user)
+
+ {:ok, activity} = TwitterAPI.repeat(repeater, note_activity.id)
+ [notification] = Notification.for_user(user)
+
+ represented = %{
+ "created_at" => notification.inserted_at |> Utils.format_naive_asctime(),
+ "from_profile" => UserView.render("show.json", %{user: repeater, for: user}),
+ "id" => notification.id,
+ "is_seen" => 0,
+ "notice" => ActivityView.render("activity.json", %{activity: notification.activity, for: user}),
+ "ntype" => "repeat"
+ }
+
+ assert represented == NotificationView.render("notification.json", %{notification: notification, for: user})
+ end
+
+ test "A like notification" do
+ note_activity = insert(:note_activity)
+ user = User.get_cached_by_ap_id(note_activity.data["actor"])
+ liker = insert(:user)
+
+ {:ok, activity} = TwitterAPI.fav(liker, note_activity.id)
+ [notification] = Notification.for_user(user)
+
+ represented = %{
+ "created_at" => notification.inserted_at |> Utils.format_naive_asctime(),
+ "from_profile" => UserView.render("show.json", %{user: liker, for: user}),
+ "id" => notification.id,
+ "is_seen" => 0,
+ "notice" => ActivityView.render("activity.json", %{activity: notification.activity, for: user}),
+ "ntype" => "like"
+ }
+
+ assert represented == NotificationView.render("notification.json", %{notification: notification, for: user})
+ end
+end