Add test for avatar description

Signed-off-by: marcin mikołajczak <git@mkljczk.pl>
This commit is contained in:
marcin mikołajczak 2024-08-17 17:02:44 +02:00
parent 71ef9f9519
commit 681765669c
3 changed files with 47 additions and 1 deletions

View file

@ -697,7 +697,7 @@ defmodule Pleroma.User do
{:ok, object} <- Object.update_data(object, %{"name" => description}) do
put_change(changeset, image_field, object.data)
else
e -> changeset
_ -> changeset
end
end

View file

@ -148,10 +148,13 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Account do
}
}
}
avatar_description: %Schema{type: :string},
header_description: %Schema{type: :string}
},
example: %{
"acct" => "foobar",
"avatar" => "https://mypleroma.com/images/avi.png",
"avatar_description" => "",
"avatar_static" => "https://mypleroma.com/images/avi.png",
"bot" => false,
"created_at" => "2020-03-24T13:05:58.000Z",
@ -162,6 +165,7 @@ defmodule Pleroma.Web.ApiSpec.Schemas.Account do
"followers_count" => 0,
"following_count" => 1,
"header" => "https://mypleroma.com/images/banner.png",
"header_description" => "",
"header_static" => "https://mypleroma.com/images/banner.png",
"id" => "9tKi3esbG7OQgZ2920",
"locked" => false,

View file

@ -430,6 +430,48 @@ defmodule Pleroma.Web.MastodonAPI.UpdateCredentialsTest do
assert :ok == File.rm(Path.absname("test/tmp/large_binary.data"))
end
test "adds avatar description with a new avatar", %{user: user, conn: conn} do
new_avatar = %Plug.Upload{
content_type: "image/jpeg",
path: Path.absname("test/fixtures/image.jpg"),
filename: "an_image.jpg"
}
res =
patch(conn, "/api/v1/accounts/update_credentials", %{
"avatar" => new_avatar,
"avatar_description" => "me and pleroma tan"
})
assert json_response_and_validate_schema(res, 200)
user = User.get_by_id(user.id)
assert user.avatar["name"] == "me and pleroma tan"
end
test "adds avatar description to existing avatar", %{user: user, conn: conn} do
new_avatar = %Plug.Upload{
content_type: "image/jpeg",
path: Path.absname("test/fixtures/image.jpg"),
filename: "an_image.jpg"
}
assert user.avatar == %{}
conn
|> patch("/api/v1/accounts/update_credentials", %{"avatar" => new_avatar})
assert conn
|> assign(:user, User.get_by_id(user.id))
|> patch("/api/v1/accounts/update_credentials", %{
"avatar_description" => "me and pleroma tan"
})
|> json_response_and_validate_schema(200)
user = User.get_by_id(user.id)
assert user.avatar["name"] == "me and pleroma tan"
end
test "Strip / from upload files", %{user: user, conn: conn} do
new_image = %Plug.Upload{
content_type: "image/jpeg",