move to 2.5.5
[anni] / test / pleroma / uploaders / local_test.exs
1 # Pleroma: A lightweight social networking server
2 # Copyright © 2017-2022 Pleroma Authors <https://pleroma.social/>
3 # SPDX-License-Identifier: AGPL-3.0-only
4
5 defmodule Pleroma.Uploaders.LocalTest do
6   use Pleroma.DataCase, async: true
7   alias Pleroma.Uploaders.Local
8
9   describe "get_file/1" do
10     test "it returns path to local folder for files" do
11       assert Local.get_file("") == {:ok, {:static_dir, "test/uploads"}}
12     end
13   end
14
15   describe "put_file/1" do
16     test "put file to local folder" do
17       File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg")
18       file_path = "local_upload/files/image.jpg"
19
20       file = %Pleroma.Upload{
21         name: "image.jpg",
22         content_type: "image/jpeg",
23         path: file_path,
24         tempfile: Path.absname("test/fixtures/image_tmp.jpg")
25       }
26
27       assert Local.put_file(file) == :ok
28
29       assert Path.join([Local.upload_path(), file_path])
30              |> File.exists?()
31     end
32   end
33
34   describe "delete_file/1" do
35     test "deletes local file" do
36       File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg")
37       file_path = "local_upload/files/image.jpg"
38
39       file = %Pleroma.Upload{
40         name: "image.jpg",
41         content_type: "image/jpeg",
42         path: file_path,
43         tempfile: Path.absname("test/fixtures/image_tmp.jpg")
44       }
45
46       :ok = Local.put_file(file)
47       local_path = Path.join([Local.upload_path(), file_path])
48       assert File.exists?(local_path)
49
50       Local.delete_file(file_path)
51
52       refute File.exists?(local_path)
53     end
54   end
55 end