From 9eea80002673eb1359a2d4369c65a89c42c2f707 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Thu, 28 May 2020 10:16:09 -0500 Subject: Refactor notification settings --- test/notification_test.exs | 17 ++++------------- test/web/mastodon_api/views/account_view_test.exs | 7 +++---- test/web/twitter_api/util_controller_test.exs | 16 +++++++--------- 3 files changed, 14 insertions(+), 26 deletions(-) (limited to 'test') diff --git a/test/notification_test.exs b/test/notification_test.exs index 37c255fee..fd59aceb5 100644 --- a/test/notification_test.exs +++ b/test/notification_test.exs @@ -237,19 +237,19 @@ defmodule Pleroma.NotificationTest do follower = insert(:user) followed = - insert(:user, notification_settings: %Pleroma.User.NotificationSetting{followers: false}) + insert(:user, notification_settings: %Pleroma.User.NotificationSetting{from_followers: false}) User.follow(follower, followed) {:ok, activity} = CommonAPI.post(follower, %{status: "hey @#{followed.nickname}"}) refute Notification.create_notification(activity, followed) end - test "it disables notifications from non-followers" do + test "it disables notifications from strangers" do follower = insert(:user) followed = insert(:user, - notification_settings: %Pleroma.User.NotificationSetting{non_followers: false} + notification_settings: %Pleroma.User.NotificationSetting{from_strangers: false} ) {:ok, activity} = CommonAPI.post(follower, %{status: "hey @#{followed.nickname}"}) @@ -258,7 +258,7 @@ defmodule Pleroma.NotificationTest do test "it disables notifications from people the user follows" do follower = - insert(:user, notification_settings: %Pleroma.User.NotificationSetting{follows: false}) + insert(:user, notification_settings: %Pleroma.User.NotificationSetting{from_following: false}) followed = insert(:user) User.follow(follower, followed) @@ -267,15 +267,6 @@ defmodule Pleroma.NotificationTest do refute Notification.create_notification(activity, follower) end - test "it disables notifications from people the user does not follow" do - follower = - insert(:user, notification_settings: %Pleroma.User.NotificationSetting{non_follows: false}) - - followed = insert(:user) - {:ok, activity} = CommonAPI.post(followed, %{status: "hey @#{follower.nickname}"}) - refute Notification.create_notification(activity, follower) - end - test "it doesn't create a notification for user if he is the activity author" do activity = insert(:note_activity) author = User.get_cached_by_ap_id(activity.data["actor"]) diff --git a/test/web/mastodon_api/views/account_view_test.exs b/test/web/mastodon_api/views/account_view_test.exs index 487ec26c2..2e01689ff 100644 --- a/test/web/mastodon_api/views/account_view_test.exs +++ b/test/web/mastodon_api/views/account_view_test.exs @@ -94,10 +94,9 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do user = insert(:user) notification_settings = %{ - followers: true, - follows: true, - non_followers: true, - non_follows: true, + from_followers: true, + from_following: true, + from_strangers: true, privacy_option: false } diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs index ad919d341..1133107f4 100644 --- a/test/web/twitter_api/util_controller_test.exs +++ b/test/web/twitter_api/util_controller_test.exs @@ -191,7 +191,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do test "it updates notification settings", %{user: user, conn: conn} do conn |> put("/api/pleroma/notification_settings", %{ - "followers" => false, + "from_followers" => false, "bar" => 1 }) |> json_response(:ok) @@ -199,10 +199,9 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do user = refresh_record(user) assert %Pleroma.User.NotificationSetting{ - followers: false, - follows: true, - non_follows: true, - non_followers: true, + from_followers: false, + from_following: true, + from_strangers: true, privacy_option: false } == user.notification_settings end @@ -215,10 +214,9 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do user = refresh_record(user) assert %Pleroma.User.NotificationSetting{ - followers: true, - follows: true, - non_follows: true, - non_followers: true, + from_followers: true, + from_following: true, + from_strangers: true, privacy_option: true } == user.notification_settings end -- cgit v1.2.3 From 4c82f657c5aaba6aacbc8ef927c1727509195839 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Thu, 28 May 2020 13:22:28 -0500 Subject: Formatting --- test/notification_test.exs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/notification_test.exs b/test/notification_test.exs index fd59aceb5..a1a7cee2a 100644 --- a/test/notification_test.exs +++ b/test/notification_test.exs @@ -237,7 +237,9 @@ defmodule Pleroma.NotificationTest do follower = insert(:user) followed = - insert(:user, notification_settings: %Pleroma.User.NotificationSetting{from_followers: false}) + insert(:user, + notification_settings: %Pleroma.User.NotificationSetting{from_followers: false} + ) User.follow(follower, followed) {:ok, activity} = CommonAPI.post(follower, %{status: "hey @#{followed.nickname}"}) @@ -258,7 +260,9 @@ defmodule Pleroma.NotificationTest do test "it disables notifications from people the user follows" do follower = - insert(:user, notification_settings: %Pleroma.User.NotificationSetting{from_following: false}) + insert(:user, + notification_settings: %Pleroma.User.NotificationSetting{from_following: false} + ) followed = insert(:user) User.follow(follower, followed) -- cgit v1.2.3 From fd5e797379155e5a85deb88dc79f8fbca483948e Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Fri, 26 Jun 2020 11:24:28 -0500 Subject: Simplify notification filtering settings further --- test/notification_test.exs | 28 +---------------------- test/web/mastodon_api/views/account_view_test.exs | 4 +--- test/web/twitter_api/util_controller_test.exs | 10 +++----- 3 files changed, 5 insertions(+), 37 deletions(-) (limited to 'test') diff --git a/test/notification_test.exs b/test/notification_test.exs index d7df9c36c..d8cb9360a 100644 --- a/test/notification_test.exs +++ b/test/notification_test.exs @@ -236,44 +236,18 @@ defmodule Pleroma.NotificationTest do assert Notification.create_notification(activity, muter) end - test "it disables notifications from followers" do - follower = insert(:user) - - followed = - insert(:user, - notification_settings: %Pleroma.User.NotificationSetting{from_followers: false} - ) - - User.follow(follower, followed) - {:ok, activity} = CommonAPI.post(follower, %{status: "hey @#{followed.nickname}"}) - refute Notification.create_notification(activity, followed) - end - test "it disables notifications from strangers" do follower = insert(:user) followed = insert(:user, - notification_settings: %Pleroma.User.NotificationSetting{from_strangers: false} + notification_settings: %Pleroma.User.NotificationSetting{block_from_strangers: true} ) {:ok, activity} = CommonAPI.post(follower, %{status: "hey @#{followed.nickname}"}) refute Notification.create_notification(activity, followed) end - test "it disables notifications from people the user follows" do - follower = - insert(:user, - notification_settings: %Pleroma.User.NotificationSetting{from_following: false} - ) - - followed = insert(:user) - User.follow(follower, followed) - follower = Repo.get(User, follower.id) - {:ok, activity} = CommonAPI.post(followed, %{status: "hey @#{follower.nickname}"}) - refute Notification.create_notification(activity, follower) - end - test "it doesn't create a notification for user if he is the activity author" do activity = insert(:note_activity) author = User.get_cached_by_ap_id(activity.data["actor"]) diff --git a/test/web/mastodon_api/views/account_view_test.exs b/test/web/mastodon_api/views/account_view_test.exs index 572830194..b6d820b3f 100644 --- a/test/web/mastodon_api/views/account_view_test.exs +++ b/test/web/mastodon_api/views/account_view_test.exs @@ -96,9 +96,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do user = insert(:user) notification_settings = %{ - from_followers: true, - from_following: true, - from_strangers: true, + block_from_strangers: false, privacy_option: false } diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs index 1133107f4..da3f6fa61 100644 --- a/test/web/twitter_api/util_controller_test.exs +++ b/test/web/twitter_api/util_controller_test.exs @@ -191,7 +191,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do test "it updates notification settings", %{user: user, conn: conn} do conn |> put("/api/pleroma/notification_settings", %{ - "from_followers" => false, + "block_from_strangers" => true, "bar" => 1 }) |> json_response(:ok) @@ -199,9 +199,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do user = refresh_record(user) assert %Pleroma.User.NotificationSetting{ - from_followers: false, - from_following: true, - from_strangers: true, + block_from_strangers: true, privacy_option: false } == user.notification_settings end @@ -214,9 +212,7 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do user = refresh_record(user) assert %Pleroma.User.NotificationSetting{ - from_followers: true, - from_following: true, - from_strangers: true, + block_from_strangers: false, privacy_option: true } == user.notification_settings end -- cgit v1.2.3 From 69848d5c97c9e5d4c14fb5613eb174cb81d5026d Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Fri, 26 Jun 2020 12:45:46 -0500 Subject: Rename notification "privacy_option" setting --- test/user/notification_setting_test.exs | 4 ++-- test/web/mastodon_api/views/account_view_test.exs | 2 +- test/web/push/impl_test.exs | 8 ++++---- test/web/twitter_api/util_controller_test.exs | 8 ++++---- 4 files changed, 11 insertions(+), 11 deletions(-) (limited to 'test') diff --git a/test/user/notification_setting_test.exs b/test/user/notification_setting_test.exs index 95bca22c4..308da216a 100644 --- a/test/user/notification_setting_test.exs +++ b/test/user/notification_setting_test.exs @@ -8,11 +8,11 @@ defmodule Pleroma.User.NotificationSettingTest do alias Pleroma.User.NotificationSetting describe "changeset/2" do - test "sets valid privacy option" do + test "sets option to hide notification contents" do changeset = NotificationSetting.changeset( %NotificationSetting{}, - %{"privacy_option" => true} + %{"hide_notification_contents" => true} ) assert %Ecto.Changeset{valid?: true} = changeset diff --git a/test/web/mastodon_api/views/account_view_test.exs b/test/web/mastodon_api/views/account_view_test.exs index b6d820b3f..ce45cb9e9 100644 --- a/test/web/mastodon_api/views/account_view_test.exs +++ b/test/web/mastodon_api/views/account_view_test.exs @@ -97,7 +97,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do notification_settings = %{ block_from_strangers: false, - privacy_option: false + hide_notification_contents: false } privacy = user.default_scope diff --git a/test/web/push/impl_test.exs b/test/web/push/impl_test.exs index b48952b29..15de5e853 100644 --- a/test/web/push/impl_test.exs +++ b/test/web/push/impl_test.exs @@ -238,9 +238,9 @@ defmodule Pleroma.Web.Push.ImplTest do } end - test "hides details for notifications when privacy option enabled" do + test "hides contents of notifications when option enabled" do user = insert(:user, nickname: "Bob") - user2 = insert(:user, nickname: "Rob", notification_settings: %{privacy_option: true}) + user2 = insert(:user, nickname: "Rob", notification_settings: %{hide_notification_contents: true}) {:ok, activity} = CommonAPI.post(user, %{ @@ -284,9 +284,9 @@ defmodule Pleroma.Web.Push.ImplTest do } end - test "returns regular content for notifications with privacy option disabled" do + test "returns regular content when hiding contents option disabled" do user = insert(:user, nickname: "Bob") - user2 = insert(:user, nickname: "Rob", notification_settings: %{privacy_option: false}) + user2 = insert(:user, nickname: "Rob", notification_settings: %{hide_notification_contents: false}) {:ok, activity} = CommonAPI.post(user, %{ diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs index da3f6fa61..b8ddadb50 100644 --- a/test/web/twitter_api/util_controller_test.exs +++ b/test/web/twitter_api/util_controller_test.exs @@ -200,20 +200,20 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do assert %Pleroma.User.NotificationSetting{ block_from_strangers: true, - privacy_option: false + hide_notification_contents: false } == user.notification_settings end - test "it updates notification privacy option", %{user: user, conn: conn} do + test "it updates notification settings to enable hiding contents", %{user: user, conn: conn} do conn - |> put("/api/pleroma/notification_settings", %{"privacy_option" => "1"}) + |> put("/api/pleroma/notification_settings", %{"hide_notification_contents" => "1"}) |> json_response(:ok) user = refresh_record(user) assert %Pleroma.User.NotificationSetting{ block_from_strangers: false, - privacy_option: true + hide_notification_contents: true } == user.notification_settings end end -- cgit v1.2.3 From ce85db41a30d95555bbd44d8931c4a3a357938d8 Mon Sep 17 00:00:00 2001 From: Mark Felder Date: Fri, 26 Jun 2020 14:35:04 -0500 Subject: Lint --- test/web/push/impl_test.exs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'test') diff --git a/test/web/push/impl_test.exs b/test/web/push/impl_test.exs index 15de5e853..aeb5c1fbd 100644 --- a/test/web/push/impl_test.exs +++ b/test/web/push/impl_test.exs @@ -240,7 +240,9 @@ defmodule Pleroma.Web.Push.ImplTest do test "hides contents of notifications when option enabled" do user = insert(:user, nickname: "Bob") - user2 = insert(:user, nickname: "Rob", notification_settings: %{hide_notification_contents: true}) + + user2 = + insert(:user, nickname: "Rob", notification_settings: %{hide_notification_contents: true}) {:ok, activity} = CommonAPI.post(user, %{ @@ -286,7 +288,9 @@ defmodule Pleroma.Web.Push.ImplTest do test "returns regular content when hiding contents option disabled" do user = insert(:user, nickname: "Bob") - user2 = insert(:user, nickname: "Rob", notification_settings: %{hide_notification_contents: false}) + + user2 = + insert(:user, nickname: "Rob", notification_settings: %{hide_notification_contents: false}) {:ok, activity} = CommonAPI.post(user, %{ -- cgit v1.2.3