added test
This commit is contained in:
parent
1830b6aae5
commit
36ec604521
@ -169,7 +169,8 @@ defmodule Pleroma.Web.ApiSpec.PleromaEmojiPackOperation do
|
|||||||
responses: %{
|
responses: %{
|
||||||
200 => ok_response(),
|
200 => ok_response(),
|
||||||
400 => Operation.response("Bad Request", "application/json", ApiError),
|
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
|
end
|
||||||
@ -184,7 +185,8 @@ defmodule Pleroma.Web.ApiSpec.PleromaEmojiPackOperation do
|
|||||||
parameters: [name_param()],
|
parameters: [name_param()],
|
||||||
responses: %{
|
responses: %{
|
||||||
200 => Operation.response("Metadata", "application/json", metadata()),
|
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
|
end
|
||||||
|
@ -3,7 +3,7 @@
|
|||||||
# SPDX-License-Identifier: AGPL-3.0-only
|
# SPDX-License-Identifier: AGPL-3.0-only
|
||||||
|
|
||||||
defmodule Pleroma.Web.PleromaAPI.EmojiPackControllerTest do
|
defmodule Pleroma.Web.PleromaAPI.EmojiPackControllerTest do
|
||||||
use Pleroma.Web.ConnCase
|
use Pleroma.Web.ConnCase, async: false
|
||||||
|
|
||||||
import Tesla.Mock
|
import Tesla.Mock
|
||||||
import Pleroma.Factory
|
import Pleroma.Factory
|
||||||
@ -346,7 +346,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiPackControllerTest do
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
describe "PATCH /api/pleroma/emoji/pack?name=:name" do
|
describe "PATCH/update /api/pleroma/emoji/pack?name=:name" do
|
||||||
setup do
|
setup do
|
||||||
pack_file = "#{@emoji_path}/test_pack/pack.json"
|
pack_file = "#{@emoji_path}/test_pack/pack.json"
|
||||||
original_content = File.read!(pack_file)
|
original_content = File.read!(pack_file)
|
||||||
@ -365,6 +365,24 @@ defmodule Pleroma.Web.PleromaAPI.EmojiPackControllerTest do
|
|||||||
}}
|
}}
|
||||||
end
|
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
|
test "for a pack without a fallback source", ctx do
|
||||||
assert ctx[:admin_conn]
|
assert ctx[:admin_conn]
|
||||||
|> put_req_header("content-type", "multipart/form-data")
|
|> put_req_header("content-type", "multipart/form-data")
|
||||||
@ -424,6 +442,43 @@ defmodule Pleroma.Web.PleromaAPI.EmojiPackControllerTest do
|
|||||||
end
|
end
|
||||||
|
|
||||||
describe "POST/DELETE /api/pleroma/emoji/pack?name=:name" do
|
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
|
test "creating and deleting a pack", %{admin_conn: admin_conn} do
|
||||||
assert admin_conn
|
assert admin_conn
|
||||||
|> post("/api/pleroma/emoji/pack?name=test_created")
|
|> post("/api/pleroma/emoji/pack?name=test_created")
|
||||||
|
Loading…
Reference in New Issue
Block a user