X-Git-Url: https://git.squeep.com/?a=blobdiff_plain;ds=inline;f=test%2Fpleroma%2Fuser_test.exs;h=7c30f39add281430906c5ecc93e788fd8c5b302e;hb=2abf8c982e72a1b7c76879423954dbde2427bf9c;hp=c2ed2c2a3f2b4d47ed07713d72ddaed29beabf97;hpb=4ba0beb60ccdc301f455c32773a3144b9448b2fb;p=akkoma
diff --git a/test/pleroma/user_test.exs b/test/pleroma/user_test.exs
index c2ed2c2a3..7c30f39ad 100644
--- a/test/pleroma/user_test.exs
+++ b/test/pleroma/user_test.exs
@@ -1720,6 +1720,38 @@ defmodule Pleroma.UserTest do
assert user.banner == %{}
end
+ describe "set_suggestion" do
+ test "suggests a user" do
+ user = insert(:user, is_suggested: false)
+ refute user.is_suggested
+ {:ok, user} = User.set_suggestion(user, true)
+ assert user.is_suggested
+ end
+
+ test "suggests a list of users" do
+ unsuggested_users = [
+ insert(:user, is_suggested: false),
+ insert(:user, is_suggested: false),
+ insert(:user, is_suggested: false)
+ ]
+
+ {:ok, users} = User.set_suggestion(unsuggested_users, true)
+
+ assert Enum.count(users) == 3
+
+ Enum.each(users, fn user ->
+ assert user.is_suggested
+ end)
+ end
+
+ test "unsuggests a user" do
+ user = insert(:user, is_suggested: true)
+ assert user.is_suggested
+ {:ok, user} = User.set_suggestion(user, false)
+ refute user.is_suggested
+ end
+ end
+
test "get_public_key_for_ap_id fetches a user that's not in the db" do
assert {:ok, _key} = User.get_public_key_for_ap_id("http://mastodon.example.org/users/admin")
end
@@ -1888,9 +1920,7 @@ defmodule Pleroma.UserTest do
bio = "A.k.a. @nick@domain.com"
expected_text =
- ~s(A.k.a. @nick@domain.com)
+ ~s(A.k.a. @nick@domain.com)
assert expected_text == User.parse_bio(bio, user)
end
@@ -2199,11 +2229,40 @@ defmodule Pleroma.UserTest do
[user: insert(:user)]
end
- test "blank email returns error", %{user: user} do
+ test "blank email returns error if we require an email on registration", %{user: user} do
+ orig_account_activation_required =
+ Pleroma.Config.get([:instance, :account_activation_required])
+
+ Pleroma.Config.put([:instance, :account_activation_required], true)
+
+ on_exit(fn ->
+ Pleroma.Config.put(
+ [:instance, :account_activation_required],
+ orig_account_activation_required
+ )
+ end)
+
assert {:error, %{errors: [email: {"can't be blank", _}]}} = User.change_email(user, "")
assert {:error, %{errors: [email: {"can't be blank", _}]}} = User.change_email(user, nil)
end
+ test "blank email should be fine if we do not require an email on registration", %{user: user} do
+ orig_account_activation_required =
+ Pleroma.Config.get([:instance, :account_activation_required])
+
+ Pleroma.Config.put([:instance, :account_activation_required], false)
+
+ on_exit(fn ->
+ Pleroma.Config.put(
+ [:instance, :account_activation_required],
+ orig_account_activation_required
+ )
+ end)
+
+ assert {:ok, %User{email: nil}} = User.change_email(user, "")
+ assert {:ok, %User{email: nil}} = User.change_email(user, nil)
+ end
+
test "non unique email returns error", %{user: user} do
%{email: email} = insert(:user)
@@ -2219,6 +2278,25 @@ defmodule Pleroma.UserTest do
test "changes email", %{user: user} do
assert {:ok, %User{email: "cofe@cofe.party"}} = User.change_email(user, "cofe@cofe.party")
end
+
+ test "adds email", %{user: user} do
+ orig_account_activation_required =
+ Pleroma.Config.get([:instance, :account_activation_required])
+
+ Pleroma.Config.put([:instance, :account_activation_required], false)
+
+ on_exit(fn ->
+ Pleroma.Config.put(
+ [:instance, :account_activation_required],
+ orig_account_activation_required
+ )
+ end)
+
+ assert {:ok, _} = User.change_email(user, "")
+ Pleroma.Config.put([:instance, :account_activation_required], true)
+
+ assert {:ok, %User{email: "cofe2@cofe.party"}} = User.change_email(user, "cofe2@cofe.party")
+ end
end
describe "get_cached_by_nickname_or_id" do
@@ -2366,13 +2444,16 @@ defmodule Pleroma.UserTest do
test "active_user_count/1" do
insert(:user)
insert(:user, %{local: false})
- insert(:user, %{last_active_at: Timex.shift(NaiveDateTime.utc_now(), weeks: -5)})
- insert(:user, %{last_active_at: Timex.shift(NaiveDateTime.utc_now(), weeks: -3)})
insert(:user, %{last_active_at: NaiveDateTime.utc_now()})
+ insert(:user, %{last_active_at: Timex.shift(NaiveDateTime.utc_now(), days: -15)})
+ insert(:user, %{last_active_at: Timex.shift(NaiveDateTime.utc_now(), weeks: -6)})
+ insert(:user, %{last_active_at: Timex.shift(NaiveDateTime.utc_now(), months: -7)})
+ insert(:user, %{last_active_at: Timex.shift(NaiveDateTime.utc_now(), years: -2)})
assert User.active_user_count() == 2
- assert User.active_user_count(6) == 3
- assert User.active_user_count(1) == 1
+ assert User.active_user_count(180) == 3
+ assert User.active_user_count(365) == 4
+ assert User.active_user_count(1000) == 5
end
describe "pins" do