+
+ test "it sends follow relationships updates to the 'user' stream", %{
+ user: user,
+ token: oauth_token
+ } do
+ user_id = user.id
+ other_user = insert(:user)
+ other_user_id = other_user.id
+
+ Streamer.get_topic_and_add_socket("user", user, oauth_token)
+ {:ok, _follower, _followed, _follow_activity} = CommonAPI.follow(user, other_user)
+
+ assert_receive {:text, event}
+
+ assert %{"event" => "pleroma:follow_relationships_update", "payload" => payload} =
+ Jason.decode!(event)
+
+ assert %{
+ "follower" => %{
+ "follower_count" => 0,
+ "following_count" => 0,
+ "id" => ^user_id
+ },
+ "following" => %{
+ "follower_count" => 0,
+ "following_count" => 0,
+ "id" => ^other_user_id
+ },
+ "state" => "follow_pending"
+ } = Jason.decode!(payload)
+
+ assert_receive {:text, event}
+
+ assert %{"event" => "pleroma:follow_relationships_update", "payload" => payload} =
+ Jason.decode!(event)
+
+ assert %{
+ "follower" => %{
+ "follower_count" => 0,
+ "following_count" => 1,
+ "id" => ^user_id
+ },
+ "following" => %{
+ "follower_count" => 1,
+ "following_count" => 0,
+ "id" => ^other_user_id
+ },
+ "state" => "follow_accept"
+ } = Jason.decode!(payload)
+ end
+
+ test "it streams edits in the 'user' stream", %{user: user, token: oauth_token} do
+ sender = insert(:user)
+ {:ok, _, _, _} = CommonAPI.follow(user, sender)
+
+ {:ok, activity} = CommonAPI.post(sender, %{status: "hey"})
+
+ Streamer.get_topic_and_add_socket("user", user, oauth_token)
+ {:ok, edited} = CommonAPI.update(sender, activity, %{status: "mew mew"})
+ create = Pleroma.Activity.get_create_by_object_ap_id_with_object(activity.object.data["id"])
+
+ stream = "user:#{user.id}"
+ assert_receive {:render_with_user, _, "status_update.json", ^create, ^stream}
+ refute Streamer.filtered_by_user?(user, edited)
+ end
+
+ test "it streams own edits in the 'user' stream", %{user: user, token: oauth_token} do
+ {:ok, activity} = CommonAPI.post(user, %{status: "hey"})
+
+ Streamer.get_topic_and_add_socket("user", user, oauth_token)
+ {:ok, edited} = CommonAPI.update(user, activity, %{status: "mew mew"})
+ create = Pleroma.Activity.get_create_by_object_ap_id_with_object(activity.object.data["id"])
+
+ stream = "user:#{user.id}"
+ assert_receive {:render_with_user, _, "status_update.json", ^create, ^stream}
+ refute Streamer.filtered_by_user?(user, edited)
+ end
+
+ test "it streams posts containing followed hashtags on the 'user' stream", %{
+ user: user,
+ token: oauth_token
+ } do
+ hashtag = insert(:hashtag, %{name: "tenshi"})
+ other_user = insert(:user)
+ {:ok, user} = User.follow_hashtag(user, hashtag)
+
+ Streamer.get_topic_and_add_socket("user", user, oauth_token)
+ {:ok, activity} = CommonAPI.post(other_user, %{status: "hey #tenshi"})
+
+ assert_receive {:render_with_user, _, "update.json", ^activity, _}
+ end
+
+ test "should not stream private posts containing followed hashtags on the 'user' stream", %{
+ user: user,
+ token: oauth_token
+ } do
+ hashtag = insert(:hashtag, %{name: "tenshi"})
+ other_user = insert(:user)
+ {:ok, user} = User.follow_hashtag(user, hashtag)
+
+ Streamer.get_topic_and_add_socket("user", user, oauth_token)
+
+ {:ok, activity} =
+ CommonAPI.post(other_user, %{status: "hey #tenshi", visibility: "private"})
+
+ refute_receive {:render_with_user, _, "update.json", ^activity, _}
+ end