1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2019 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
5 defmodule Pleroma.UserTest do
7 alias Pleroma.Builders.UserBuilder
10 alias Pleroma.Tests.ObanHelpers
12 alias Pleroma.Web.ActivityPub.ActivityPub
13 alias Pleroma.Web.CommonAPI
16 use Oban.Testing, repo: Pleroma.Repo
19 import Pleroma.Factory
22 Tesla.Mock.mock_global(fn env -> apply(HttpRequestMock, :request, [env]) end)
26 clear_config([:instance, :account_activation_required])
28 describe "service actors" do
29 test "returns invisible actor" do
30 uri = "#{Pleroma.Web.Endpoint.url()}/internal/fetch-test"
31 followers_uri = "#{uri}/followers"
32 user = User.get_or_create_service_actor_by_ap_id(uri, "internal.fetch-test")
35 nickname: "internal.fetch-test",
39 follower_address: ^followers_uri
42 user2 = User.get_or_create_service_actor_by_ap_id(uri, "internal.fetch-test")
43 assert user.id == user2.id
47 describe "AP ID user relationships" do
49 {:ok, user: insert(:user)}
52 test "outgoing_relations_ap_ids/1", %{user: user} do
53 rel_types = [:block, :mute, :notification_mute, :reblog_mute, :inverse_subscription]
61 insert_list(2, :user_relationship, %{source: user, relationship_type: rel_type})
63 ap_ids = Enum.map(rel_records, fn rr -> Repo.preload(rr, :target).target.ap_id end)
64 {rel_type, Enum.sort(ap_ids)}
68 assert ap_ids_by_rel[:block] == Enum.sort(User.blocked_users_ap_ids(user))
69 assert ap_ids_by_rel[:block] == Enum.sort(Enum.map(User.blocked_users(user), & &1.ap_id))
71 assert ap_ids_by_rel[:mute] == Enum.sort(User.muted_users_ap_ids(user))
72 assert ap_ids_by_rel[:mute] == Enum.sort(Enum.map(User.muted_users(user), & &1.ap_id))
74 assert ap_ids_by_rel[:notification_mute] ==
75 Enum.sort(User.notification_muted_users_ap_ids(user))
77 assert ap_ids_by_rel[:notification_mute] ==
78 Enum.sort(Enum.map(User.notification_muted_users(user), & &1.ap_id))
80 assert ap_ids_by_rel[:reblog_mute] == Enum.sort(User.reblog_muted_users_ap_ids(user))
82 assert ap_ids_by_rel[:reblog_mute] ==
83 Enum.sort(Enum.map(User.reblog_muted_users(user), & &1.ap_id))
85 assert ap_ids_by_rel[:inverse_subscription] == Enum.sort(User.subscriber_users_ap_ids(user))
87 assert ap_ids_by_rel[:inverse_subscription] ==
88 Enum.sort(Enum.map(User.subscriber_users(user), & &1.ap_id))
90 outgoing_relations_ap_ids = User.outgoing_relations_ap_ids(user, rel_types)
92 assert ap_ids_by_rel ==
93 Enum.into(outgoing_relations_ap_ids, %{}, fn {k, v} -> {k, Enum.sort(v)} end)
97 describe "when tags are nil" do
98 test "tagging a user" do
99 user = insert(:user, %{tags: nil})
100 user = User.tag(user, ["cool", "dude"])
102 assert "cool" in user.tags
103 assert "dude" in user.tags
106 test "untagging a user" do
107 user = insert(:user, %{tags: nil})
108 user = User.untag(user, ["cool", "dude"])
110 assert user.tags == []
114 test "ap_id returns the activity pub id for the user" do
115 user = UserBuilder.build()
117 expected_ap_id = "#{Pleroma.Web.base_url()}/users/#{user.nickname}"
119 assert expected_ap_id == User.ap_id(user)
122 test "ap_followers returns the followers collection for the user" do
123 user = UserBuilder.build()
125 expected_followers_collection = "#{User.ap_id(user)}/followers"
127 assert expected_followers_collection == User.ap_followers(user)
130 test "ap_following returns the following collection for the user" do
131 user = UserBuilder.build()
133 expected_followers_collection = "#{User.ap_id(user)}/following"
135 assert expected_followers_collection == User.ap_following(user)
138 test "returns all pending follow requests" do
139 unlocked = insert(:user)
140 locked = insert(:user, locked: true)
141 follower = insert(:user)
143 CommonAPI.follow(follower, unlocked)
144 CommonAPI.follow(follower, locked)
146 assert [] = User.get_follow_requests(unlocked)
147 assert [activity] = User.get_follow_requests(locked)
152 test "doesn't return already accepted or duplicate follow requests" do
153 locked = insert(:user, locked: true)
154 pending_follower = insert(:user)
155 accepted_follower = insert(:user)
157 CommonAPI.follow(pending_follower, locked)
158 CommonAPI.follow(pending_follower, locked)
159 CommonAPI.follow(accepted_follower, locked)
160 Pleroma.FollowingRelationship.update(accepted_follower, locked, "accept")
162 assert [^pending_follower] = User.get_follow_requests(locked)
165 test "clears follow requests when requester is blocked" do
166 followed = insert(:user, locked: true)
167 follower = insert(:user)
169 CommonAPI.follow(follower, followed)
170 assert [_activity] = User.get_follow_requests(followed)
172 {:ok, _user_relationship} = User.block(followed, follower)
173 assert [] = User.get_follow_requests(followed)
176 test "follow_all follows mutliple users" do
178 followed_zero = insert(:user)
179 followed_one = insert(:user)
180 followed_two = insert(:user)
181 blocked = insert(:user)
182 not_followed = insert(:user)
183 reverse_blocked = insert(:user)
185 {:ok, _user_relationship} = User.block(user, blocked)
186 {:ok, _user_relationship} = User.block(reverse_blocked, user)
188 {:ok, user} = User.follow(user, followed_zero)
190 {:ok, user} = User.follow_all(user, [followed_one, followed_two, blocked, reverse_blocked])
192 assert User.following?(user, followed_one)
193 assert User.following?(user, followed_two)
194 assert User.following?(user, followed_zero)
195 refute User.following?(user, not_followed)
196 refute User.following?(user, blocked)
197 refute User.following?(user, reverse_blocked)
200 test "follow_all follows mutliple users without duplicating" do
202 followed_zero = insert(:user)
203 followed_one = insert(:user)
204 followed_two = insert(:user)
206 {:ok, user} = User.follow_all(user, [followed_zero, followed_one])
207 assert length(User.following(user)) == 3
209 {:ok, user} = User.follow_all(user, [followed_one, followed_two])
210 assert length(User.following(user)) == 4
213 test "follow takes a user and another user" do
215 followed = insert(:user)
217 {:ok, user} = User.follow(user, followed)
219 user = User.get_cached_by_id(user.id)
220 followed = User.get_cached_by_ap_id(followed.ap_id)
222 assert followed.follower_count == 1
223 assert user.following_count == 1
225 assert User.ap_followers(followed) in User.following(user)
228 test "can't follow a deactivated users" do
230 followed = insert(:user, %{deactivated: true})
232 {:error, _} = User.follow(user, followed)
235 test "can't follow a user who blocked us" do
236 blocker = insert(:user)
237 blockee = insert(:user)
239 {:ok, _user_relationship} = User.block(blocker, blockee)
241 {:error, _} = User.follow(blockee, blocker)
244 test "can't subscribe to a user who blocked us" do
245 blocker = insert(:user)
246 blocked = insert(:user)
248 {:ok, _user_relationship} = User.block(blocker, blocked)
250 {:error, _} = User.subscribe(blocked, blocker)
253 test "local users do not automatically follow local locked accounts" do
254 follower = insert(:user, locked: true)
255 followed = insert(:user, locked: true)
257 {:ok, follower} = User.maybe_direct_follow(follower, followed)
259 refute User.following?(follower, followed)
262 describe "unfollow/2" do
264 setting = Pleroma.Config.get([:instance, :external_user_synchronization])
267 Pleroma.Config.put([:instance, :external_user_synchronization], setting)
273 test "unfollow with syncronizes external user" do
274 Pleroma.Config.put([:instance, :external_user_synchronization], true)
279 follower_address: "http://localhost:4001/users/fuser1/followers",
280 following_address: "http://localhost:4001/users/fuser1/following",
281 ap_id: "http://localhost:4001/users/fuser1"
288 ap_id: "http://localhost:4001/users/fuser2",
289 follower_address: "http://localhost:4001/users/fuser2/followers",
290 following_address: "http://localhost:4001/users/fuser2/following"
293 {:ok, user} = User.follow(user, followed, "accept")
295 {:ok, user, _activity} = User.unfollow(user, followed)
297 user = User.get_cached_by_id(user.id)
299 assert User.following(user) == []
302 test "unfollow takes a user and another user" do
303 followed = insert(:user)
306 {:ok, user} = User.follow(user, followed, "accept")
308 assert User.following(user) == [user.follower_address, followed.follower_address]
310 {:ok, user, _activity} = User.unfollow(user, followed)
312 assert User.following(user) == [user.follower_address]
315 test "unfollow doesn't unfollow yourself" do
318 {:error, _} = User.unfollow(user, user)
320 assert User.following(user) == [user.follower_address]
324 test "test if a user is following another user" do
325 followed = insert(:user)
327 User.follow(user, followed, "accept")
329 assert User.following?(user, followed)
330 refute User.following?(followed, user)
333 test "fetches correct profile for nickname beginning with number" do
334 # Use old-style integer ID to try to reproduce the problem
335 user = insert(:user, %{id: 1080})
336 user_with_numbers = insert(:user, %{nickname: "#{user.id}garbage"})
337 assert user_with_numbers == User.get_cached_by_nickname_or_id(user_with_numbers.nickname)
340 describe "user registration" do
346 password_confirmation: "test",
347 email: "email@example.com"
349 clear_config([:instance, :autofollowed_nicknames])
350 clear_config([:instance, :welcome_message])
351 clear_config([:instance, :welcome_user_nickname])
353 test "it autofollows accounts that are set for it" do
355 remote_user = insert(:user, %{local: false})
357 Pleroma.Config.put([:instance, :autofollowed_nicknames], [
362 cng = User.register_changeset(%User{}, @full_user_data)
364 {:ok, registered_user} = User.register(cng)
366 assert User.following?(registered_user, user)
367 refute User.following?(registered_user, remote_user)
370 test "it sends a welcome message if it is set" do
371 welcome_user = insert(:user)
373 Pleroma.Config.put([:instance, :welcome_user_nickname], welcome_user.nickname)
374 Pleroma.Config.put([:instance, :welcome_message], "Hello, this is a cool site")
376 cng = User.register_changeset(%User{}, @full_user_data)
377 {:ok, registered_user} = User.register(cng)
379 activity = Repo.one(Pleroma.Activity)
380 assert registered_user.ap_id in activity.recipients
381 assert Object.normalize(activity).data["content"] =~ "cool site"
382 assert activity.actor == welcome_user.ap_id
385 test "it requires an email, name, nickname and password, bio is optional" do
388 |> Enum.each(fn key ->
389 params = Map.delete(@full_user_data, key)
390 changeset = User.register_changeset(%User{}, params)
392 assert if key == :bio, do: changeset.valid?, else: not changeset.valid?
396 test "it restricts certain nicknames" do
397 [restricted_name | _] = Pleroma.Config.get([User, :restricted_nicknames])
399 assert is_bitstring(restricted_name)
403 |> Map.put(:nickname, restricted_name)
405 changeset = User.register_changeset(%User{}, params)
407 refute changeset.valid?
410 test "it sets the password_hash and ap_id" do
411 changeset = User.register_changeset(%User{}, @full_user_data)
413 assert changeset.valid?
415 assert is_binary(changeset.changes[:password_hash])
416 assert changeset.changes[:ap_id] == User.ap_id(%User{nickname: @full_user_data.nickname})
418 assert changeset.changes.follower_address == "#{changeset.changes.ap_id}/followers"
422 describe "user registration, with :account_activation_required" do
428 password_confirmation: "test",
429 email: "email@example.com"
432 clear_config([:instance, :account_activation_required]) do
433 Pleroma.Config.put([:instance, :account_activation_required], true)
436 test "it creates unconfirmed user" do
437 changeset = User.register_changeset(%User{}, @full_user_data)
438 assert changeset.valid?
440 {:ok, user} = Repo.insert(changeset)
442 assert user.confirmation_pending
443 assert user.confirmation_token
446 test "it creates confirmed user if :confirmed option is given" do
447 changeset = User.register_changeset(%User{}, @full_user_data, need_confirmation: false)
448 assert changeset.valid?
450 {:ok, user} = Repo.insert(changeset)
452 refute user.confirmation_pending
453 refute user.confirmation_token
457 describe "get_or_fetch/1" do
458 test "gets an existing user by nickname" do
460 {:ok, fetched_user} = User.get_or_fetch(user.nickname)
462 assert user == fetched_user
465 test "gets an existing user by ap_id" do
466 ap_id = "http://mastodon.example.org/users/admin"
472 nickname: "admin@mastodon.example.org",
476 {:ok, fetched_user} = User.get_or_fetch(ap_id)
477 freshed_user = refresh_record(user)
478 assert freshed_user == fetched_user
482 describe "fetching a user from nickname or trying to build one" do
483 test "gets an existing user" do
485 {:ok, fetched_user} = User.get_or_fetch_by_nickname(user.nickname)
487 assert user == fetched_user
490 test "gets an existing user, case insensitive" do
491 user = insert(:user, nickname: "nick")
492 {:ok, fetched_user} = User.get_or_fetch_by_nickname("NICK")
494 assert user == fetched_user
497 test "gets an existing user by fully qualified nickname" do
500 {:ok, fetched_user} =
501 User.get_or_fetch_by_nickname(user.nickname <> "@" <> Pleroma.Web.Endpoint.host())
503 assert user == fetched_user
506 test "gets an existing user by fully qualified nickname, case insensitive" do
507 user = insert(:user, nickname: "nick")
508 casing_altered_fqn = String.upcase(user.nickname <> "@" <> Pleroma.Web.Endpoint.host())
510 {:ok, fetched_user} = User.get_or_fetch_by_nickname(casing_altered_fqn)
512 assert user == fetched_user
515 test "returns nil if no user could be fetched" do
516 {:error, fetched_user} = User.get_or_fetch_by_nickname("nonexistant@social.heldscal.la")
517 assert fetched_user == "not found nonexistant@social.heldscal.la"
520 test "returns nil for nonexistant local user" do
521 {:error, fetched_user} = User.get_or_fetch_by_nickname("nonexistant")
522 assert fetched_user == "not found nonexistant"
525 test "updates an existing user, if stale" do
526 a_week_ago = NaiveDateTime.add(NaiveDateTime.utc_now(), -604_800)
532 nickname: "admin@mastodon.example.org",
533 ap_id: "http://mastodon.example.org/users/admin",
534 last_refreshed_at: a_week_ago
537 assert orig_user.last_refreshed_at == a_week_ago
539 {:ok, user} = User.get_or_fetch_by_ap_id("http://mastodon.example.org/users/admin")
541 assert user.source_data["endpoints"]
543 refute user.last_refreshed_at == orig_user.last_refreshed_at
547 test "returns an ap_id for a user" do
550 assert User.ap_id(user) ==
551 Pleroma.Web.Router.Helpers.feed_url(
552 Pleroma.Web.Endpoint,
558 test "returns an ap_followers link for a user" do
561 assert User.ap_followers(user) ==
562 Pleroma.Web.Router.Helpers.feed_url(
563 Pleroma.Web.Endpoint,
569 describe "remote user creation changeset" do
575 avatar: %{some: "avatar"}
578 clear_config([:instance, :user_bio_length])
579 clear_config([:instance, :user_name_length])
581 test "it confirms validity" do
582 cs = User.remote_user_creation(@valid_remote)
586 test "it sets the follower_adress" do
587 cs = User.remote_user_creation(@valid_remote)
588 # remote users get a fake local follower address
589 assert cs.changes.follower_address ==
590 User.ap_followers(%User{nickname: @valid_remote[:nickname]})
593 test "it enforces the fqn format for nicknames" do
594 cs = User.remote_user_creation(%{@valid_remote | nickname: "bla"})
595 assert Ecto.Changeset.get_field(cs, :local) == false
596 assert cs.changes.avatar
600 test "it has required fields" do
602 |> Enum.each(fn field ->
603 cs = User.remote_user_creation(Map.delete(@valid_remote, field))
609 describe "followers and friends" do
610 test "gets all followers for a given user" do
612 follower_one = insert(:user)
613 follower_two = insert(:user)
614 not_follower = insert(:user)
616 {:ok, follower_one} = User.follow(follower_one, user)
617 {:ok, follower_two} = User.follow(follower_two, user)
619 res = User.get_followers(user)
621 assert Enum.member?(res, follower_one)
622 assert Enum.member?(res, follower_two)
623 refute Enum.member?(res, not_follower)
626 test "gets all friends (followed users) for a given user" do
628 followed_one = insert(:user)
629 followed_two = insert(:user)
630 not_followed = insert(:user)
632 {:ok, user} = User.follow(user, followed_one)
633 {:ok, user} = User.follow(user, followed_two)
635 res = User.get_friends(user)
637 followed_one = User.get_cached_by_ap_id(followed_one.ap_id)
638 followed_two = User.get_cached_by_ap_id(followed_two.ap_id)
639 assert Enum.member?(res, followed_one)
640 assert Enum.member?(res, followed_two)
641 refute Enum.member?(res, not_followed)
645 describe "updating note and follower count" do
646 test "it sets the note_count property" do
649 user = User.get_cached_by_ap_id(note.data["actor"])
651 assert user.note_count == 0
653 {:ok, user} = User.update_note_count(user)
655 assert user.note_count == 1
658 test "it increases the note_count property" do
660 user = User.get_cached_by_ap_id(note.data["actor"])
662 assert user.note_count == 0
664 {:ok, user} = User.increase_note_count(user)
666 assert user.note_count == 1
668 {:ok, user} = User.increase_note_count(user)
670 assert user.note_count == 2
673 test "it decreases the note_count property" do
675 user = User.get_cached_by_ap_id(note.data["actor"])
677 assert user.note_count == 0
679 {:ok, user} = User.increase_note_count(user)
681 assert user.note_count == 1
683 {:ok, user} = User.decrease_note_count(user)
685 assert user.note_count == 0
687 {:ok, user} = User.decrease_note_count(user)
689 assert user.note_count == 0
692 test "it sets the follower_count property" do
694 follower = insert(:user)
696 User.follow(follower, user)
698 assert user.follower_count == 0
700 {:ok, user} = User.update_follower_count(user)
702 assert user.follower_count == 1
706 describe "follow_import" do
707 test "it imports user followings from list" do
708 [user1, user2, user3] = insert_list(3, :user)
715 {:ok, job} = User.follow_import(user1, identifiers)
716 result = ObanHelpers.perform(job)
718 assert is_list(result)
719 assert result == [user2, user3]
724 test "it mutes people" do
726 muted_user = insert(:user)
728 refute User.mutes?(user, muted_user)
729 refute User.muted_notifications?(user, muted_user)
731 {:ok, _user_relationships} = User.mute(user, muted_user)
733 assert User.mutes?(user, muted_user)
734 assert User.muted_notifications?(user, muted_user)
737 test "it unmutes users" do
739 muted_user = insert(:user)
741 {:ok, _user_relationships} = User.mute(user, muted_user)
742 {:ok, _user_mute} = User.unmute(user, muted_user)
744 refute User.mutes?(user, muted_user)
745 refute User.muted_notifications?(user, muted_user)
748 test "it mutes user without notifications" do
750 muted_user = insert(:user)
752 refute User.mutes?(user, muted_user)
753 refute User.muted_notifications?(user, muted_user)
755 {:ok, _user_relationships} = User.mute(user, muted_user, false)
757 assert User.mutes?(user, muted_user)
758 refute User.muted_notifications?(user, muted_user)
763 test "it blocks people" do
765 blocked_user = insert(:user)
767 refute User.blocks?(user, blocked_user)
769 {:ok, _user_relationship} = User.block(user, blocked_user)
771 assert User.blocks?(user, blocked_user)
774 test "it unblocks users" do
776 blocked_user = insert(:user)
778 {:ok, _user_relationship} = User.block(user, blocked_user)
779 {:ok, _user_block} = User.unblock(user, blocked_user)
781 refute User.blocks?(user, blocked_user)
784 test "blocks tear down cyclical follow relationships" do
785 blocker = insert(:user)
786 blocked = insert(:user)
788 {:ok, blocker} = User.follow(blocker, blocked)
789 {:ok, blocked} = User.follow(blocked, blocker)
791 assert User.following?(blocker, blocked)
792 assert User.following?(blocked, blocker)
794 {:ok, _user_relationship} = User.block(blocker, blocked)
795 blocked = User.get_cached_by_id(blocked.id)
797 assert User.blocks?(blocker, blocked)
799 refute User.following?(blocker, blocked)
800 refute User.following?(blocked, blocker)
803 test "blocks tear down blocker->blocked follow relationships" do
804 blocker = insert(:user)
805 blocked = insert(:user)
807 {:ok, blocker} = User.follow(blocker, blocked)
809 assert User.following?(blocker, blocked)
810 refute User.following?(blocked, blocker)
812 {:ok, _user_relationship} = User.block(blocker, blocked)
813 blocked = User.get_cached_by_id(blocked.id)
815 assert User.blocks?(blocker, blocked)
817 refute User.following?(blocker, blocked)
818 refute User.following?(blocked, blocker)
821 test "blocks tear down blocked->blocker follow relationships" do
822 blocker = insert(:user)
823 blocked = insert(:user)
825 {:ok, blocked} = User.follow(blocked, blocker)
827 refute User.following?(blocker, blocked)
828 assert User.following?(blocked, blocker)
830 {:ok, _user_relationship} = User.block(blocker, blocked)
831 blocked = User.get_cached_by_id(blocked.id)
833 assert User.blocks?(blocker, blocked)
835 refute User.following?(blocker, blocked)
836 refute User.following?(blocked, blocker)
839 test "blocks tear down blocked->blocker subscription relationships" do
840 blocker = insert(:user)
841 blocked = insert(:user)
843 {:ok, _subscription} = User.subscribe(blocked, blocker)
845 assert User.subscribed_to?(blocked, blocker)
846 refute User.subscribed_to?(blocker, blocked)
848 {:ok, _user_relationship} = User.block(blocker, blocked)
850 assert User.blocks?(blocker, blocked)
851 refute User.subscribed_to?(blocker, blocked)
852 refute User.subscribed_to?(blocked, blocker)
856 describe "domain blocking" do
857 test "blocks domains" do
859 collateral_user = insert(:user, %{ap_id: "https://awful-and-rude-instance.com/user/bully"})
861 {:ok, user} = User.block_domain(user, "awful-and-rude-instance.com")
863 assert User.blocks?(user, collateral_user)
866 test "does not block domain with same end" do
870 insert(:user, %{ap_id: "https://another-awful-and-rude-instance.com/user/bully"})
872 {:ok, user} = User.block_domain(user, "awful-and-rude-instance.com")
874 refute User.blocks?(user, collateral_user)
877 test "does not block domain with same end if wildcard added" do
881 insert(:user, %{ap_id: "https://another-awful-and-rude-instance.com/user/bully"})
883 {:ok, user} = User.block_domain(user, "*.awful-and-rude-instance.com")
885 refute User.blocks?(user, collateral_user)
888 test "blocks domain with wildcard for subdomain" do
891 user_from_subdomain =
892 insert(:user, %{ap_id: "https://subdomain.awful-and-rude-instance.com/user/bully"})
894 user_with_two_subdomains =
896 ap_id: "https://subdomain.second_subdomain.awful-and-rude-instance.com/user/bully"
899 user_domain = insert(:user, %{ap_id: "https://awful-and-rude-instance.com/user/bully"})
901 {:ok, user} = User.block_domain(user, "*.awful-and-rude-instance.com")
903 assert User.blocks?(user, user_from_subdomain)
904 assert User.blocks?(user, user_with_two_subdomains)
905 assert User.blocks?(user, user_domain)
908 test "unblocks domains" do
910 collateral_user = insert(:user, %{ap_id: "https://awful-and-rude-instance.com/user/bully"})
912 {:ok, user} = User.block_domain(user, "awful-and-rude-instance.com")
913 {:ok, user} = User.unblock_domain(user, "awful-and-rude-instance.com")
915 refute User.blocks?(user, collateral_user)
919 describe "blocks_import" do
920 test "it imports user blocks from list" do
921 [user1, user2, user3] = insert_list(3, :user)
928 {:ok, job} = User.blocks_import(user1, identifiers)
929 result = ObanHelpers.perform(job)
931 assert is_list(result)
932 assert result == [user2, user3]
936 describe "get_recipients_from_activity" do
937 test "get recipients" do
938 actor = insert(:user)
939 user = insert(:user, local: true)
940 user_two = insert(:user, local: false)
941 addressed = insert(:user, local: true)
942 addressed_remote = insert(:user, local: false)
945 CommonAPI.post(actor, %{
946 "status" => "hey @#{addressed.nickname} @#{addressed_remote.nickname}"
949 assert Enum.map([actor, addressed], & &1.ap_id) --
950 Enum.map(User.get_recipients_from_activity(activity), & &1.ap_id) == []
952 {:ok, user} = User.follow(user, actor)
953 {:ok, _user_two} = User.follow(user_two, actor)
954 recipients = User.get_recipients_from_activity(activity)
955 assert length(recipients) == 3
956 assert user in recipients
957 assert addressed in recipients
960 test "has following" do
961 actor = insert(:user)
963 user_two = insert(:user)
964 addressed = insert(:user, local: true)
967 CommonAPI.post(actor, %{
968 "status" => "hey @#{addressed.nickname}"
971 assert Enum.map([actor, addressed], & &1.ap_id) --
972 Enum.map(User.get_recipients_from_activity(activity), & &1.ap_id) == []
974 {:ok, _actor} = User.follow(actor, user)
975 {:ok, _actor} = User.follow(actor, user_two)
976 recipients = User.get_recipients_from_activity(activity)
977 assert length(recipients) == 2
978 assert addressed in recipients
982 describe ".deactivate" do
983 test "can de-activate then re-activate a user" do
985 assert false == user.deactivated
986 {:ok, user} = User.deactivate(user)
987 assert true == user.deactivated
988 {:ok, user} = User.deactivate(user, false)
989 assert false == user.deactivated
992 test "hide a user from followers" do
994 user2 = insert(:user)
996 {:ok, user} = User.follow(user, user2)
997 {:ok, _user} = User.deactivate(user)
999 user2 = User.get_cached_by_id(user2.id)
1001 assert user2.follower_count == 0
1002 assert [] = User.get_followers(user2)
1005 test "hide a user from friends" do
1006 user = insert(:user)
1007 user2 = insert(:user)
1009 {:ok, user2} = User.follow(user2, user)
1010 assert user2.following_count == 1
1011 assert User.following_count(user2) == 1
1013 {:ok, _user} = User.deactivate(user)
1015 user2 = User.get_cached_by_id(user2.id)
1017 assert refresh_record(user2).following_count == 0
1018 assert user2.following_count == 0
1019 assert User.following_count(user2) == 0
1020 assert [] = User.get_friends(user2)
1023 test "hide a user's statuses from timelines and notifications" do
1024 user = insert(:user)
1025 user2 = insert(:user)
1027 {:ok, user2} = User.follow(user2, user)
1029 {:ok, activity} = CommonAPI.post(user, %{"status" => "hey @#{user2.nickname}"})
1031 activity = Repo.preload(activity, :bookmark)
1033 [notification] = Pleroma.Notification.for_user(user2)
1034 assert notification.activity.id == activity.id
1036 assert [activity] == ActivityPub.fetch_public_activities(%{}) |> Repo.preload(:bookmark)
1038 assert [%{activity | thread_muted?: CommonAPI.thread_muted?(user2, activity)}] ==
1039 ActivityPub.fetch_activities([user2.ap_id | User.following(user2)], %{
1043 {:ok, _user} = User.deactivate(user)
1045 assert [] == ActivityPub.fetch_public_activities(%{})
1046 assert [] == Pleroma.Notification.for_user(user2)
1049 ActivityPub.fetch_activities([user2.ap_id | User.following(user2)], %{
1055 describe "delete" do
1057 {:ok, user} = insert(:user) |> User.set_cache()
1062 clear_config([:instance, :federating])
1064 test ".delete_user_activities deletes all create activities", %{user: user} do
1065 {:ok, activity} = CommonAPI.post(user, %{"status" => "2hu"})
1067 User.delete_user_activities(user)
1069 # TODO: Remove favorites, repeats, delete activities.
1070 refute Activity.get_by_id(activity.id)
1073 test "it deletes deactivated user" do
1074 {:ok, user} = insert(:user, deactivated: true) |> User.set_cache()
1076 {:ok, job} = User.delete(user)
1077 {:ok, _user} = ObanHelpers.perform(job)
1079 refute User.get_by_id(user.id)
1082 test "it deletes a user, all follow relationships and all activities", %{user: user} do
1083 follower = insert(:user)
1084 {:ok, follower} = User.follow(follower, user)
1086 object = insert(:note, user: user)
1087 activity = insert(:note_activity, user: user, note: object)
1089 object_two = insert(:note, user: follower)
1090 activity_two = insert(:note_activity, user: follower, note: object_two)
1092 {:ok, like, _} = CommonAPI.favorite(activity_two.id, user)
1093 {:ok, like_two, _} = CommonAPI.favorite(activity.id, follower)
1094 {:ok, repeat, _} = CommonAPI.repeat(activity_two.id, user)
1096 {:ok, job} = User.delete(user)
1097 {:ok, _user} = ObanHelpers.perform(job)
1099 follower = User.get_cached_by_id(follower.id)
1101 refute User.following?(follower, user)
1102 refute User.get_by_id(user.id)
1103 assert {:ok, nil} == Cachex.get(:user_cache, "ap_id:#{user.ap_id}")
1107 |> Activity.Queries.by_actor()
1109 |> Enum.map(fn act -> act.data["type"] end)
1111 assert Enum.all?(user_activities, fn act -> act in ~w(Delete Undo) end)
1113 refute Activity.get_by_id(activity.id)
1114 refute Activity.get_by_id(like.id)
1115 refute Activity.get_by_id(like_two.id)
1116 refute Activity.get_by_id(repeat.id)
1119 test_with_mock "it sends out User Delete activity",
1121 Pleroma.Web.ActivityPub.Publisher,
1124 Pleroma.Config.put([:instance, :federating], true)
1126 {:ok, follower} = User.get_or_fetch_by_ap_id("http://mastodon.example.org/users/admin")
1127 {:ok, _} = User.follow(follower, user)
1129 {:ok, job} = User.delete(user)
1130 {:ok, _user} = ObanHelpers.perform(job)
1132 assert ObanHelpers.member?(
1134 "op" => "publish_one",
1136 "inbox" => "http://mastodon.example.org/inbox",
1137 "id" => "pleroma:fakeid"
1140 all_enqueued(worker: Pleroma.Workers.PublisherWorker)
1145 test "get_public_key_for_ap_id fetches a user that's not in the db" do
1146 assert {:ok, _key} = User.get_public_key_for_ap_id("http://mastodon.example.org/users/admin")
1149 describe "insert or update a user from given data" do
1150 test "with normal data" do
1151 user = insert(:user, %{nickname: "nick@name.de"})
1152 data = %{ap_id: user.ap_id <> "xxx", name: user.name, nickname: user.nickname}
1154 assert {:ok, %User{}} = User.insert_or_update_user(data)
1157 test "with overly long fields" do
1158 current_max_length = Pleroma.Config.get([:instance, :account_field_value_length], 255)
1159 user = insert(:user, nickname: "nickname@supergood.domain")
1164 nickname: user.nickname,
1166 %{"name" => "myfield", "value" => String.duplicate("h", current_max_length + 1)}
1170 assert {:ok, %User{}} = User.insert_or_update_user(data)
1173 test "with an overly long bio" do
1174 current_max_length = Pleroma.Config.get([:instance, :user_bio_length], 5000)
1175 user = insert(:user, nickname: "nickname@supergood.domain")
1180 nickname: user.nickname,
1181 bio: String.duplicate("h", current_max_length + 1)
1184 assert {:ok, %User{}} = User.insert_or_update_user(data)
1187 test "with an overly long display name" do
1188 current_max_length = Pleroma.Config.get([:instance, :user_name_length], 100)
1189 user = insert(:user, nickname: "nickname@supergood.domain")
1193 name: String.duplicate("h", current_max_length + 1),
1194 nickname: user.nickname
1197 assert {:ok, %User{}} = User.insert_or_update_user(data)
1201 describe "per-user rich-text filtering" do
1202 test "html_filter_policy returns default policies, when rich-text is enabled" do
1203 user = insert(:user)
1205 assert Pleroma.Config.get([:markup, :scrub_policy]) == User.html_filter_policy(user)
1208 test "html_filter_policy returns TwitterText scrubber when rich-text is disabled" do
1209 user = insert(:user, no_rich_text: true)
1211 assert Pleroma.HTML.Scrubber.TwitterText == User.html_filter_policy(user)
1215 describe "caching" do
1216 test "invalidate_cache works" do
1217 user = insert(:user)
1219 User.set_cache(user)
1220 User.invalidate_cache(user)
1222 {:ok, nil} = Cachex.get(:user_cache, "ap_id:#{user.ap_id}")
1223 {:ok, nil} = Cachex.get(:user_cache, "nickname:#{user.nickname}")
1226 test "User.delete() plugs any possible zombie objects" do
1227 user = insert(:user)
1229 {:ok, job} = User.delete(user)
1230 {:ok, _} = ObanHelpers.perform(job)
1232 {:ok, cached_user} = Cachex.get(:user_cache, "ap_id:#{user.ap_id}")
1234 assert cached_user != user
1236 {:ok, cached_user} = Cachex.get(:user_cache, "nickname:#{user.ap_id}")
1238 assert cached_user != user
1242 test "auth_active?/1 works correctly" do
1243 Pleroma.Config.put([:instance, :account_activation_required], true)
1245 local_user = insert(:user, local: true, confirmation_pending: true)
1246 confirmed_user = insert(:user, local: true, confirmation_pending: false)
1247 remote_user = insert(:user, local: false)
1249 refute User.auth_active?(local_user)
1250 assert User.auth_active?(confirmed_user)
1251 assert User.auth_active?(remote_user)
1253 # also shows unactive for deactivated users
1255 deactivated_but_confirmed =
1256 insert(:user, local: true, confirmation_pending: false, deactivated: true)
1258 refute User.auth_active?(deactivated_but_confirmed)
1261 describe "superuser?/1" do
1262 test "returns false for unprivileged users" do
1263 user = insert(:user, local: true)
1265 refute User.superuser?(user)
1268 test "returns false for remote users" do
1269 user = insert(:user, local: false)
1270 remote_admin_user = insert(:user, local: false, is_admin: true)
1272 refute User.superuser?(user)
1273 refute User.superuser?(remote_admin_user)
1276 test "returns true for local moderators" do
1277 user = insert(:user, local: true, is_moderator: true)
1279 assert User.superuser?(user)
1282 test "returns true for local admins" do
1283 user = insert(:user, local: true, is_admin: true)
1285 assert User.superuser?(user)
1289 describe "invisible?/1" do
1290 test "returns true for an invisible user" do
1291 user = insert(:user, local: true, invisible: true)
1293 assert User.invisible?(user)
1296 test "returns false for a non-invisible user" do
1297 user = insert(:user, local: true)
1299 refute User.invisible?(user)
1303 describe "visible_for?/2" do
1304 test "returns true when the account is itself" do
1305 user = insert(:user, local: true)
1307 assert User.visible_for?(user, user)
1310 test "returns false when the account is unauthenticated and auth is required" do
1311 Pleroma.Config.put([:instance, :account_activation_required], true)
1313 user = insert(:user, local: true, confirmation_pending: true)
1314 other_user = insert(:user, local: true)
1316 refute User.visible_for?(user, other_user)
1319 test "returns true when the account is unauthenticated and auth is not required" do
1320 user = insert(:user, local: true, confirmation_pending: true)
1321 other_user = insert(:user, local: true)
1323 assert User.visible_for?(user, other_user)
1326 test "returns true when the account is unauthenticated and being viewed by a privileged account (auth required)" do
1327 Pleroma.Config.put([:instance, :account_activation_required], true)
1329 user = insert(:user, local: true, confirmation_pending: true)
1330 other_user = insert(:user, local: true, is_admin: true)
1332 assert User.visible_for?(user, other_user)
1336 describe "parse_bio/2" do
1337 test "preserves hosts in user links text" do
1338 remote_user = insert(:user, local: false, nickname: "nick@domain.com")
1339 user = insert(:user)
1340 bio = "A.k.a. @nick@domain.com"
1343 ~s(A.k.a. <span class="h-card"><a data-user="#{remote_user.id}" class="u-url mention" href="#{
1345 }" rel="ugc">@<span>nick@domain.com</span></a></span>)
1347 assert expected_text == User.parse_bio(bio, user)
1350 test "Adds rel=me on linkbacked urls" do
1351 user = insert(:user, ap_id: "https://social.example.org/users/lain")
1353 bio = "http://example.com/rel_me/null"
1354 expected_text = "<a href=\"#{bio}\">#{bio}</a>"
1355 assert expected_text == User.parse_bio(bio, user)
1357 bio = "http://example.com/rel_me/link"
1358 expected_text = "<a href=\"#{bio}\" rel=\"me\">#{bio}</a>"
1359 assert expected_text == User.parse_bio(bio, user)
1361 bio = "http://example.com/rel_me/anchor"
1362 expected_text = "<a href=\"#{bio}\" rel=\"me\">#{bio}</a>"
1363 assert expected_text == User.parse_bio(bio, user)
1367 test "follower count is updated when a follower is blocked" do
1368 user = insert(:user)
1369 follower = insert(:user)
1370 follower2 = insert(:user)
1371 follower3 = insert(:user)
1373 {:ok, follower} = User.follow(follower, user)
1374 {:ok, _follower2} = User.follow(follower2, user)
1375 {:ok, _follower3} = User.follow(follower3, user)
1377 {:ok, _user_relationship} = User.block(user, follower)
1378 user = refresh_record(user)
1380 assert user.follower_count == 2
1383 describe "list_inactive_users_query/1" do
1384 defp days_ago(days) do
1386 NaiveDateTime.truncate(NaiveDateTime.utc_now(), :second),
1387 -days * 60 * 60 * 24,
1392 test "Users are inactive by default" do
1396 Enum.map(1..total, fn _ ->
1397 insert(:user, last_digest_emailed_at: days_ago(20), deactivated: false)
1400 inactive_users_ids =
1401 Pleroma.User.list_inactive_users_query()
1402 |> Pleroma.Repo.all()
1403 |> Enum.map(& &1.id)
1405 Enum.each(users, fn user ->
1406 assert user.id in inactive_users_ids
1410 test "Only includes users who has no recent activity" do
1414 Enum.map(1..total, fn _ ->
1415 insert(:user, last_digest_emailed_at: days_ago(20), deactivated: false)
1418 {inactive, active} = Enum.split(users, trunc(total / 2))
1420 Enum.map(active, fn user ->
1421 to = Enum.random(users -- [user])
1424 CommonAPI.post(user, %{
1425 "status" => "hey @#{to.nickname}"
1429 inactive_users_ids =
1430 Pleroma.User.list_inactive_users_query()
1431 |> Pleroma.Repo.all()
1432 |> Enum.map(& &1.id)
1434 Enum.each(active, fn user ->
1435 refute user.id in inactive_users_ids
1438 Enum.each(inactive, fn user ->
1439 assert user.id in inactive_users_ids
1443 test "Only includes users with no read notifications" do
1447 Enum.map(1..total, fn _ ->
1448 insert(:user, last_digest_emailed_at: days_ago(20), deactivated: false)
1451 [sender | recipients] = users
1452 {inactive, active} = Enum.split(recipients, trunc(total / 2))
1454 Enum.each(recipients, fn to ->
1456 CommonAPI.post(sender, %{
1457 "status" => "hey @#{to.nickname}"
1461 CommonAPI.post(sender, %{
1462 "status" => "hey again @#{to.nickname}"
1466 Enum.each(active, fn user ->
1467 [n1, _n2] = Pleroma.Notification.for_user(user)
1468 {:ok, _} = Pleroma.Notification.read_one(user, n1.id)
1471 inactive_users_ids =
1472 Pleroma.User.list_inactive_users_query()
1473 |> Pleroma.Repo.all()
1474 |> Enum.map(& &1.id)
1476 Enum.each(active, fn user ->
1477 refute user.id in inactive_users_ids
1480 Enum.each(inactive, fn user ->
1481 assert user.id in inactive_users_ids
1486 describe "toggle_confirmation/1" do
1487 test "if user is confirmed" do
1488 user = insert(:user, confirmation_pending: false)
1489 {:ok, user} = User.toggle_confirmation(user)
1491 assert user.confirmation_pending
1492 assert user.confirmation_token
1495 test "if user is unconfirmed" do
1496 user = insert(:user, confirmation_pending: true, confirmation_token: "some token")
1497 {:ok, user} = User.toggle_confirmation(user)
1499 refute user.confirmation_pending
1500 refute user.confirmation_token
1504 describe "ensure_keys_present" do
1505 test "it creates keys for a user and stores them in info" do
1506 user = insert(:user)
1507 refute is_binary(user.keys)
1508 {:ok, user} = User.ensure_keys_present(user)
1509 assert is_binary(user.keys)
1512 test "it doesn't create keys if there already are some" do
1513 user = insert(:user, keys: "xxx")
1514 {:ok, user} = User.ensure_keys_present(user)
1515 assert user.keys == "xxx"
1519 describe "get_ap_ids_by_nicknames" do
1520 test "it returns a list of AP ids for a given set of nicknames" do
1521 user = insert(:user)
1522 user_two = insert(:user)
1524 ap_ids = User.get_ap_ids_by_nicknames([user.nickname, user_two.nickname, "nonexistent"])
1525 assert length(ap_ids) == 2
1526 assert user.ap_id in ap_ids
1527 assert user_two.ap_id in ap_ids
1531 describe "sync followers count" do
1533 user1 = insert(:user, local: false, ap_id: "http://localhost:4001/users/masto_closed")
1534 user2 = insert(:user, local: false, ap_id: "http://localhost:4001/users/fuser2")
1535 insert(:user, local: true)
1536 insert(:user, local: false, deactivated: true)
1537 {:ok, user1: user1, user2: user2}
1540 test "external_users/1 external active users with limit", %{user1: user1, user2: user2} do
1541 [fdb_user1] = User.external_users(limit: 1)
1543 assert fdb_user1.ap_id
1544 assert fdb_user1.ap_id == user1.ap_id
1545 assert fdb_user1.id == user1.id
1547 [fdb_user2] = User.external_users(max_id: fdb_user1.id, limit: 1)
1549 assert fdb_user2.ap_id
1550 assert fdb_user2.ap_id == user2.ap_id
1551 assert fdb_user2.id == user2.id
1553 assert User.external_users(max_id: fdb_user2.id, limit: 1) == []
1557 describe "is_internal_user?/1" do
1558 test "non-internal user returns false" do
1559 user = insert(:user)
1560 refute User.is_internal_user?(user)
1563 test "user with no nickname returns true" do
1564 user = insert(:user, %{nickname: nil})
1565 assert User.is_internal_user?(user)
1568 test "user with internal-prefixed nickname returns true" do
1569 user = insert(:user, %{nickname: "internal.test"})
1570 assert User.is_internal_user?(user)
1574 describe "update_and_set_cache/1" do
1575 test "returns error when user is stale instead Ecto.StaleEntryError" do
1576 user = insert(:user)
1578 changeset = Ecto.Changeset.change(user, bio: "test")
1582 assert {:error, %Ecto.Changeset{errors: [id: {"is stale", [stale: true]}], valid?: false}} =
1583 User.update_and_set_cache(changeset)
1586 test "performs update cache if user updated" do
1587 user = insert(:user)
1588 assert {:ok, nil} = Cachex.get(:user_cache, "ap_id:#{user.ap_id}")
1590 changeset = Ecto.Changeset.change(user, bio: "test-bio")
1592 assert {:ok, %User{bio: "test-bio"} = user} = User.update_and_set_cache(changeset)
1593 assert {:ok, user} = Cachex.get(:user_cache, "ap_id:#{user.ap_id}")
1594 assert %User{bio: "test-bio"} = User.get_cached_by_ap_id(user.ap_id)
1598 describe "following/followers synchronization" do
1599 clear_config([:instance, :external_user_synchronization])
1601 test "updates the counters normally on following/getting a follow when disabled" do
1602 Pleroma.Config.put([:instance, :external_user_synchronization], false)
1603 user = insert(:user)
1608 follower_address: "http://localhost:4001/users/masto_closed/followers",
1609 following_address: "http://localhost:4001/users/masto_closed/following",
1613 assert other_user.following_count == 0
1614 assert other_user.follower_count == 0
1616 {:ok, user} = Pleroma.User.follow(user, other_user)
1617 other_user = Pleroma.User.get_by_id(other_user.id)
1619 assert user.following_count == 1
1620 assert other_user.follower_count == 1
1623 test "syncronizes the counters with the remote instance for the followed when enabled" do
1624 Pleroma.Config.put([:instance, :external_user_synchronization], false)
1626 user = insert(:user)
1631 follower_address: "http://localhost:4001/users/masto_closed/followers",
1632 following_address: "http://localhost:4001/users/masto_closed/following",
1636 assert other_user.following_count == 0
1637 assert other_user.follower_count == 0
1639 Pleroma.Config.put([:instance, :external_user_synchronization], true)
1640 {:ok, _user} = User.follow(user, other_user)
1641 other_user = User.get_by_id(other_user.id)
1643 assert other_user.follower_count == 437
1646 test "syncronizes the counters with the remote instance for the follower when enabled" do
1647 Pleroma.Config.put([:instance, :external_user_synchronization], false)
1649 user = insert(:user)
1654 follower_address: "http://localhost:4001/users/masto_closed/followers",
1655 following_address: "http://localhost:4001/users/masto_closed/following",
1659 assert other_user.following_count == 0
1660 assert other_user.follower_count == 0
1662 Pleroma.Config.put([:instance, :external_user_synchronization], true)
1663 {:ok, other_user} = User.follow(other_user, user)
1665 assert other_user.following_count == 152
1669 describe "change_email/2" do
1671 [user: insert(:user)]
1674 test "blank email returns error", %{user: user} do
1675 assert {:error, %{errors: [email: {"can't be blank", _}]}} = User.change_email(user, "")
1676 assert {:error, %{errors: [email: {"can't be blank", _}]}} = User.change_email(user, nil)
1679 test "non unique email returns error", %{user: user} do
1680 %{email: email} = insert(:user)
1682 assert {:error, %{errors: [email: {"has already been taken", _}]}} =
1683 User.change_email(user, email)
1686 test "invalid email returns error", %{user: user} do
1687 assert {:error, %{errors: [email: {"has invalid format", _}]}} =
1688 User.change_email(user, "cofe")
1691 test "changes email", %{user: user} do
1692 assert {:ok, %User{email: "cofe@cofe.party"}} = User.change_email(user, "cofe@cofe.party")
1696 describe "get_cached_by_nickname_or_id" do
1698 limit_to_local_content = Pleroma.Config.get([:instance, :limit_to_local_content])
1699 local_user = insert(:user)
1700 remote_user = insert(:user, nickname: "nickname@example.com", local: false)
1703 Pleroma.Config.put([:instance, :limit_to_local_content], limit_to_local_content)
1706 [local_user: local_user, remote_user: remote_user]
1709 test "allows getting remote users by id no matter what :limit_to_local_content is set to", %{
1710 remote_user: remote_user
1712 Pleroma.Config.put([:instance, :limit_to_local_content], false)
1713 assert %User{} = User.get_cached_by_nickname_or_id(remote_user.id)
1715 Pleroma.Config.put([:instance, :limit_to_local_content], true)
1716 assert %User{} = User.get_cached_by_nickname_or_id(remote_user.id)
1718 Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
1719 assert %User{} = User.get_cached_by_nickname_or_id(remote_user.id)
1722 test "disallows getting remote users by nickname without authentication when :limit_to_local_content is set to :unauthenticated",
1723 %{remote_user: remote_user} do
1724 Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
1725 assert nil == User.get_cached_by_nickname_or_id(remote_user.nickname)
1728 test "allows getting remote users by nickname with authentication when :limit_to_local_content is set to :unauthenticated",
1729 %{remote_user: remote_user, local_user: local_user} do
1730 Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
1731 assert %User{} = User.get_cached_by_nickname_or_id(remote_user.nickname, for: local_user)
1734 test "disallows getting remote users by nickname when :limit_to_local_content is set to true",
1735 %{remote_user: remote_user} do
1736 Pleroma.Config.put([:instance, :limit_to_local_content], true)
1737 assert nil == User.get_cached_by_nickname_or_id(remote_user.nickname)
1740 test "allows getting local users by nickname no matter what :limit_to_local_content is set to",
1741 %{local_user: local_user} do
1742 Pleroma.Config.put([:instance, :limit_to_local_content], false)
1743 assert %User{} = User.get_cached_by_nickname_or_id(local_user.nickname)
1745 Pleroma.Config.put([:instance, :limit_to_local_content], true)
1746 assert %User{} = User.get_cached_by_nickname_or_id(local_user.nickname)
1748 Pleroma.Config.put([:instance, :limit_to_local_content], :unauthenticated)
1749 assert %User{} = User.get_cached_by_nickname_or_id(local_user.nickname)
1753 describe "update_email_notifications/2" do
1755 user = insert(:user, email_notifications: %{"digest" => true})
1760 test "Notifications are updated", %{user: user} do
1761 true = user.email_notifications["digest"]
1762 assert {:ok, result} = User.update_email_notifications(user, %{"digest" => false})
1763 assert result.email_notifications["digest"] == false