[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)
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
assert %{"error" => "Missing field: email."} = json_response_and_validate_schema(conn, 400)
end
- test "with proper permissions, valid password and blank email", %{
- conn: conn
- } do
+ test "with proper permissions, valid password and blank email, when instance requires user email",
+ %{
+ conn: conn
+ } 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)
+
conn =
conn
|> put_req_header("content-type", "multipart/form-data")
assert json_response_and_validate_schema(conn, 200) == %{"error" => "Email can't be blank."}
end
+ test "with proper permissions, valid password and blank email, when instance does not require user email",
+ %{
+ conn: conn
+ } 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)
+
+ conn =
+ conn
+ |> put_req_header("content-type", "multipart/form-data")
+ |> post("/api/pleroma/change_email", %{password: "test", email: ""})
+
+ assert json_response_and_validate_schema(conn, 200) == %{"status" => "success"}
+ end
+
test "with proper permissions, valid password and non unique email", %{
conn: conn
} do