X-Git-Url: http://git.squeep.com/?a=blobdiff_plain;ds=sidebyside;f=test%2Fpleroma%2Fweb%2Fpleroma_api%2Fcontrollers%2Femoji_pack_controller_test.exs;h=5c24739556393dabcc1b290b287bc1bef5f0b1ce;hb=87c468f009e048634b705452abbdf2ef489cd055;hp=3445f0ca043173879a9e7e9af218f1c1d24c213c;hpb=2f7401806bbe5427bbcaa7cdce35130320ae3bb4;p=akkoma
diff --git a/test/pleroma/web/pleroma_api/controllers/emoji_pack_controller_test.exs b/test/pleroma/web/pleroma_api/controllers/emoji_pack_controller_test.exs
index 3445f0ca0..5c2473955 100644
--- a/test/pleroma/web/pleroma_api/controllers/emoji_pack_controller_test.exs
+++ b/test/pleroma/web/pleroma_api/controllers/emoji_pack_controller_test.exs
@@ -1,10 +1,11 @@
# Pleroma: A lightweight social networking server
-# Copyright © 2017-2020 Pleroma Authors
+# Copyright © 2017-2021 Pleroma Authors
# SPDX-License-Identifier: AGPL-3.0-only
defmodule Pleroma.Web.PleromaAPI.EmojiPackControllerTest do
- use Pleroma.Web.ConnCase
+ use Pleroma.Web.ConnCase, async: false
+ import Mock
import Tesla.Mock
import Pleroma.Factory
@@ -346,7 +347,7 @@ defmodule Pleroma.Web.PleromaAPI.EmojiPackControllerTest 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 +366,20 @@ defmodule Pleroma.Web.PleromaAPI.EmojiPackControllerTest do
}}
end
+ test "returns error when file system not writable", %{admin_conn: conn} = ctx do
+ with_mocks([
+ {File, [:passthrough], [stat: fn _ -> {:error, :eacces} end]}
+ ]) do
+ 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)
+ 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 +439,46 @@ defmodule Pleroma.Web.PleromaAPI.EmojiPackControllerTest do
end
describe "POST/DELETE /api/pleroma/emoji/pack?name=:name" do
+ test "returns an error on creates pack when file system not writable", %{
+ admin_conn: admin_conn
+ } do
+ path_pack = Path.join(@emoji_path, "test_pack")
+
+ with_mocks([
+ {File, [:passthrough], [mkdir: fn ^path_pack -> {:error, :eacces} end]}
+ ]) do
+ 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)"
+ }
+ end
+ end
+
+ test "returns an error on deletes pack when the file system is not writable", %{
+ admin_conn: admin_conn
+ } do
+ path_pack = Path.join(@emoji_path, "test_emoji_pack")
+
+ try do
+ {:ok, _pack} = Pleroma.Emoji.Pack.create("test_emoji_pack")
+
+ with_mocks([
+ {File, [:passthrough], [rm_rf: fn ^path_pack -> {:error, :eacces, path_pack} end]}
+ ]) do
+ assert admin_conn
+ |> delete("/api/pleroma/emoji/pack?name=test_emoji_pack")
+ |> json_response_and_validate_schema(500) == %{
+ "error" =>
+ "Couldn't delete the `test_emoji_pack` pack (POSIX error: Permission denied)"
+ }
+ end
+ after
+ File.rm_rf(path_pack)
+ end
+ end
+
test "creating and deleting a pack", %{admin_conn: admin_conn} do
assert admin_conn
|> post("/api/pleroma/emoji/pack?name=test_created")