Merge branch 'develop' into gun
This commit is contained in:
commit
b2eb1124d1
19 changed files with 197 additions and 50 deletions
|
|
@ -1880,10 +1880,10 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
"@#{admin.nickname} deleted status ##{id}"
|
||||
end
|
||||
|
||||
test "returns error when status is not exist", %{conn: conn} do
|
||||
test "returns 404 when the status does not exist", %{conn: conn} do
|
||||
conn = delete(conn, "/api/pleroma/admin/statuses/test")
|
||||
|
||||
assert json_response(conn, :bad_request) == "Could not delete"
|
||||
assert json_response(conn, :not_found) == "Not found"
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -85,6 +85,37 @@ defmodule Pleroma.Web.MastodonAPI.AuthControllerTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "POST /auth/password, with nickname" do
|
||||
test "it returns 204", %{conn: conn} do
|
||||
user = insert(:user)
|
||||
|
||||
assert conn
|
||||
|> post("/auth/password?nickname=#{user.nickname}")
|
||||
|> json_response(:no_content)
|
||||
|
||||
ObanHelpers.perform_all()
|
||||
token_record = Repo.get_by(Pleroma.PasswordResetToken, user_id: user.id)
|
||||
|
||||
email = Pleroma.Emails.UserEmail.password_reset_email(user, token_record.token)
|
||||
notify_email = Config.get([:instance, :notify_email])
|
||||
instance_name = Config.get([:instance, :name])
|
||||
|
||||
assert_email_sent(
|
||||
from: {instance_name, notify_email},
|
||||
to: {user.name, user.email},
|
||||
html_body: email.html_body
|
||||
)
|
||||
end
|
||||
|
||||
test "it doesn't fail when a user has no email", %{conn: conn} do
|
||||
user = insert(:user, %{email: nil})
|
||||
|
||||
assert conn
|
||||
|> post("/auth/password?nickname=#{user.nickname}")
|
||||
|> json_response(:no_content)
|
||||
end
|
||||
end
|
||||
|
||||
describe "POST /auth/password, with invalid parameters" do
|
||||
setup do
|
||||
user = insert(:user)
|
||||
|
|
|
|||
|
|
@ -75,4 +75,13 @@ defmodule Pleroma.Web.MastodonAPI.ReportControllerTest do
|
|||
|
||||
assert json_response(conn, 400) == %{"error" => "Account not found"}
|
||||
end
|
||||
|
||||
test "doesn't fail if an admin has no email", %{conn: conn, target_user: target_user} do
|
||||
insert(:user, %{is_admin: true, email: nil})
|
||||
|
||||
assert %{"action_taken" => false, "id" => _} =
|
||||
conn
|
||||
|> post("/api/v1/reports", %{"account_id" => target_user.id})
|
||||
|> json_response(200)
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -476,6 +476,15 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
assert id == to_string(activity.id)
|
||||
end
|
||||
|
||||
test "getting a status that doesn't exist returns 404" do
|
||||
%{conn: conn} = oauth_access(["read:statuses"])
|
||||
activity = insert(:note_activity)
|
||||
|
||||
conn = get(conn, "/api/v1/statuses/#{String.downcase(activity.id)}")
|
||||
|
||||
assert json_response(conn, 404) == %{"error" => "Record not found"}
|
||||
end
|
||||
|
||||
test "get a direct status" do
|
||||
%{user: user, conn: conn} = oauth_access(["read:statuses"])
|
||||
other_user = insert(:user)
|
||||
|
|
@ -520,6 +529,18 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
refute Activity.get_by_id(activity.id)
|
||||
end
|
||||
|
||||
test "when it doesn't exist" do
|
||||
%{user: author, conn: conn} = oauth_access(["write:statuses"])
|
||||
activity = insert(:note_activity, user: author)
|
||||
|
||||
conn =
|
||||
conn
|
||||
|> assign(:user, author)
|
||||
|> delete("/api/v1/statuses/#{String.downcase(activity.id)}")
|
||||
|
||||
assert %{"error" => "Record not found"} == json_response(conn, 404)
|
||||
end
|
||||
|
||||
test "when you didn't create it" do
|
||||
%{conn: conn} = oauth_access(["write:statuses"])
|
||||
activity = insert(:note_activity)
|
||||
|
|
@ -574,6 +595,14 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
assert to_string(activity.id) == id
|
||||
end
|
||||
|
||||
test "returns 404 if the reblogged status doesn't exist", %{conn: conn} do
|
||||
activity = insert(:note_activity)
|
||||
|
||||
conn = post(conn, "/api/v1/statuses/#{String.downcase(activity.id)}/reblog")
|
||||
|
||||
assert %{"error" => "Record not found"} = json_response(conn, 404)
|
||||
end
|
||||
|
||||
test "reblogs privately and returns the reblogged status", %{conn: conn} do
|
||||
activity = insert(:note_activity)
|
||||
|
||||
|
|
@ -626,12 +655,6 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
|
||||
assert to_string(activity.id) == id
|
||||
end
|
||||
|
||||
test "returns 400 error when activity is not exist", %{conn: conn} do
|
||||
conn = post(conn, "/api/v1/statuses/foo/reblog")
|
||||
|
||||
assert json_response(conn, 400) == %{"error" => "Could not repeat"}
|
||||
end
|
||||
end
|
||||
|
||||
describe "unreblogging" do
|
||||
|
|
@ -649,10 +672,10 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
assert to_string(activity.id) == id
|
||||
end
|
||||
|
||||
test "returns 400 error when activity is not exist", %{conn: conn} do
|
||||
test "returns 404 error when activity does not exist", %{conn: conn} do
|
||||
conn = post(conn, "/api/v1/statuses/foo/unreblog")
|
||||
|
||||
assert json_response(conn, 400) == %{"error" => "Could not unrepeat"}
|
||||
assert json_response(conn, 404) == %{"error" => "Record not found"}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -677,10 +700,10 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
assert post(conn, "/api/v1/statuses/#{activity.id}/favourite") |> json_response(200)
|
||||
end
|
||||
|
||||
test "returns 400 error for a wrong id", %{conn: conn} do
|
||||
test "returns 404 error for a wrong id", %{conn: conn} do
|
||||
conn = post(conn, "/api/v1/statuses/1/favourite")
|
||||
|
||||
assert json_response(conn, 400) == %{"error" => "Could not favorite"}
|
||||
assert json_response(conn, 404) == %{"error" => "Record not found"}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -700,10 +723,10 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
assert to_string(activity.id) == id
|
||||
end
|
||||
|
||||
test "returns 400 error for a wrong id", %{conn: conn} do
|
||||
test "returns 404 error for a wrong id", %{conn: conn} do
|
||||
conn = post(conn, "/api/v1/statuses/1/unfavourite")
|
||||
|
||||
assert json_response(conn, 400) == %{"error" => "Could not unfavorite"}
|
||||
assert json_response(conn, 404) == %{"error" => "Record not found"}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ defmodule Pleroma.Workers.Cron.DigestEmailsWorkerTest do
|
|||
|
||||
clear_config([:email_notifications, :digest])
|
||||
|
||||
test "it sends digest emails" do
|
||||
setup do
|
||||
Pleroma.Config.put([:email_notifications, :digest], %{
|
||||
active: true,
|
||||
inactivity_threshold: 7,
|
||||
|
|
@ -31,6 +31,10 @@ defmodule Pleroma.Workers.Cron.DigestEmailsWorkerTest do
|
|||
{:ok, _} = User.switch_email_notifications(user2, "digest", true)
|
||||
CommonAPI.post(user, %{"status" => "hey @#{user2.nickname}!"})
|
||||
|
||||
{:ok, user2: user2}
|
||||
end
|
||||
|
||||
test "it sends digest emails", %{user2: user2} do
|
||||
Pleroma.Workers.Cron.DigestEmailsWorker.perform(:opts, :pid)
|
||||
# Performing job(s) enqueued at previous step
|
||||
ObanHelpers.perform_all()
|
||||
|
|
@ -39,4 +43,12 @@ defmodule Pleroma.Workers.Cron.DigestEmailsWorkerTest do
|
|||
assert email.to == [{user2.name, user2.email}]
|
||||
assert email.subject == "Your digest from #{Pleroma.Config.get(:instance)[:name]}"
|
||||
end
|
||||
|
||||
test "it doesn't fail when a user has no email", %{user2: user2} do
|
||||
{:ok, _} = user2 |> Ecto.Changeset.change(%{email: nil}) |> Pleroma.Repo.update()
|
||||
|
||||
Pleroma.Workers.Cron.DigestEmailsWorker.perform(:opts, :pid)
|
||||
# Performing job(s) enqueued at previous step
|
||||
ObanHelpers.perform_all()
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -29,4 +29,16 @@ defmodule Pleroma.Workers.Cron.NewUsersDigestWorkerTest do
|
|||
assert email.html_body =~ user2.nickname
|
||||
assert email.html_body =~ "cofe"
|
||||
end
|
||||
|
||||
test "it doesn't fail when admin has no email" do
|
||||
yesterday = NaiveDateTime.utc_now() |> Timex.shift(days: -1)
|
||||
insert(:user, %{is_admin: true, email: nil})
|
||||
insert(:user, %{inserted_at: yesterday})
|
||||
user = insert(:user, %{inserted_at: yesterday})
|
||||
|
||||
CommonAPI.post(user, %{"status" => "cofe"})
|
||||
|
||||
NewUsersDigestWorker.perform(nil, nil)
|
||||
ObanHelpers.perform_all()
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue