aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/notification_test.exs20
-rw-r--r--test/support/builders/user_builder.ex3
-rw-r--r--test/support/factory.ex3
-rw-r--r--test/user/notification_setting_test.exs21
-rw-r--r--test/user_search_test.exs1
-rw-r--r--test/web/mastodon_api/views/account_view_test.exs8
-rw-r--r--test/web/push/impl_test.exs47
-rw-r--r--test/web/twitter_api/util_controller_test.exs30
8 files changed, 115 insertions, 18 deletions
diff --git a/test/notification_test.exs b/test/notification_test.exs
index 827ac4f06..ffa3d4b8c 100644
--- a/test/notification_test.exs
+++ b/test/notification_test.exs
@@ -136,7 +136,10 @@ defmodule Pleroma.NotificationTest do
test "it disables notifications from followers" do
follower = insert(:user)
- followed = insert(:user, notification_settings: %{"followers" => false})
+
+ followed =
+ insert(:user, notification_settings: %Pleroma.User.NotificationSetting{followers: false})
+
User.follow(follower, followed)
{:ok, activity} = CommonAPI.post(follower, %{"status" => "hey @#{followed.nickname}"})
refute Notification.create_notification(activity, followed)
@@ -144,13 +147,20 @@ defmodule Pleroma.NotificationTest do
test "it disables notifications from non-followers" do
follower = insert(:user)
- followed = insert(:user, notification_settings: %{"non_followers" => false})
+
+ followed =
+ insert(:user,
+ notification_settings: %Pleroma.User.NotificationSetting{non_followers: false}
+ )
+
{: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: %{"follows" => false})
+ follower =
+ insert(:user, notification_settings: %Pleroma.User.NotificationSetting{follows: false})
+
followed = insert(:user)
User.follow(follower, followed)
follower = Repo.get(User, follower.id)
@@ -159,7 +169,9 @@ defmodule Pleroma.NotificationTest do
end
test "it disables notifications from people the user does not follow" do
- follower = insert(:user, notification_settings: %{"non_follows" => false})
+ 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)
diff --git a/test/support/builders/user_builder.ex b/test/support/builders/user_builder.ex
index 6da16f71a..fcfea666f 100644
--- a/test/support/builders/user_builder.ex
+++ b/test/support/builders/user_builder.ex
@@ -10,7 +10,8 @@ defmodule Pleroma.Builders.UserBuilder do
password_hash: Comeonin.Pbkdf2.hashpwsalt("test"),
bio: "A tester.",
ap_id: "some id",
- last_digest_emailed_at: NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second)
+ last_digest_emailed_at: NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second),
+ notification_settings: %Pleroma.User.NotificationSetting{}
}
Map.merge(user, data)
diff --git a/test/support/factory.ex b/test/support/factory.ex
index 35ba523a1..314f26ec9 100644
--- a/test/support/factory.ex
+++ b/test/support/factory.ex
@@ -31,7 +31,8 @@ defmodule Pleroma.Factory do
nickname: sequence(:nickname, &"nick#{&1}"),
password_hash: Comeonin.Pbkdf2.hashpwsalt("test"),
bio: sequence(:bio, &"Tester Number #{&1}"),
- last_digest_emailed_at: NaiveDateTime.utc_now()
+ last_digest_emailed_at: NaiveDateTime.utc_now(),
+ notification_settings: %Pleroma.User.NotificationSetting{}
}
%{
diff --git a/test/user/notification_setting_test.exs b/test/user/notification_setting_test.exs
new file mode 100644
index 000000000..4744d7b4a
--- /dev/null
+++ b/test/user/notification_setting_test.exs
@@ -0,0 +1,21 @@
+# Pleroma: A lightweight social networking server
+# Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
+# SPDX-License-Identifier: AGPL-3.0-only
+
+defmodule Pleroma.User.NotificationSettingTest do
+ use Pleroma.DataCase
+
+ alias Pleroma.User.NotificationSetting
+
+ describe "changeset/2" do
+ test "sets valid privacy option" do
+ changeset =
+ NotificationSetting.changeset(
+ %NotificationSetting{},
+ %{"privacy_option" => true}
+ )
+
+ assert %Ecto.Changeset{valid?: true} = changeset
+ end
+ end
+end
diff --git a/test/user_search_test.exs b/test/user_search_test.exs
index 98841dbbd..821858476 100644
--- a/test/user_search_test.exs
+++ b/test/user_search_test.exs
@@ -174,6 +174,7 @@ defmodule Pleroma.UserSearchTest do
|> Map.put(:search_rank, nil)
|> Map.put(:search_type, nil)
|> Map.put(:last_digest_emailed_at, nil)
+ |> Map.put(:notification_settings, nil)
assert user == expected
end
diff --git a/test/web/mastodon_api/views/account_view_test.exs b/test/web/mastodon_api/views/account_view_test.exs
index ed6f2ecbd..5e297d129 100644
--- a/test/web/mastodon_api/views/account_view_test.exs
+++ b/test/web/mastodon_api/views/account_view_test.exs
@@ -92,13 +92,7 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
test "Represent the user account for the account owner" do
user = insert(:user)
- notification_settings = %{
- "followers" => true,
- "follows" => true,
- "non_follows" => true,
- "non_followers" => true
- }
-
+ notification_settings = %Pleroma.User.NotificationSetting{}
privacy = user.default_scope
assert %{
diff --git a/test/web/push/impl_test.exs b/test/web/push/impl_test.exs
index 9b554601d..acae7a734 100644
--- a/test/web/push/impl_test.exs
+++ b/test/web/push/impl_test.exs
@@ -6,6 +6,7 @@ defmodule Pleroma.Web.Push.ImplTest do
use Pleroma.DataCase
alias Pleroma.Object
+ alias Pleroma.User
alias Pleroma.Web.CommonAPI
alias Pleroma.Web.Push.Impl
alias Pleroma.Web.Push.Subscription
@@ -182,4 +183,50 @@ defmodule Pleroma.Web.Push.ImplTest do
assert Impl.format_title(%{activity: activity}) ==
"New Direct Message"
end
+
+ describe "build_content/3" do
+ test "returns info content for direct message with enabled privacy option" do
+ user = insert(:user, nickname: "Bob")
+ user2 = insert(:user, nickname: "Rob", notification_settings: %{privacy_option: true})
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "visibility" => "direct",
+ "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: "@Bob",
+ title: "New Direct Message"
+ }
+ end
+
+ test "returns regular content for direct message with disabled privacy option" do
+ user = insert(:user, nickname: "Bob")
+ user2 = insert(:user, nickname: "Rob", notification_settings: %{privacy_option: false})
+
+ {:ok, activity} =
+ CommonAPI.post(user, %{
+ "visibility" => "direct",
+ "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 Direct Message"
+ }
+ end
+ end
end
diff --git a/test/web/twitter_api/util_controller_test.exs b/test/web/twitter_api/util_controller_test.exs
index 986ee01f3..734cd2211 100644
--- a/test/web/twitter_api/util_controller_test.exs
+++ b/test/web/twitter_api/util_controller_test.exs
@@ -159,11 +159,31 @@ defmodule Pleroma.Web.TwitterAPI.UtilControllerTest do
user = Repo.get(User, user.id)
- assert %{
- "followers" => false,
- "follows" => true,
- "non_follows" => true,
- "non_followers" => true
+ assert %Pleroma.User.NotificationSetting{
+ followers: false,
+ follows: true,
+ non_follows: true,
+ non_followers: true,
+ privacy_option: false
+ } == user.notification_settings
+ end
+
+ test "it update notificatin privacy option", %{conn: conn} do
+ user = insert(:user)
+
+ conn
+ |> assign(:user, user)
+ |> put("/api/pleroma/notification_settings", %{"privacy_option" => "1"})
+ |> json_response(:ok)
+
+ user = refresh_record(user)
+
+ assert %Pleroma.User.NotificationSetting{
+ followers: true,
+ follows: true,
+ non_follows: true,
+ non_followers: true,
+ privacy_option: true
} == user.notification_settings
end
end