Merge branch 'develop' into feature/admin-api-status-count-per-instance
This commit is contained in:
commit
01bd6a1e54
83 changed files with 2550 additions and 679 deletions
|
|
@ -951,7 +951,7 @@ defmodule Pleroma.Web.ActivityPub.ActivityPubTest do
|
|||
|
||||
test "works with base64 encoded images" do
|
||||
file = %{
|
||||
"img" => data_uri()
|
||||
img: data_uri()
|
||||
}
|
||||
|
||||
{:ok, %Object{}} = ActivityPub.upload(file)
|
||||
|
|
|
|||
|
|
@ -2509,6 +2509,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
%{"tuple" => [":seconds_valid", 60]},
|
||||
%{"tuple" => [":path", ""]},
|
||||
%{"tuple" => [":key1", nil]},
|
||||
%{"tuple" => [":partial_chain", "&:hackney_connect.partial_chain/1"]},
|
||||
%{"tuple" => [":regex1", "~r/https:\/\/example.com/"]},
|
||||
%{"tuple" => [":regex2", "~r/https:\/\/example.com/u"]},
|
||||
%{"tuple" => [":regex3", "~r/https:\/\/example.com/i"]},
|
||||
|
|
@ -2532,6 +2533,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
%{"tuple" => [":seconds_valid", 60]},
|
||||
%{"tuple" => [":path", ""]},
|
||||
%{"tuple" => [":key1", nil]},
|
||||
%{"tuple" => [":partial_chain", "&:hackney_connect.partial_chain/1"]},
|
||||
%{"tuple" => [":regex1", "~r/https:\\/\\/example.com/"]},
|
||||
%{"tuple" => [":regex2", "~r/https:\\/\\/example.com/u"]},
|
||||
%{"tuple" => [":regex3", "~r/https:\\/\\/example.com/i"]},
|
||||
|
|
@ -2544,6 +2546,7 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
":seconds_valid",
|
||||
":path",
|
||||
":key1",
|
||||
":partial_chain",
|
||||
":regex1",
|
||||
":regex2",
|
||||
":regex3",
|
||||
|
|
@ -2940,6 +2943,33 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
assert %{"tuple" => [":proxy_url", %{"tuple" => [":socks5", "127.0.0.1", 1234]}]} in value
|
||||
assert ":proxy_url" in db
|
||||
end
|
||||
|
||||
test "doesn't set keys not in the whitelist", %{conn: conn} do
|
||||
clear_config(:database_config_whitelist, [
|
||||
{:pleroma, :key1},
|
||||
{:pleroma, :key2},
|
||||
{:pleroma, Pleroma.Captcha.NotReal},
|
||||
{:not_real}
|
||||
])
|
||||
|
||||
post(conn, "/api/pleroma/admin/config", %{
|
||||
configs: [
|
||||
%{group: ":pleroma", key: ":key1", value: "value1"},
|
||||
%{group: ":pleroma", key: ":key2", value: "value2"},
|
||||
%{group: ":pleroma", key: ":key3", value: "value3"},
|
||||
%{group: ":pleroma", key: "Pleroma.Web.Endpoint.NotReal", value: "value4"},
|
||||
%{group: ":pleroma", key: "Pleroma.Captcha.NotReal", value: "value5"},
|
||||
%{group: ":not_real", key: ":anything", value: "value6"}
|
||||
]
|
||||
})
|
||||
|
||||
assert Application.get_env(:pleroma, :key1) == "value1"
|
||||
assert Application.get_env(:pleroma, :key2) == "value2"
|
||||
assert Application.get_env(:pleroma, :key3) == nil
|
||||
assert Application.get_env(:pleroma, Pleroma.Web.Endpoint.NotReal) == nil
|
||||
assert Application.get_env(:pleroma, Pleroma.Captcha.NotReal) == "value5"
|
||||
assert Application.get_env(:not_real, :anything) == "value6"
|
||||
end
|
||||
end
|
||||
|
||||
describe "GET /api/pleroma/admin/restart" do
|
||||
|
|
@ -3571,19 +3601,54 @@ defmodule Pleroma.Web.AdminAPI.AdminAPIControllerTest do
|
|||
end
|
||||
end
|
||||
|
||||
test "GET /api/pleroma/admin/config/descriptions", %{conn: conn} do
|
||||
admin = insert(:user, is_admin: true)
|
||||
describe "GET /api/pleroma/admin/config/descriptions" do
|
||||
test "structure", %{conn: conn} do
|
||||
admin = insert(:user, is_admin: true)
|
||||
|
||||
conn =
|
||||
assign(conn, :user, admin)
|
||||
|> get("/api/pleroma/admin/config/descriptions")
|
||||
conn =
|
||||
assign(conn, :user, admin)
|
||||
|> get("/api/pleroma/admin/config/descriptions")
|
||||
|
||||
assert [child | _others] = json_response(conn, 200)
|
||||
assert [child | _others] = json_response(conn, 200)
|
||||
|
||||
assert child["children"]
|
||||
assert child["key"]
|
||||
assert String.starts_with?(child["group"], ":")
|
||||
assert child["description"]
|
||||
assert child["children"]
|
||||
assert child["key"]
|
||||
assert String.starts_with?(child["group"], ":")
|
||||
assert child["description"]
|
||||
end
|
||||
|
||||
test "filters by database configuration whitelist", %{conn: conn} do
|
||||
clear_config(:database_config_whitelist, [
|
||||
{:pleroma, :instance},
|
||||
{:pleroma, :activitypub},
|
||||
{:pleroma, Pleroma.Upload},
|
||||
{:esshd}
|
||||
])
|
||||
|
||||
admin = insert(:user, is_admin: true)
|
||||
|
||||
conn =
|
||||
assign(conn, :user, admin)
|
||||
|> get("/api/pleroma/admin/config/descriptions")
|
||||
|
||||
children = json_response(conn, 200)
|
||||
|
||||
assert length(children) == 4
|
||||
|
||||
assert Enum.count(children, fn c -> c["group"] == ":pleroma" end) == 3
|
||||
|
||||
instance = Enum.find(children, fn c -> c["key"] == ":instance" end)
|
||||
assert instance["children"]
|
||||
|
||||
activitypub = Enum.find(children, fn c -> c["key"] == ":activitypub" end)
|
||||
assert activitypub["children"]
|
||||
|
||||
web_endpoint = Enum.find(children, fn c -> c["key"] == "Pleroma.Upload" end)
|
||||
assert web_endpoint["children"]
|
||||
|
||||
esshd = Enum.find(children, fn c -> c["group"] == ":esshd" end)
|
||||
assert esshd["children"]
|
||||
end
|
||||
end
|
||||
|
||||
describe "/api/pleroma/admin/stats" do
|
||||
|
|
|
|||
|
|
@ -15,11 +15,16 @@ defmodule Pleroma.Web.Auth.PleromaAuthenticatorTest do
|
|||
{:ok, [user: user, name: name, password: password]}
|
||||
end
|
||||
|
||||
test "get_user/authorization", %{user: user, name: name, password: password} do
|
||||
test "get_user/authorization", %{name: name, password: password} do
|
||||
name = name <> "1"
|
||||
user = insert(:user, nickname: name, password_hash: Bcrypt.hash_pwd_salt(password))
|
||||
|
||||
params = %{"authorization" => %{"name" => name, "password" => password}}
|
||||
res = PleromaAuthenticator.get_user(%Plug.Conn{params: params})
|
||||
|
||||
assert {:ok, user} == res
|
||||
assert {:ok, returned_user} = res
|
||||
assert returned_user.id == user.id
|
||||
assert "$pbkdf2" <> _ = returned_user.password_hash
|
||||
end
|
||||
|
||||
test "get_user/authorization with invalid password", %{name: name} do
|
||||
|
|
|
|||
|
|
@ -23,6 +23,18 @@ defmodule Pleroma.Web.CommonAPITest do
|
|||
setup do: clear_config([:instance, :limit])
|
||||
setup do: clear_config([:instance, :max_pinned_statuses])
|
||||
|
||||
describe "unblocking" do
|
||||
test "it works even without an existing block activity" do
|
||||
blocked = insert(:user)
|
||||
blocker = insert(:user)
|
||||
User.block(blocker, blocked)
|
||||
|
||||
assert User.blocks?(blocker, blocked)
|
||||
assert {:ok, :no_activity} == CommonAPI.unblock(blocker, blocked)
|
||||
refute User.blocks?(blocker, blocked)
|
||||
end
|
||||
end
|
||||
|
||||
describe "deletion" do
|
||||
test "it works with pruned objects" do
|
||||
user = insert(:user)
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ defmodule Pleroma.Web.MastodonAPI.MediaControllerTest do
|
|||
|
||||
setup do: oauth_access(["write:media"])
|
||||
|
||||
describe "media upload" do
|
||||
describe "Upload media" do
|
||||
setup do
|
||||
image = %Plug.Upload{
|
||||
content_type: "image/jpg",
|
||||
|
|
@ -25,13 +25,14 @@ defmodule Pleroma.Web.MastodonAPI.MediaControllerTest do
|
|||
setup do: clear_config([:media_proxy])
|
||||
setup do: clear_config([Pleroma.Upload])
|
||||
|
||||
test "returns uploaded image", %{conn: conn, image: image} do
|
||||
test "/api/v1/media", %{conn: conn, image: image} do
|
||||
desc = "Description of the image"
|
||||
|
||||
media =
|
||||
conn
|
||||
|> put_req_header("content-type", "multipart/form-data")
|
||||
|> post("/api/v1/media", %{"file" => image, "description" => desc})
|
||||
|> json_response(:ok)
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
assert media["type"] == "image"
|
||||
assert media["description"] == desc
|
||||
|
|
@ -40,9 +41,32 @@ defmodule Pleroma.Web.MastodonAPI.MediaControllerTest do
|
|||
object = Object.get_by_id(media["id"])
|
||||
assert object.data["actor"] == User.ap_id(conn.assigns[:user])
|
||||
end
|
||||
|
||||
test "/api/v2/media", %{conn: conn, image: image} do
|
||||
desc = "Description of the image"
|
||||
|
||||
response =
|
||||
conn
|
||||
|> put_req_header("content-type", "multipart/form-data")
|
||||
|> post("/api/v2/media", %{"file" => image, "description" => desc})
|
||||
|> json_response_and_validate_schema(202)
|
||||
|
||||
assert media_id = response["id"]
|
||||
|
||||
media =
|
||||
conn
|
||||
|> get("/api/v1/media/#{media_id}")
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert media["type"] == "image"
|
||||
assert media["description"] == desc
|
||||
assert media["id"]
|
||||
object = Object.get_by_id(media["id"])
|
||||
assert object.data["actor"] == User.ap_id(conn.assigns[:user])
|
||||
end
|
||||
end
|
||||
|
||||
describe "PUT /api/v1/media/:id" do
|
||||
describe "Update media description" do
|
||||
setup %{user: actor} do
|
||||
file = %Plug.Upload{
|
||||
content_type: "image/jpg",
|
||||
|
|
@ -60,23 +84,45 @@ defmodule Pleroma.Web.MastodonAPI.MediaControllerTest do
|
|||
[object: object]
|
||||
end
|
||||
|
||||
test "updates name of media", %{conn: conn, object: object} do
|
||||
test "/api/v1/media/:id good request", %{conn: conn, object: object} do
|
||||
media =
|
||||
conn
|
||||
|> put_req_header("content-type", "multipart/form-data")
|
||||
|> put("/api/v1/media/#{object.id}", %{"description" => "test-media"})
|
||||
|> json_response(:ok)
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
assert media["description"] == "test-media"
|
||||
assert refresh_record(object).data["name"] == "test-media"
|
||||
end
|
||||
end
|
||||
|
||||
test "returns error when request is bad", %{conn: conn, object: object} do
|
||||
describe "Get media by id" do
|
||||
setup %{user: actor} do
|
||||
file = %Plug.Upload{
|
||||
content_type: "image/jpg",
|
||||
path: Path.absname("test/fixtures/image.jpg"),
|
||||
filename: "an_image.jpg"
|
||||
}
|
||||
|
||||
{:ok, %Object{} = object} =
|
||||
ActivityPub.upload(
|
||||
file,
|
||||
actor: User.ap_id(actor),
|
||||
description: "test-media"
|
||||
)
|
||||
|
||||
[object: object]
|
||||
end
|
||||
|
||||
test "/api/v1/media/:id", %{conn: conn, object: object} do
|
||||
media =
|
||||
conn
|
||||
|> put("/api/v1/media/#{object.id}", %{})
|
||||
|> json_response(400)
|
||||
|> get("/api/v1/media/#{object.id}")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
assert media == %{"error" => "bad_request"}
|
||||
assert media["description"] == "test-media"
|
||||
assert media["type"] == "image"
|
||||
assert media["id"]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
|
|
@ -12,9 +12,7 @@ defmodule Pleroma.Web.MastodonAPI.NotificationControllerTest do
|
|||
|
||||
import Pleroma.Factory
|
||||
|
||||
test "does NOT render account/pleroma/relationship if this is disabled by default" do
|
||||
clear_config([:extensions, :output_relationships_in_statuses_by_default], false)
|
||||
|
||||
test "does NOT render account/pleroma/relationship by default" do
|
||||
%{user: user, conn: conn} = oauth_access(["read:notifications"])
|
||||
other_user = insert(:user)
|
||||
|
||||
|
|
|
|||
|
|
@ -1176,7 +1176,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusControllerTest do
|
|||
end
|
||||
|
||||
test "bookmarks" do
|
||||
bookmarks_uri = "/api/v1/bookmarks?with_relationships=true"
|
||||
bookmarks_uri = "/api/v1/bookmarks"
|
||||
|
||||
%{conn: conn} = oauth_access(["write:bookmarks", "read:bookmarks"])
|
||||
author = insert(:user)
|
||||
|
|
|
|||
|
|
@ -20,12 +20,10 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
|
|||
describe "home" do
|
||||
setup do: oauth_access(["read:statuses"])
|
||||
|
||||
test "does NOT render account/pleroma/relationship if this is disabled by default", %{
|
||||
test "does NOT embed account/pleroma/relationship in statuses", %{
|
||||
user: user,
|
||||
conn: conn
|
||||
} do
|
||||
clear_config([:extensions, :output_relationships_in_statuses_by_default], false)
|
||||
|
||||
other_user = insert(:user)
|
||||
|
||||
{:ok, _} = CommonAPI.post(other_user, %{status: "hi @#{user.nickname}"})
|
||||
|
|
@ -41,72 +39,6 @@ defmodule Pleroma.Web.MastodonAPI.TimelineControllerTest do
|
|||
end)
|
||||
end
|
||||
|
||||
test "the home timeline", %{user: user, conn: conn} do
|
||||
uri = "/api/v1/timelines/home?with_relationships=1"
|
||||
|
||||
following = insert(:user, nickname: "followed")
|
||||
third_user = insert(:user, nickname: "repeated")
|
||||
|
||||
{:ok, _activity} = CommonAPI.post(following, %{status: "post"})
|
||||
{:ok, activity} = CommonAPI.post(third_user, %{status: "repeated post"})
|
||||
{:ok, _, _} = CommonAPI.repeat(activity.id, following)
|
||||
|
||||
ret_conn = get(conn, uri)
|
||||
|
||||
assert Enum.empty?(json_response_and_validate_schema(ret_conn, :ok))
|
||||
|
||||
{:ok, _user} = User.follow(user, following)
|
||||
|
||||
ret_conn = get(conn, uri)
|
||||
|
||||
assert [
|
||||
%{
|
||||
"reblog" => %{
|
||||
"content" => "repeated post",
|
||||
"account" => %{
|
||||
"pleroma" => %{
|
||||
"relationship" => %{"following" => false, "followed_by" => false}
|
||||
}
|
||||
}
|
||||
},
|
||||
"account" => %{"pleroma" => %{"relationship" => %{"following" => true}}}
|
||||
},
|
||||
%{
|
||||
"content" => "post",
|
||||
"account" => %{
|
||||
"acct" => "followed",
|
||||
"pleroma" => %{"relationship" => %{"following" => true}}
|
||||
}
|
||||
}
|
||||
] = json_response_and_validate_schema(ret_conn, :ok)
|
||||
|
||||
{:ok, _user} = User.follow(third_user, user)
|
||||
|
||||
ret_conn = get(conn, uri)
|
||||
|
||||
assert [
|
||||
%{
|
||||
"reblog" => %{
|
||||
"content" => "repeated post",
|
||||
"account" => %{
|
||||
"acct" => "repeated",
|
||||
"pleroma" => %{
|
||||
"relationship" => %{"following" => false, "followed_by" => true}
|
||||
}
|
||||
}
|
||||
},
|
||||
"account" => %{"pleroma" => %{"relationship" => %{"following" => true}}}
|
||||
},
|
||||
%{
|
||||
"content" => "post",
|
||||
"account" => %{
|
||||
"acct" => "followed",
|
||||
"pleroma" => %{"relationship" => %{"following" => true}}
|
||||
}
|
||||
}
|
||||
] = json_response_and_validate_schema(ret_conn, :ok)
|
||||
end
|
||||
|
||||
test "the home timeline when the direct messages are excluded", %{user: user, conn: conn} do
|
||||
{:ok, public_activity} = CommonAPI.post(user, %{status: ".", visibility: "public"})
|
||||
{:ok, direct_activity} = CommonAPI.post(user, %{status: ".", visibility: "direct"})
|
||||
|
|
|
|||
|
|
@ -302,82 +302,6 @@ defmodule Pleroma.Web.MastodonAPI.AccountViewTest do
|
|||
end
|
||||
end
|
||||
|
||||
test "represent an embedded relationship" do
|
||||
user =
|
||||
insert(:user, %{
|
||||
follower_count: 0,
|
||||
note_count: 5,
|
||||
actor_type: "Service",
|
||||
nickname: "shp@shitposter.club",
|
||||
inserted_at: ~N[2017-08-15 15:47:06.597036]
|
||||
})
|
||||
|
||||
other_user = insert(:user)
|
||||
{:ok, other_user} = User.follow(other_user, user)
|
||||
{:ok, _user_relationship} = User.block(other_user, user)
|
||||
{:ok, _} = User.follow(insert(:user), user)
|
||||
|
||||
expected = %{
|
||||
id: to_string(user.id),
|
||||
username: "shp",
|
||||
acct: user.nickname,
|
||||
display_name: user.name,
|
||||
locked: false,
|
||||
created_at: "2017-08-15T15:47:06.000Z",
|
||||
followers_count: 1,
|
||||
following_count: 0,
|
||||
statuses_count: 5,
|
||||
note: user.bio,
|
||||
url: user.ap_id,
|
||||
avatar: "http://localhost:4001/images/avi.png",
|
||||
avatar_static: "http://localhost:4001/images/avi.png",
|
||||
header: "http://localhost:4001/images/banner.png",
|
||||
header_static: "http://localhost:4001/images/banner.png",
|
||||
emojis: [],
|
||||
fields: [],
|
||||
bot: true,
|
||||
source: %{
|
||||
note: user.bio,
|
||||
sensitive: false,
|
||||
pleroma: %{
|
||||
actor_type: "Service",
|
||||
discoverable: false
|
||||
},
|
||||
fields: []
|
||||
},
|
||||
pleroma: %{
|
||||
background_image: nil,
|
||||
confirmation_pending: false,
|
||||
tags: [],
|
||||
is_admin: false,
|
||||
is_moderator: false,
|
||||
hide_favorites: true,
|
||||
hide_followers: false,
|
||||
hide_follows: false,
|
||||
hide_followers_count: false,
|
||||
hide_follows_count: false,
|
||||
relationship: %{
|
||||
id: to_string(user.id),
|
||||
following: false,
|
||||
followed_by: false,
|
||||
blocking: true,
|
||||
blocked_by: false,
|
||||
subscribing: false,
|
||||
muting: false,
|
||||
muting_notifications: false,
|
||||
requested: false,
|
||||
domain_blocking: false,
|
||||
showing_reblogs: true,
|
||||
endorsed: false
|
||||
},
|
||||
skip_thread_containment: false
|
||||
}
|
||||
}
|
||||
|
||||
assert expected ==
|
||||
AccountView.render("show.json", %{user: refresh_record(user), for: other_user})
|
||||
end
|
||||
|
||||
test "returns the settings store if the requesting user is the represented user and it's requested specifically" do
|
||||
user = insert(:user, pleroma_settings_store: %{fe: "test"})
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,11 @@ defmodule Pleroma.Web.MastodonAPI.NotificationViewTest do
|
|||
id: to_string(notification.id),
|
||||
pleroma: %{is_seen: false},
|
||||
type: "mention",
|
||||
account: AccountView.render("show.json", %{user: user, for: mentioned_user}),
|
||||
account:
|
||||
AccountView.render("show.json", %{
|
||||
user: user,
|
||||
for: mentioned_user
|
||||
}),
|
||||
status: StatusView.render("show.json", %{activity: activity, for: mentioned_user}),
|
||||
created_at: Utils.to_masto_date(notification.inserted_at)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -576,7 +576,7 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
end
|
||||
end
|
||||
|
||||
test "embeds a relationship in the account" do
|
||||
test "does not embed a relationship in the account" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
|
|
@ -587,13 +587,11 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
|
||||
result = StatusView.render("show.json", %{activity: activity, for: other_user})
|
||||
|
||||
assert result[:account][:pleroma][:relationship] ==
|
||||
AccountView.render("relationship.json", %{user: other_user, target: user})
|
||||
|
||||
assert result[:account][:pleroma][:relationship] == %{}
|
||||
assert_schema(result, "Status", Pleroma.Web.ApiSpec.spec())
|
||||
end
|
||||
|
||||
test "embeds a relationship in the account in reposts" do
|
||||
test "does not embed a relationship in the account in reposts" do
|
||||
user = insert(:user)
|
||||
other_user = insert(:user)
|
||||
|
||||
|
|
@ -606,12 +604,8 @@ defmodule Pleroma.Web.MastodonAPI.StatusViewTest do
|
|||
|
||||
result = StatusView.render("show.json", %{activity: activity, for: user})
|
||||
|
||||
assert result[:account][:pleroma][:relationship] ==
|
||||
AccountView.render("relationship.json", %{user: user, target: other_user})
|
||||
|
||||
assert result[:reblog][:account][:pleroma][:relationship] ==
|
||||
AccountView.render("relationship.json", %{user: user, target: user})
|
||||
|
||||
assert result[:account][:pleroma][:relationship] == %{}
|
||||
assert result[:reblog][:account][:pleroma][:relationship] == %{}
|
||||
assert_schema(result, "Status", Pleroma.Web.ApiSpec.spec())
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -31,8 +31,28 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
|||
|
||||
test "resend account confirmation email", %{conn: conn, user: user} do
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/pleroma/accounts/confirmation_resend?email=#{user.email}")
|
||||
|> json_response(:no_content)
|
||||
|> json_response_and_validate_schema(:no_content)
|
||||
|
||||
ObanHelpers.perform_all()
|
||||
|
||||
email = Pleroma.Emails.UserEmail.account_confirmation_email(user)
|
||||
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 "resend account confirmation email (with nickname)", %{conn: conn, user: user} do
|
||||
conn
|
||||
|> put_req_header("content-type", "application/json")
|
||||
|> post("/api/v1/pleroma/accounts/confirmation_resend?nickname=#{user.nickname}")
|
||||
|> json_response_and_validate_schema(:no_content)
|
||||
|
||||
ObanHelpers.perform_all()
|
||||
|
||||
|
|
@ -54,7 +74,10 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
|||
test "user avatar can be set", %{user: user, conn: conn} do
|
||||
avatar_image = File.read!("test/fixtures/avatar_data_uri")
|
||||
|
||||
conn = patch(conn, "/api/v1/pleroma/accounts/update_avatar", %{img: avatar_image})
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("content-type", "multipart/form-data")
|
||||
|> patch("/api/v1/pleroma/accounts/update_avatar", %{img: avatar_image})
|
||||
|
||||
user = refresh_record(user)
|
||||
|
||||
|
|
@ -70,17 +93,20 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
|||
]
|
||||
} = user.avatar
|
||||
|
||||
assert %{"url" => _} = json_response(conn, 200)
|
||||
assert %{"url" => _} = json_response_and_validate_schema(conn, 200)
|
||||
end
|
||||
|
||||
test "user avatar can be reset", %{user: user, conn: conn} do
|
||||
conn = patch(conn, "/api/v1/pleroma/accounts/update_avatar", %{img: ""})
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("content-type", "multipart/form-data")
|
||||
|> patch("/api/v1/pleroma/accounts/update_avatar", %{img: ""})
|
||||
|
||||
user = User.get_cached_by_id(user.id)
|
||||
|
||||
assert user.avatar == nil
|
||||
|
||||
assert %{"url" => nil} = json_response(conn, 200)
|
||||
assert %{"url" => nil} = json_response_and_validate_schema(conn, 200)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -88,21 +114,27 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
|||
setup do: oauth_access(["write:accounts"])
|
||||
|
||||
test "can set profile banner", %{user: user, conn: conn} do
|
||||
conn = patch(conn, "/api/v1/pleroma/accounts/update_banner", %{"banner" => @image})
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("content-type", "multipart/form-data")
|
||||
|> patch("/api/v1/pleroma/accounts/update_banner", %{"banner" => @image})
|
||||
|
||||
user = refresh_record(user)
|
||||
assert user.banner["type"] == "Image"
|
||||
|
||||
assert %{"url" => _} = json_response(conn, 200)
|
||||
assert %{"url" => _} = json_response_and_validate_schema(conn, 200)
|
||||
end
|
||||
|
||||
test "can reset profile banner", %{user: user, conn: conn} do
|
||||
conn = patch(conn, "/api/v1/pleroma/accounts/update_banner", %{"banner" => ""})
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("content-type", "multipart/form-data")
|
||||
|> patch("/api/v1/pleroma/accounts/update_banner", %{"banner" => ""})
|
||||
|
||||
user = refresh_record(user)
|
||||
assert user.banner == %{}
|
||||
|
||||
assert %{"url" => nil} = json_response(conn, 200)
|
||||
assert %{"url" => nil} = json_response_and_validate_schema(conn, 200)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -110,19 +142,26 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
|||
setup do: oauth_access(["write:accounts"])
|
||||
|
||||
test "background image can be set", %{user: user, conn: conn} do
|
||||
conn = patch(conn, "/api/v1/pleroma/accounts/update_background", %{"img" => @image})
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("content-type", "multipart/form-data")
|
||||
|> patch("/api/v1/pleroma/accounts/update_background", %{"img" => @image})
|
||||
|
||||
user = refresh_record(user)
|
||||
assert user.background["type"] == "Image"
|
||||
assert %{"url" => _} = json_response(conn, 200)
|
||||
# assert %{"url" => _} = json_response(conn, 200)
|
||||
assert %{"url" => _} = json_response_and_validate_schema(conn, 200)
|
||||
end
|
||||
|
||||
test "background image can be reset", %{user: user, conn: conn} do
|
||||
conn = patch(conn, "/api/v1/pleroma/accounts/update_background", %{"img" => ""})
|
||||
conn =
|
||||
conn
|
||||
|> put_req_header("content-type", "multipart/form-data")
|
||||
|> patch("/api/v1/pleroma/accounts/update_background", %{"img" => ""})
|
||||
|
||||
user = refresh_record(user)
|
||||
assert user.background == %{}
|
||||
assert %{"url" => nil} = json_response(conn, 200)
|
||||
assert %{"url" => nil} = json_response_and_validate_schema(conn, 200)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -143,7 +182,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
|||
response =
|
||||
conn
|
||||
|> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
|
||||
|> json_response(:ok)
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
[like] = response
|
||||
|
||||
|
|
@ -160,7 +199,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
|||
response =
|
||||
build_conn()
|
||||
|> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
|
||||
|> json_response(200)
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert length(response) == 1
|
||||
end
|
||||
|
|
@ -183,7 +222,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
|||
|> assign(:user, u)
|
||||
|> assign(:token, insert(:oauth_token, user: u, scopes: ["read:favourites"]))
|
||||
|> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
|
||||
|> json_response(:ok)
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
assert length(response) == 1
|
||||
end
|
||||
|
|
@ -191,7 +230,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
|||
response =
|
||||
build_conn()
|
||||
|> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
|
||||
|> json_response(200)
|
||||
|> json_response_and_validate_schema(200)
|
||||
|
||||
assert length(response) == 0
|
||||
end
|
||||
|
|
@ -213,7 +252,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
|||
response =
|
||||
conn
|
||||
|> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
|
||||
|> json_response(:ok)
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
assert Enum.empty?(response)
|
||||
end
|
||||
|
|
@ -233,11 +272,12 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
|||
|
||||
response =
|
||||
conn
|
||||
|> get("/api/v1/pleroma/accounts/#{user.id}/favourites", %{
|
||||
since_id: third_activity.id,
|
||||
max_id: seventh_activity.id
|
||||
})
|
||||
|> json_response(:ok)
|
||||
|> get(
|
||||
"/api/v1/pleroma/accounts/#{user.id}/favourites?since_id=#{third_activity.id}&max_id=#{
|
||||
seventh_activity.id
|
||||
}"
|
||||
)
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
assert length(response) == 3
|
||||
refute third_activity in response
|
||||
|
|
@ -256,8 +296,8 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
|||
|
||||
response =
|
||||
conn
|
||||
|> get("/api/v1/pleroma/accounts/#{user.id}/favourites", %{limit: "3"})
|
||||
|> json_response(:ok)
|
||||
|> get("/api/v1/pleroma/accounts/#{user.id}/favourites?limit=3")
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
assert length(response) == 3
|
||||
end
|
||||
|
|
@ -269,7 +309,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
|||
response =
|
||||
conn
|
||||
|> get("/api/v1/pleroma/accounts/#{user.id}/favourites")
|
||||
|> json_response(:ok)
|
||||
|> json_response_and_validate_schema(:ok)
|
||||
|
||||
assert Enum.empty?(response)
|
||||
end
|
||||
|
|
@ -277,7 +317,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
|||
test "returns 404 error when specified user is not exist", %{conn: conn} do
|
||||
conn = get(conn, "/api/v1/pleroma/accounts/test/favourites")
|
||||
|
||||
assert json_response(conn, 404) == %{"error" => "Record not found"}
|
||||
assert json_response_and_validate_schema(conn, 404) == %{"error" => "Record not found"}
|
||||
end
|
||||
|
||||
test "returns 403 error when user has hidden own favorites", %{conn: conn} do
|
||||
|
|
@ -287,7 +327,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
|||
|
||||
conn = get(conn, "/api/v1/pleroma/accounts/#{user.id}/favourites")
|
||||
|
||||
assert json_response(conn, 403) == %{"error" => "Can't get favorites"}
|
||||
assert json_response_and_validate_schema(conn, 403) == %{"error" => "Can't get favorites"}
|
||||
end
|
||||
|
||||
test "hides favorites for new users by default", %{conn: conn} do
|
||||
|
|
@ -298,7 +338,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
|||
assert user.hide_favorites
|
||||
conn = get(conn, "/api/v1/pleroma/accounts/#{user.id}/favourites")
|
||||
|
||||
assert json_response(conn, 403) == %{"error" => "Can't get favorites"}
|
||||
assert json_response_and_validate_schema(conn, 403) == %{"error" => "Can't get favorites"}
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -312,11 +352,12 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
|||
|> assign(:user, user)
|
||||
|> post("/api/v1/pleroma/accounts/#{subscription_target.id}/subscribe")
|
||||
|
||||
assert %{"id" => _id, "subscribing" => true} = json_response(ret_conn, 200)
|
||||
assert %{"id" => _id, "subscribing" => true} =
|
||||
json_response_and_validate_schema(ret_conn, 200)
|
||||
|
||||
conn = post(conn, "/api/v1/pleroma/accounts/#{subscription_target.id}/unsubscribe")
|
||||
|
||||
assert %{"id" => _id, "subscribing" => false} = json_response(conn, 200)
|
||||
assert %{"id" => _id, "subscribing" => false} = json_response_and_validate_schema(conn, 200)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -326,7 +367,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
|||
|
||||
conn = post(conn, "/api/v1/pleroma/accounts/target_id/subscribe")
|
||||
|
||||
assert %{"error" => "Record not found"} = json_response(conn, 404)
|
||||
assert %{"error" => "Record not found"} = json_response_and_validate_schema(conn, 404)
|
||||
end
|
||||
end
|
||||
|
||||
|
|
@ -336,7 +377,7 @@ defmodule Pleroma.Web.PleromaAPI.AccountControllerTest do
|
|||
|
||||
conn = post(conn, "/api/v1/pleroma/accounts/target_id/unsubscribe")
|
||||
|
||||
assert %{"error" => "Record not found"} = json_response(conn, 404)
|
||||
assert %{"error" => "Record not found"} = json_response_and_validate_schema(conn, 404)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue