user: add is_internal_user? helper function

This commit is contained in:
Ariadne Conill 2019-07-17 17:12:42 +00:00
parent 0a6f6e1b5b
commit 62e5ff624e
2 changed files with 21 additions and 0 deletions

View file

@ -1410,4 +1410,8 @@ defp put_password_hash(
end
defp put_password_hash(changeset), do: changeset
def is_internal_user?(%User{nickname: nil}), do: true
def is_internal_user?(%User{local: true, nickname: "internal." <> _}), do: true
def is_internal_user?(_), do: false
end

View file

@ -1310,4 +1310,21 @@ test "without args", %{user: user} do
assert following == 0
end
end
describe "is_internal_user?/1" do
test "non-internal user returns false" do
user = insert(:user)
refute User.is_internal_user?(user)
end
test "user with no nickname returns true" do
user = insert(:user, %{nickname: nil})
assert User.is_internal_user?(user)
end
test "user with internal-prefixed nickname returns true" do
user = insert(:user, %{nickname: "internal.test"})
assert User.is_internal_user?(user)
end
end
end