diff options
Diffstat (limited to 'test')
17 files changed, 300 insertions, 129 deletions
diff --git a/test/marker_test.exs b/test/marker_test.exs index c80ae16b6..5b6d0b4a4 100644 --- a/test/marker_test.exs +++ b/test/marker_test.exs @@ -8,12 +8,39 @@ defmodule Pleroma.MarkerTest do    import Pleroma.Factory +  describe "multi_set_unread_count/3" do +    test "returns multi" do +      user = insert(:user) + +      assert %Ecto.Multi{ +               operations: [marker: {:run, _}, counters: {:run, _}] +             } = +               Marker.multi_set_last_read_id( +                 Ecto.Multi.new(), +                 user, +                 "notifications" +               ) +    end + +    test "return empty multi" do +      user = insert(:user) +      multi = Ecto.Multi.new() +      assert Marker.multi_set_last_read_id(multi, user, "home") == multi +    end +  end +    describe "get_markers/2" do      test "returns user markers" do        user = insert(:user)        marker = insert(:marker, user: user) +      insert(:notification, user: user) +      insert(:notification, user: user)        insert(:marker, timeline: "home", user: user) -      assert Marker.get_markers(user, ["notifications"]) == [refresh_record(marker)] + +      assert Marker.get_markers( +               user, +               ["notifications"] +             ) == [%Marker{refresh_record(marker) | unread_count: 2}]      end    end diff --git a/test/notification_test.exs b/test/notification_test.exs index 7f359711f..24e5f0c73 100644 --- a/test/notification_test.exs +++ b/test/notification_test.exs @@ -12,6 +12,8 @@ defmodule Pleroma.NotificationTest do    alias Pleroma.Notification    alias Pleroma.Tests.ObanHelpers    alias Pleroma.User +  alias Pleroma.Web.ActivityPub.ActivityPub +  alias Pleroma.Web.ActivityPub.Builder    alias Pleroma.Web.ActivityPub.Transmogrifier    alias Pleroma.Web.CommonAPI    alias Pleroma.Web.MastodonAPI.NotificationView @@ -24,7 +26,7 @@ defmodule Pleroma.NotificationTest do        other_user = insert(:user)        {:ok, activity} = CommonAPI.post(user, %{"status" => "yeah"}) -      {:ok, activity, _object} = CommonAPI.react_with_emoji(activity.id, other_user, "☕") +      {:ok, activity} = CommonAPI.react_with_emoji(activity.id, other_user, "☕")        {:ok, [notification]} = Notification.create_notifications(activity) @@ -47,6 +49,9 @@ defmodule Pleroma.NotificationTest do        assert notified_ids == [other_user.id, third_user.id]        assert notification.activity_id == activity.id        assert other_notification.activity_id == activity.id + +      assert [%Pleroma.Marker{unread_count: 2}] = +               Pleroma.Marker.get_markers(other_user, ["notifications"])      end      test "it creates a notification for subscribed users" do @@ -466,6 +471,16 @@ defmodule Pleroma.NotificationTest do        assert n1.seen == true        assert n2.seen == true        assert n3.seen == false + +      assert %Pleroma.Marker{} = +               m = +               Pleroma.Repo.get_by( +                 Pleroma.Marker, +                 user_id: other_user.id, +                 timeline: "notifications" +               ) + +      assert m.last_read_id == to_string(n2.id)      end    end @@ -601,6 +616,28 @@ defmodule Pleroma.NotificationTest do        assert other_user not in enabled_receivers      end +    test "it only notifies the post's author in likes" do +      user = insert(:user) +      other_user = insert(:user) +      third_user = insert(:user) + +      {:ok, activity_one} = +        CommonAPI.post(user, %{ +          "status" => "hey @#{other_user.nickname}!" +        }) + +      {:ok, like_data, _} = Builder.like(third_user, activity_one.object) + +      {:ok, like, _} = +        like_data +        |> Map.put("to", [other_user.ap_id | like_data["to"]]) +        |> ActivityPub.persist(local: true) + +      {enabled_receivers, _disabled_receivers} = Notification.get_notified_from_activity(like) + +      assert other_user not in enabled_receivers +    end +      test "it does not send notification to mentioned users in announces" do        user = insert(:user)        other_user = insert(:user) diff --git a/test/web/activity_pub/activity_pub_test.exs b/test/web/activity_pub/activity_pub_test.exs index 0a8a7119d..0739cbfef 100644 --- a/test/web/activity_pub/activity_pub_test.exs +++ b/test/web/activity_pub/activity_pub_test.exs @@ -16,7 +16,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do    alias Pleroma.Web.ActivityPub.Utils    alias Pleroma.Web.AdminAPI.AccountView    alias Pleroma.Web.CommonAPI -  alias Pleroma.Web.Federator    import ExUnit.CaptureLog    import Mock @@ -874,71 +873,6 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do      end    end -  describe "react to an object" do -    test_with_mock "sends an activity to federation", Federator, [:passthrough], [] do -      Config.put([:instance, :federating], true) -      user = insert(:user) -      reactor = insert(:user) -      {:ok, activity} = CommonAPI.post(user, %{"status" => "YASSSS queen slay"}) -      assert object = Object.normalize(activity) - -      {:ok, reaction_activity, _object} = ActivityPub.react_with_emoji(reactor, object, "🔥") - -      assert called(Federator.publish(reaction_activity)) -    end - -    test "adds an emoji reaction activity to the db" do -      user = insert(:user) -      reactor = insert(:user) -      third_user = insert(:user) -      fourth_user = insert(:user) -      {:ok, activity} = CommonAPI.post(user, %{"status" => "YASSSS queen slay"}) -      assert object = Object.normalize(activity) - -      {:ok, reaction_activity, object} = ActivityPub.react_with_emoji(reactor, object, "🔥") - -      assert reaction_activity - -      assert reaction_activity.data["actor"] == reactor.ap_id -      assert reaction_activity.data["type"] == "EmojiReact" -      assert reaction_activity.data["content"] == "🔥" -      assert reaction_activity.data["object"] == object.data["id"] -      assert reaction_activity.data["to"] == [User.ap_followers(reactor), activity.data["actor"]] -      assert reaction_activity.data["context"] == object.data["context"] -      assert object.data["reaction_count"] == 1 -      assert object.data["reactions"] == [["🔥", [reactor.ap_id]]] - -      {:ok, _reaction_activity, object} = ActivityPub.react_with_emoji(third_user, object, "☕") - -      assert object.data["reaction_count"] == 2 -      assert object.data["reactions"] == [["🔥", [reactor.ap_id]], ["☕", [third_user.ap_id]]] - -      {:ok, _reaction_activity, object} = ActivityPub.react_with_emoji(fourth_user, object, "🔥") - -      assert object.data["reaction_count"] == 3 - -      assert object.data["reactions"] == [ -               ["🔥", [fourth_user.ap_id, reactor.ap_id]], -               ["☕", [third_user.ap_id]] -             ] -    end - -    test "reverts emoji reaction on error" do -      [user, reactor] = insert_list(2, :user) - -      {:ok, activity} = CommonAPI.post(user, %{"status" => "Status"}) -      object = Object.normalize(activity) - -      with_mock(Utils, [:passthrough], maybe_federate: fn _ -> {:error, :reverted} end) do -        assert {:error, :reverted} = ActivityPub.react_with_emoji(reactor, object, "😀") -      end - -      object = Object.get_by_ap_id(object.data["id"]) -      refute object.data["reaction_count"] -      refute object.data["reactions"] -    end -  end -    describe "announcing an object" do      test "adds an announce activity to the db" do        note_activity = insert(:note_activity) diff --git a/test/web/activity_pub/object_validator_test.exs b/test/web/activity_pub/object_validator_test.exs index 174be5ec6..f382adf3e 100644 --- a/test/web/activity_pub/object_validator_test.exs +++ b/test/web/activity_pub/object_validator_test.exs @@ -10,6 +10,46 @@ defmodule Pleroma.Web.ActivityPub.ObjectValidatorTest do    import Pleroma.Factory +  describe "EmojiReacts" do +    setup do +      user = insert(:user) +      {:ok, post_activity} = CommonAPI.post(user, %{"status" => "uguu"}) + +      object = Pleroma.Object.get_by_ap_id(post_activity.data["object"]) + +      {:ok, valid_emoji_react, []} = Builder.emoji_react(user, object, "👌") + +      %{user: user, post_activity: post_activity, valid_emoji_react: valid_emoji_react} +    end + +    test "it validates a valid EmojiReact", %{valid_emoji_react: valid_emoji_react} do +      assert {:ok, _, _} = ObjectValidator.validate(valid_emoji_react, []) +    end + +    test "it is not valid without a 'content' field", %{valid_emoji_react: valid_emoji_react} do +      without_content = +        valid_emoji_react +        |> Map.delete("content") + +      {:error, cng} = ObjectValidator.validate(without_content, []) + +      refute cng.valid? +      assert {:content, {"can't be blank", [validation: :required]}} in cng.errors +    end + +    test "it is not valid with a non-emoji content field", %{valid_emoji_react: valid_emoji_react} do +      without_emoji_content = +        valid_emoji_react +        |> Map.put("content", "x") + +      {:error, cng} = ObjectValidator.validate(without_emoji_content, []) + +      refute cng.valid? + +      assert {:content, {"must be a single character emoji", []}} in cng.errors +    end +  end +    describe "Undos" do      setup do        user = insert(:user) diff --git a/test/web/activity_pub/side_effects_test.exs b/test/web/activity_pub/side_effects_test.exs index aafc450d3..b29a7a7be 100644 --- a/test/web/activity_pub/side_effects_test.exs +++ b/test/web/activity_pub/side_effects_test.exs @@ -72,13 +72,40 @@ defmodule Pleroma.Web.ActivityPub.SideEffectsTest do      end    end +  describe "EmojiReact objects" do +    setup do +      poster = insert(:user) +      user = insert(:user) + +      {:ok, post} = CommonAPI.post(poster, %{"status" => "hey"}) + +      {:ok, emoji_react_data, []} = Builder.emoji_react(user, post.object, "👌") +      {:ok, emoji_react, _meta} = ActivityPub.persist(emoji_react_data, local: true) + +      %{emoji_react: emoji_react, user: user, poster: poster} +    end + +    test "adds the reaction to the object", %{emoji_react: emoji_react, user: user} do +      {:ok, emoji_react, _} = SideEffects.handle(emoji_react) +      object = Object.get_by_ap_id(emoji_react.data["object"]) + +      assert object.data["reaction_count"] == 1 +      assert ["👌", [user.ap_id]] in object.data["reactions"] +    end + +    test "creates a notification", %{emoji_react: emoji_react, poster: poster} do +      {:ok, emoji_react, _} = SideEffects.handle(emoji_react) +      assert Repo.get_by(Notification, user_id: poster.id, activity_id: emoji_react.id) +    end +  end +    describe "Undo objects" do      setup do        poster = insert(:user)        user = insert(:user)        {:ok, post} = CommonAPI.post(poster, %{"status" => "hey"})        {:ok, like} = CommonAPI.favorite(user, post.id) -      {:ok, reaction, _} = CommonAPI.react_with_emoji(post.id, user, "👍") +      {:ok, reaction} = CommonAPI.react_with_emoji(post.id, user, "👍")        {:ok, announce, _} = CommonAPI.repeat(post.id, user)        {:ok, block} = ActivityPub.block(user, poster)        User.block(user, poster) diff --git a/test/web/activity_pub/transmogrifier/emoji_react_handling_test.exs b/test/web/activity_pub/transmogrifier/emoji_react_handling_test.exs new file mode 100644 index 000000000..6988e3e0a --- /dev/null +++ b/test/web/activity_pub/transmogrifier/emoji_react_handling_test.exs @@ -0,0 +1,61 @@ +# Pleroma: A lightweight social networking server +# Copyright © 2017-2020 Pleroma Authors <https://pleroma.social/> +# SPDX-License-Identifier: AGPL-3.0-only + +defmodule Pleroma.Web.ActivityPub.Transmogrifier.EmojiReactHandlingTest do +  use Pleroma.DataCase + +  alias Pleroma.Activity +  alias Pleroma.Object +  alias Pleroma.Web.ActivityPub.Transmogrifier +  alias Pleroma.Web.CommonAPI + +  import Pleroma.Factory + +  test "it works for incoming emoji reactions" do +    user = insert(:user) +    other_user = insert(:user, local: false) +    {:ok, activity} = CommonAPI.post(user, %{"status" => "hello"}) + +    data = +      File.read!("test/fixtures/emoji-reaction.json") +      |> Poison.decode!() +      |> Map.put("object", activity.data["object"]) +      |> Map.put("actor", other_user.ap_id) + +    {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data) + +    assert data["actor"] == other_user.ap_id +    assert data["type"] == "EmojiReact" +    assert data["id"] == "http://mastodon.example.org/users/admin#reactions/2" +    assert data["object"] == activity.data["object"] +    assert data["content"] == "👌" + +    object = Object.get_by_ap_id(data["object"]) + +    assert object.data["reaction_count"] == 1 +    assert match?([["👌", _]], object.data["reactions"]) +  end + +  test "it reject invalid emoji reactions" do +    user = insert(:user) +    other_user = insert(:user, local: false) +    {:ok, activity} = CommonAPI.post(user, %{"status" => "hello"}) + +    data = +      File.read!("test/fixtures/emoji-reaction-too-long.json") +      |> Poison.decode!() +      |> Map.put("object", activity.data["object"]) +      |> Map.put("actor", other_user.ap_id) + +    assert {:error, _} = Transmogrifier.handle_incoming(data) + +    data = +      File.read!("test/fixtures/emoji-reaction-no-emoji.json") +      |> Poison.decode!() +      |> Map.put("object", activity.data["object"]) +      |> Map.put("actor", other_user.ap_id) + +    assert {:error, _} = Transmogrifier.handle_incoming(data) +  end +end diff --git a/test/web/activity_pub/transmogrifier/undo_handling_test.exs b/test/web/activity_pub/transmogrifier/undo_handling_test.exs index 6f5e61ac3..eaf58adf7 100644 --- a/test/web/activity_pub/transmogrifier/undo_handling_test.exs +++ b/test/web/activity_pub/transmogrifier/undo_handling_test.exs @@ -17,7 +17,7 @@ defmodule Pleroma.Web.ActivityPub.Transmogrifier.UndoHandlingTest do      user = insert(:user)      {:ok, activity} = CommonAPI.post(user, %{"status" => "hello"}) -    {:ok, reaction_activity, _object} = CommonAPI.react_with_emoji(activity.id, user, "👌") +    {:ok, reaction_activity} = CommonAPI.react_with_emoji(activity.id, user, "👌")      data =        File.read!("test/fixtures/mastodon-undo-like.json") diff --git a/test/web/activity_pub/transmogrifier_test.exs b/test/web/activity_pub/transmogrifier_test.exs index 4fd6c8b00..2914c90ea 100644 --- a/test/web/activity_pub/transmogrifier_test.exs +++ b/test/web/activity_pub/transmogrifier_test.exs @@ -325,43 +325,6 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do        assert object_data["cc"] == to      end -    test "it works for incoming emoji reactions" do -      user = insert(:user) -      {:ok, activity} = CommonAPI.post(user, %{"status" => "hello"}) - -      data = -        File.read!("test/fixtures/emoji-reaction.json") -        |> Poison.decode!() -        |> Map.put("object", activity.data["object"]) - -      {:ok, %Activity{data: data, local: false}} = Transmogrifier.handle_incoming(data) - -      assert data["actor"] == "http://mastodon.example.org/users/admin" -      assert data["type"] == "EmojiReact" -      assert data["id"] == "http://mastodon.example.org/users/admin#reactions/2" -      assert data["object"] == activity.data["object"] -      assert data["content"] == "👌" -    end - -    test "it reject invalid emoji reactions" do -      user = insert(:user) -      {:ok, activity} = CommonAPI.post(user, %{"status" => "hello"}) - -      data = -        File.read!("test/fixtures/emoji-reaction-too-long.json") -        |> Poison.decode!() -        |> Map.put("object", activity.data["object"]) - -      assert :error = Transmogrifier.handle_incoming(data) - -      data = -        File.read!("test/fixtures/emoji-reaction-no-emoji.json") -        |> Poison.decode!() -        |> Map.put("object", activity.data["object"]) - -      assert :error = Transmogrifier.handle_incoming(data) -    end -      test "it works for incoming announces" do        data = File.read!("test/fixtures/mastodon-announce.json") |> Poison.decode!() @@ -518,7 +481,7 @@ defmodule Pleroma.Web.ActivityPub.TransmogrifierTest do      test "it strips internal reactions" do        user = insert(:user)        {:ok, activity} = CommonAPI.post(user, %{"status" => "#cofe"}) -      {:ok, _, _} = CommonAPI.react_with_emoji(activity.id, user, "📢") +      {:ok, _} = CommonAPI.react_with_emoji(activity.id, user, "📢")        %{object: object} = Activity.get_by_id_with_object(activity.id)        assert Map.has_key?(object.data, "reactions") diff --git a/test/web/common_api/common_api_test.exs b/test/web/common_api/common_api_test.exs index 9a37d1887..2fd17a1b8 100644 --- a/test/web/common_api/common_api_test.exs +++ b/test/web/common_api/common_api_test.exs @@ -358,7 +358,7 @@ defmodule Pleroma.Web.CommonAPITest do        {:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"}) -      {:ok, reaction, _} = CommonAPI.react_with_emoji(activity.id, user, "👍") +      {:ok, reaction} = CommonAPI.react_with_emoji(activity.id, user, "👍")        assert reaction.data["actor"] == user.ap_id        assert reaction.data["content"] == "👍" @@ -373,7 +373,7 @@ defmodule Pleroma.Web.CommonAPITest do        other_user = insert(:user)        {:ok, activity} = CommonAPI.post(other_user, %{"status" => "cofe"}) -      {:ok, reaction, _} = CommonAPI.react_with_emoji(activity.id, user, "👍") +      {:ok, reaction} = CommonAPI.react_with_emoji(activity.id, user, "👍")        {:ok, unreaction} = CommonAPI.unreact_with_emoji(activity.id, user, "👍") diff --git a/test/web/mastodon_api/controllers/account_controller_test.exs b/test/web/mastodon_api/controllers/account_controller_test.exs index b9da7e924..256a8b304 100644 --- a/test/web/mastodon_api/controllers/account_controller_test.exs +++ b/test/web/mastodon_api/controllers/account_controller_test.exs @@ -1196,12 +1196,15 @@ defmodule Pleroma.Web.MastodonAPI.AccountControllerTest do    describe "verify_credentials" do      test "verify_credentials" do        %{user: user, conn: conn} = oauth_access(["read:accounts"]) +      [notification | _] = insert_list(7, :notification, user: user) +      Pleroma.Notification.set_read_up_to(user, notification.id)        conn = get(conn, "/api/v1/accounts/verify_credentials")        response = json_response_and_validate_schema(conn, 200)        assert %{"id" => id, "source" => %{"privacy" => "public"}} = response        assert response["pleroma"]["chat_token"] +      assert response["pleroma"]["unread_notifications_count"] == 6        assert id == to_string(user.id)      end diff --git a/test/web/mastodon_api/controllers/marker_controller_test.exs b/test/web/mastodon_api/controllers/marker_controller_test.exs index bce719bea..6dd40fb4a 100644 --- a/test/web/mastodon_api/controllers/marker_controller_test.exs +++ b/test/web/mastodon_api/controllers/marker_controller_test.exs @@ -11,6 +11,7 @@ defmodule Pleroma.Web.MastodonAPI.MarkerControllerTest do      test "gets markers with correct scopes", %{conn: conn} do        user = insert(:user)        token = insert(:oauth_token, user: user, scopes: ["read:statuses"]) +      insert_list(7, :notification, user: user)        {:ok, %{"notifications" => marker}} =          Pleroma.Marker.upsert( @@ -29,7 +30,8 @@ defmodule Pleroma.Web.MastodonAPI.MarkerControllerTest do                 "notifications" => %{                   "last_read_id" => "69420",                   "updated_at" => NaiveDateTime.to_iso8601(marker.updated_at), -                 "version" => 0 +                 "version" => 0, +                 "pleroma" => %{"unread_count" => 7}                 }               }      end @@ -71,7 +73,8 @@ defmodule Pleroma.Web.MastodonAPI.MarkerControllerTest do                 "notifications" => %{                   "last_read_id" => "69420",                   "updated_at" => _, -                 "version" => 0 +                 "version" => 0, +                 "pleroma" => %{"unread_count" => 0}                 }               } = response      end @@ -101,7 +104,8 @@ defmodule Pleroma.Web.MastodonAPI.MarkerControllerTest do                 "notifications" => %{                   "last_read_id" => "69888",                   "updated_at" => NaiveDateTime.to_iso8601(marker.updated_at), -                 "version" => 0 +                 "version" => 0, +                 "pleroma" => %{"unread_count" => 0}                 }               }      end diff --git a/test/web/mastodon_api/views/account_view_test.exs b/test/web/mastodon_api/views/account_view_test.exs index 85fa4f6a2..5fb162141 100644 --- a/test/web/mastodon_api/views/account_view_test.exs +++ b/test/web/mastodon_api/views/account_view_test.exs @@ -466,6 +466,24 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do                 :unread_conversation_count               ] == 1      end + +    test "shows unread_count only to the account owner" do +      user = insert(:user) +      insert_list(7, :notification, user: user) +      other_user = insert(:user) + +      user = User.get_cached_by_ap_id(user.ap_id) + +      assert AccountView.render( +               "show.json", +               %{user: user, for: other_user} +             )[:pleroma][:unread_notifications_count] == nil + +      assert AccountView.render( +               "show.json", +               %{user: user, for: user} +             )[:pleroma][:unread_notifications_count] == 7 +    end    end    describe "follow requests counter" do diff --git a/test/web/mastodon_api/views/marker_view_test.exs b/test/web/mastodon_api/views/marker_view_test.exs index 893cf8857..48a0a6d33 100644 --- a/test/web/mastodon_api/views/marker_view_test.exs +++ b/test/web/mastodon_api/views/marker_view_test.exs @@ -8,19 +8,21 @@ defmodule Pleroma.Web.MastodonAPI.MarkerViewTest do    import Pleroma.Factory    test "returns markers" do -    marker1 = insert(:marker, timeline: "notifications", last_read_id: "17") +    marker1 = insert(:marker, timeline: "notifications", last_read_id: "17", unread_count: 5)      marker2 = insert(:marker, timeline: "home", last_read_id: "42")      assert MarkerView.render("markers.json", %{markers: [marker1, marker2]}) == %{               "home" => %{                 last_read_id: "42",                 updated_at: NaiveDateTime.to_iso8601(marker2.updated_at), -               version: 0 +               version: 0, +               pleroma: %{unread_count: 0}               },               "notifications" => %{                 last_read_id: "17",                 updated_at: NaiveDateTime.to_iso8601(marker1.updated_at), -               version: 0 +               version: 0, +               pleroma: %{unread_count: 5}               }             }    end diff --git a/test/web/mastodon_api/views/notification_view_test.exs b/test/web/mastodon_api/views/notification_view_test.exs index c3ec9dfec..0806269a2 100644 --- a/test/web/mastodon_api/views/notification_view_test.exs +++ b/test/web/mastodon_api/views/notification_view_test.exs @@ -156,7 +156,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do      other_user = insert(:user)      {:ok, activity} = CommonAPI.post(user, %{"status" => "#cofe"}) -    {:ok, _activity, _} = CommonAPI.react_with_emoji(activity.id, other_user, "☕") +    {:ok, _activity} = CommonAPI.react_with_emoji(activity.id, other_user, "☕")      activity = Repo.get(Activity, activity.id) diff --git a/test/web/mastodon_api/views/status_view_test.exs b/test/web/mastodon_api/views/status_view_test.exs index 451723e60..b5e7dc317 100644 --- a/test/web/mastodon_api/views/status_view_test.exs +++ b/test/web/mastodon_api/views/status_view_test.exs @@ -32,9 +32,9 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do      third_user = insert(:user)      {:ok, activity} = CommonAPI.post(user, %{"status" => "dae cofe??"}) -    {:ok, _, _} = CommonAPI.react_with_emoji(activity.id, user, "☕") -    {:ok, _, _} = CommonAPI.react_with_emoji(activity.id, third_user, "🍵") -    {:ok, _, _} = CommonAPI.react_with_emoji(activity.id, other_user, "☕") +    {:ok, _} = CommonAPI.react_with_emoji(activity.id, user, "☕") +    {:ok, _} = CommonAPI.react_with_emoji(activity.id, third_user, "🍵") +    {:ok, _} = CommonAPI.react_with_emoji(activity.id, other_user, "☕")      activity = Repo.get(Activity, activity.id)      status = StatusView.render("show.json", activity: activity) diff --git a/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs b/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs index 299dbad41..43f1b154d 100644 --- a/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs +++ b/test/web/pleroma_api/controllers/pleroma_api_controller_test.exs @@ -43,7 +43,7 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do      other_user = insert(:user)      {:ok, activity} = CommonAPI.post(user, %{"status" => "#cofe"}) -    {:ok, _reaction, _object} = CommonAPI.react_with_emoji(activity.id, other_user, "☕") +    {:ok, _reaction_activity} = CommonAPI.react_with_emoji(activity.id, other_user, "☕")      ObanHelpers.perform_all() @@ -77,8 +77,8 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do      assert result == [] -    {:ok, _, _} = CommonAPI.react_with_emoji(activity.id, other_user, "🎅") -    {:ok, _, _} = CommonAPI.react_with_emoji(activity.id, doomed_user, "🎅") +    {:ok, _} = CommonAPI.react_with_emoji(activity.id, other_user, "🎅") +    {:ok, _} = CommonAPI.react_with_emoji(activity.id, doomed_user, "🎅")      User.perform(:delete, doomed_user) @@ -115,8 +115,8 @@ defmodule Pleroma.Web.PleromaAPI.PleromaAPIControllerTest do      assert result == [] -    {:ok, _, _} = CommonAPI.react_with_emoji(activity.id, other_user, "🎅") -    {:ok, _, _} = CommonAPI.react_with_emoji(activity.id, other_user, "☕") +    {:ok, _} = CommonAPI.react_with_emoji(activity.id, other_user, "🎅") +    {:ok, _} = CommonAPI.react_with_emoji(activity.id, other_user, "☕")      result =        conn diff --git a/test/web/push/impl_test.exs b/test/web/push/impl_test.exs index b2664bf28..b855d72ba 100644 --- a/test/web/push/impl_test.exs +++ b/test/web/push/impl_test.exs @@ -193,7 +193,7 @@ defmodule Pleroma.Web.Push.ImplTest do    end    describe "build_content/3" do -    test "returns info content for direct message with enabled privacy option" do +    test "hides details for notifications when privacy option enabled" do        user = insert(:user, nickname: "Bob")        user2 = insert(:user, nickname: "Rob", notification_settings: %{privacy_option: true}) @@ -209,12 +209,37 @@ defmodule Pleroma.Web.Push.ImplTest do        object = Object.normalize(activity)        assert Impl.build_content(notif, actor, object) == %{ -               body: "@Bob", -               title: "New Direct Message" +               body: "New Direct Message" +             } + +      {:ok, activity} = +        CommonAPI.post(user, %{ +          "visibility" => "public", +          "status" => "<Lorem ipsum dolor sit amet." +        }) + +      notif = insert(:notification, user: user2, activity: activity) + +      actor = User.get_cached_by_ap_id(notif.activity.data["actor"]) +      object = Object.normalize(activity) + +      assert Impl.build_content(notif, actor, object) == %{ +               body: "New Mention" +             } + +      {:ok, activity} = CommonAPI.favorite(user, activity.id) + +      notif = insert(:notification, user: user2, activity: activity) + +      actor = User.get_cached_by_ap_id(notif.activity.data["actor"]) +      object = Object.normalize(activity) + +      assert Impl.build_content(notif, actor, object) == %{ +               body: "New Favorite"               }      end -    test "returns regular content for direct message with disabled privacy option" do +    test "returns regular content for notifications with privacy option disabled" do        user = insert(:user, nickname: "Bob")        user2 = insert(:user, nickname: "Rob", notification_settings: %{privacy_option: false}) @@ -235,6 +260,36 @@ defmodule Pleroma.Web.Push.ImplTest do                   "@Bob: Lorem ipsum dolor sit amet, consectetur  adipiscing elit. Fusce sagittis fini...",                 title: "New Direct Message"               } + +      {:ok, activity} = +        CommonAPI.post(user, %{ +          "visibility" => "public", +          "status" => +            "<span>Lorem ipsum dolor sit amet</span>, consectetur :firefox: adipiscing elit. Fusce sagittis finibus turpis." +        }) + +      notif = insert(:notification, user: user2, activity: activity) + +      actor = User.get_cached_by_ap_id(notif.activity.data["actor"]) +      object = Object.normalize(activity) + +      assert Impl.build_content(notif, actor, object) == %{ +               body: +                 "@Bob: Lorem ipsum dolor sit amet, consectetur  adipiscing elit. Fusce sagittis fini...", +               title: "New Mention" +             } + +      {:ok, activity} = CommonAPI.favorite(user, activity.id) + +      notif = insert(:notification, user: user2, activity: activity) + +      actor = User.get_cached_by_ap_id(notif.activity.data["actor"]) +      object = Object.normalize(activity) + +      assert Impl.build_content(notif, actor, object) == %{ +               body: "@Bob has favorited your post", +               title: "New Favorite" +             }      end    end  end  | 
