added test

This commit is contained in:
Maksim Pechnikov 2020-11-14 08:30:22 +03:00
parent 1830b6aae5
commit 36ec604521
2 changed files with 61 additions and 4 deletions

View file

@ -169,7 +169,8 @@ def delete_operation do
responses: %{
200 => ok_response(),
400 => Operation.response("Bad Request", "application/json", ApiError),
404 => Operation.response("Not Found", "application/json", ApiError)
404 => Operation.response("Not Found", "application/json", ApiError),
500 => Operation.response("Error", "application/json", ApiError)
}
}
end
@ -184,7 +185,8 @@ def update_operation do
parameters: [name_param()],
responses: %{
200 => Operation.response("Metadata", "application/json", metadata()),
400 => Operation.response("Bad Request", "application/json", ApiError)
400 => Operation.response("Bad Request", "application/json", ApiError),
500 => Operation.response("Error", "application/json", ApiError)
}
}
end

View file

@ -3,7 +3,7 @@
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.PleromaAPI.EmojiPackControllerTest do
use Pleroma.Web.ConnCase
use Pleroma.Web.ConnCase, async: false
import Tesla.Mock
import Pleroma.Factory
@ -346,7 +346,7 @@ test "other error", %{admin_conn: admin_conn} do
end
end
describe "PATCH /api/pleroma/emoji/pack?name=:name" do
describe "PATCH/update /api/pleroma/emoji/pack?name=:name" do
setup do
pack_file = "#{@emoji_path}/test_pack/pack.json"
original_content = File.read!(pack_file)
@ -365,6 +365,24 @@ test "other error", %{admin_conn: admin_conn} do
}}
end
test "returns error when file system not writable", %{admin_conn: conn} = ctx do
{:ok, %File.Stat{mode: mode}} = File.stat(@emoji_path)
try do
File.chmod!(@emoji_path, 0o400)
assert conn
|> put_req_header("content-type", "multipart/form-data")
|> patch(
"/api/pleroma/emoji/pack?name=test_pack",
%{"metadata" => ctx[:new_data]}
)
|> json_response_and_validate_schema(500)
after
File.chmod!(@emoji_path, mode)
end
end
test "for a pack without a fallback source", ctx do
assert ctx[:admin_conn]
|> put_req_header("content-type", "multipart/form-data")
@ -424,6 +442,43 @@ test "when the fallback source doesn't have all the files", ctx do
end
describe "POST/DELETE /api/pleroma/emoji/pack?name=:name" do
test "returns error when file system not writable", %{admin_conn: admin_conn} do
{:ok, %File.Stat{mode: mode}} = File.stat(@emoji_path)
try do
File.chmod!(@emoji_path, 0o400)
assert admin_conn
|> post("/api/pleroma/emoji/pack?name=test_pack")
|> json_response_and_validate_schema(500) == %{
"error" =>
"Unexpected error occurred while creating pack. (POSIX error: Permission denied)"
}
after
File.chmod!(@emoji_path, mode)
end
end
test "returns an error on deletes pack when the file system is not writable", %{
admin_conn: admin_conn
} do
{:ok, _pack} = Pleroma.Emoji.Pack.create("test_pack2")
{:ok, %File.Stat{mode: mode}} = File.stat(@emoji_path)
try do
File.chmod!(@emoji_path, 0o400)
assert admin_conn
|> delete("/api/pleroma/emoji/pack?name=test_pack")
|> json_response_and_validate_schema(500) == %{
"error" => "Couldn't delete the pack test_pack (POSIX error: Permission denied)"
}
after
File.chmod!(@emoji_path, mode)
File.rm_rf!(Path.join([@emoji_path, "test_pack2"]))
end
end
test "creating and deleting a pack", %{admin_conn: admin_conn} do
assert admin_conn
|> post("/api/pleroma/emoji/pack?name=test_created")