Various refactoring and typespec improvements

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel
2021-09-24 16:46:42 +02:00
parent d235653876
commit 1893d9f55b
142 changed files with 1854 additions and 1297 deletions

View File

@@ -8,6 +8,15 @@ defmodule Mobilizon.Web.Upload.Uploader.LocalTest do
alias Mobilizon.Web.Upload
alias Mobilizon.Web.Upload.Uploader.Local
@file_path "local_upload/files/image.jpg"
@local_path Path.join([Local.upload_path(), @file_path])
setup do
File.rm(@local_path)
:ok
end
describe "get_file/1" do
test "it returns path to local folder for files" do
assert Local.get_file("") == {:ok, {:static_dir, "test/uploads"}}
@@ -17,42 +26,44 @@ defmodule Mobilizon.Web.Upload.Uploader.LocalTest do
describe "put_file/1" do
test "put file to local folder" do
File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg")
file_path = "local_upload/files/image.jpg"
file = %Upload{
name: "image.jpg",
content_type: "image/jpeg",
path: file_path,
path: @file_path,
tempfile: Path.absname("test/fixtures/image_tmp.jpg")
}
assert Local.put_file(file) == :ok
assert {:ok, {:file, @file_path}} == Local.put_file(file)
assert [Local.upload_path(), file_path]
|> Path.join()
|> File.exists?()
assert File.exists?(@local_path)
assert :ok == Local.put_file(file)
assert File.exists?(@local_path)
end
end
describe "remove_file/1" do
test "removes local file" do
File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg")
file_path = "local_upload/files/image.jpg"
file = %Upload{
name: "image.jpg",
content_type: "image/jpeg",
path: file_path,
path: @file_path,
tempfile: Path.absname("test/fixtures/image_tmp.jpg")
}
:ok = Local.put_file(file)
local_path = Path.join([Local.upload_path(), file_path])
assert File.exists?(local_path)
refute File.exists?(@local_path)
Local.remove_file(file_path)
assert {:ok, {:file, @file_path}} = Local.put_file(file)
refute File.exists?(local_path)
assert File.exists?(@local_path)
Local.remove_file(@file_path)
refute File.exists?(@local_path)
end
end
end