diff options
Diffstat (limited to 'test')
5 files changed, 200 insertions, 10 deletions
diff --git a/test/pleroma/web/mastodon_api/controllers/notification_controller_test.exs b/test/pleroma/web/mastodon_api/controllers/notification_controller_test.exs index 2615912a8..f51f77946 100644 --- a/test/pleroma/web/mastodon_api/controllers/notification_controller_test.exs +++ b/test/pleroma/web/mastodon_api/controllers/notification_controller_test.exs @@ -408,6 +408,83 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do assert [%{"id" => ^reblog_notification_id}] = json_response_and_validate_schema(conn_res, 200) end + defp update_notification_settings_and_conn(user, conn, exclude_types) do + {:ok, user} = + User.update_notification_settings(user, %{ + "exclude_types" => exclude_types + }) + + conn + |> assign(:user, user) + |> get("/api/v1/notifications") + end + + test "filters notifications with user settings for exclude_types" do + %{user: user, conn: conn} = oauth_access(["read:notifications"]) + + other_user = insert(:user) + + {:ok, mention_activity} = CommonAPI.post(other_user, %{status: "hey @#{user.nickname}"}) + {:ok, create_activity} = CommonAPI.post(user, %{status: "hey"}) + {:ok, favorite_activity} = CommonAPI.favorite(other_user, create_activity.id) + {:ok, reblog_activity} = CommonAPI.repeat(create_activity.id, other_user) + {:ok, _, _, follow_activity} = CommonAPI.follow(other_user, user) + + mention_notification_id = get_notification_id_by_activity(mention_activity) + favorite_notification_id = get_notification_id_by_activity(favorite_activity) + reblog_notification_id = get_notification_id_by_activity(reblog_activity) + follow_notification_id = get_notification_id_by_activity(follow_activity) + + conn_res = + update_notification_settings_and_conn(user, conn, ["mention", "favourite", "reblog"]) + + assert [%{"id" => ^follow_notification_id}] = json_response_and_validate_schema(conn_res, 200) + + conn_res = + update_notification_settings_and_conn(user, conn, ["favourite", "reblog", "follow"]) + + assert [%{"id" => ^mention_notification_id}] = + json_response_and_validate_schema(conn_res, 200) + + conn_res = update_notification_settings_and_conn(user, conn, ["reblog", "follow", "mention"]) + + assert [%{"id" => ^favorite_notification_id}] = + json_response_and_validate_schema(conn_res, 200) + + conn_res = + update_notification_settings_and_conn(user, conn, ["follow", "mention", "favourite"]) + + assert [%{"id" => ^reblog_notification_id}] = json_response_and_validate_schema(conn_res, 200) + end + + test "exclude_types params have high priority than user settings" do + %{user: user, conn: conn} = oauth_access(["read:notifications"]) + + other_user = insert(:user) + + {:ok, _mention_activity} = CommonAPI.post(other_user, %{status: "hey @#{user.nickname}"}) + {:ok, create_activity} = CommonAPI.post(user, %{status: "hey"}) + {:ok, _favorite_activity} = CommonAPI.favorite(other_user, create_activity.id) + {:ok, _reblog_activity} = CommonAPI.repeat(create_activity.id, other_user) + {:ok, _, _, follow_activity} = CommonAPI.follow(other_user, user) + + follow_notification_id = get_notification_id_by_activity(follow_activity) + + {:ok, user} = + User.update_notification_settings(user, %{ + "exclude_types" => ["favourite", "reblog", "follow", "mention"] + }) + + query = params_to_query(%{exclude_types: ["mention", "favourite", "reblog"]}) + + conn_res = + conn + |> assign(:user, user) + |> get("/api/v1/notifications?" <> query) + + assert [%{"id" => ^follow_notification_id}] = json_response_and_validate_schema(conn_res, 200) + end + test "filters notifications using include_types" do %{user: user, conn: conn} = oauth_access(["read:notifications"]) other_user = insert(:user) diff --git a/test/pleroma/web/mastodon_api/masto_fe_controller_test.exs b/test/pleroma/web/mastodon_api/masto_fe_controller_test.exs index ea66c708f..c13b9cb73 100644 --- a/test/pleroma/web/mastodon_api/masto_fe_controller_test.exs +++ b/test/pleroma/web/mastodon_api/masto_fe_controller_test.exs @@ -11,19 +11,96 @@ defmodule Pleroma.Web.MastodonAPI.MastoFEControllerTest do setup do: clear_config([:instance, :public]) - test "put settings", %{conn: conn} do - user = insert(:user) + describe "put_settings/2" do + setup do + %{conn: conn, user: user} = oauth_access(["write:accounts"]) + [conn: conn, user: user] + end - conn = - conn - |> assign(:user, user) - |> assign(:token, insert(:oauth_token, user: user, scopes: ["write:accounts"])) - |> put("/api/web/settings", %{"data" => %{"programming" => "socks"}}) + test "common", %{conn: conn, user: user} do + assert conn + |> put("/api/web/settings", %{"data" => %{"programming" => "socks"}}) + |> json_response(200) - assert _result = json_response(conn, 200) + user = User.get_cached_by_ap_id(user.ap_id) + assert user.mastofe_settings == %{"programming" => "socks"} + end - user = User.get_cached_by_ap_id(user.ap_id) - assert user.mastofe_settings == %{"programming" => "socks"} + test "saves notification settings", %{conn: conn, user: user} do + assert conn + |> put("/api/web/settings", %{ + "data" => %{ + "notifications" => %{ + "alerts" => %{ + "favourite" => true, + "follow" => true, + "follow_request" => true, + "mention" => true, + "poll" => true, + "reblog" => true + }, + "quickFilter" => %{"active" => "all", "advanced" => true, "show" => true}, + "shows" => %{ + "favourite" => false, + "follow" => false, + "follow_request" => false, + "mention" => false, + "poll" => false, + "reblog" => false + }, + "sounds" => %{ + "favourite" => true, + "follow" => true, + "follow_request" => true, + "mention" => true, + "poll" => true, + "reblog" => true + } + } + } + }) + + user = User.get_cached_by_ap_id(user.ap_id) + + assert user.settings == %{ + "notifications" => %{ + "alerts" => %{ + "favourite" => true, + "follow" => true, + "follow_request" => true, + "mention" => true, + "poll" => true, + "reblog" => true + }, + "quickFilter" => %{"active" => "all", "advanced" => true, "show" => true}, + "shows" => %{ + "favourite" => false, + "follow" => false, + "follow_request" => false, + "mention" => false, + "poll" => false, + "reblog" => false + }, + "sounds" => %{ + "favourite" => true, + "follow" => true, + "follow_request" => true, + "mention" => true, + "poll" => true, + "reblog" => true + } + } + } + + assert user.notification_settings.exclude_types == [ + "favourite", + "follow", + "follow_request", + "mention", + "poll", + "reblog" + ] + end end describe "index/2 redirections" do diff --git a/test/pleroma/web/mastodon_api/views/account_view_test.exs b/test/pleroma/web/mastodon_api/views/account_view_test.exs index 5373a17c3..a9c66e63e 100644 --- a/test/pleroma/web/mastodon_api/views/account_view_test.exs +++ b/test/pleroma/web/mastodon_api/views/account_view_test.exs @@ -125,6 +125,12 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do notification_settings = %{ block_from_strangers: false, hide_notification_contents: false + followers: true, + follows: true, + non_followers: true, + non_follows: true, + privacy_option: false, + exclude_types: [] } privacy = user.default_scope diff --git a/test/pleroma/web/push/impl_test.exs b/test/pleroma/web/push/impl_test.exs index b3ca1a337..a7c2431ed 100644 --- a/test/pleroma/web/push/impl_test.exs +++ b/test/pleroma/web/push/impl_test.exs @@ -69,6 +69,27 @@ defmodule Pleroma.Web.Push.ImplTest do assert Impl.perform(notif) == {:ok, [:ok, :ok]} end + test "notification for follow_request" do + user = insert(:user) + reaction_user = insert(:user) + + insert(:push_subscription, user: user, data: %{alerts: %{"pleroma:emoji_reaction" => true}}) + insert(:push_subscription, user: user, data: %{alerts: %{"pleroma:emoji_reaction" => false}}) + + {:ok, activity} = CommonAPI.post(user, %{status: "<Lorem ipsum dolor sit amet."}) + + {:ok, reaction_activity} = CommonAPI.react_with_emoji(activity.id, reaction_user, "☕") + + notif = + insert(:notification, + user: user, + activity: reaction_activity, + type: "pleroma:emoji_reaction" + ) + + assert Impl.perform(notif) == {:ok, [:ok]} + end + @tag capture_log: true test "returns error if notif does not match " do assert Impl.perform(%{}) == {:error, :unknown_type} diff --git a/test/pleroma/web/twitter_api/util_controller_test.exs b/test/pleroma/web/twitter_api/util_controller_test.exs index bdbc478c3..f6a552369 100644 --- a/test/pleroma/web/twitter_api/util_controller_test.exs +++ b/test/pleroma/web/twitter_api/util_controller_test.exs @@ -28,6 +28,9 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do |> put("/api/pleroma/notification_settings", %{ "block_from_strangers" => true, "bar" => 1 + "followers" => false, + "bar" => 1, + "exclude_types" => ["follow"] }) |> json_response(:ok) @@ -36,6 +39,12 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do assert %Pleroma.User.NotificationSetting{ block_from_strangers: true, hide_notification_contents: false + followers: false, + follows: true, + non_follows: true, + non_followers: true, + privacy_option: false, + exclude_types: ["follow"] } == user.notification_settings end |