upload_test.exs 1.72 KB
Newer Older
lain's avatar
lain committed
1
2
3
4
5
defmodule Pleroma.UploadTest do
  alias Pleroma.Upload
  use Pleroma.DataCase

  describe "Storing a file" do
Sir_Boops's avatar
Sir_Boops committed
6
7
8
    test "copies the file to the configured folder with deduping" do
      File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg")

lain's avatar
lain committed
9
10
      file = %Plug.Upload{
        content_type: "image/jpg",
Sir_Boops's avatar
Sir_Boops committed
11
        path: Path.absname("test/fixtures/image_tmp.jpg"),
lain's avatar
lain committed
12
13
14
        filename: "an [image.jpg"
      }

Sir_Boops's avatar
Sir_Boops committed
15
      data = Upload.store(file, true)
lain's avatar
lain committed
16

Sir_Boops's avatar
Sir_Boops committed
17
18
      assert data["name"] ==
               "e7a6d0cf595bff76f14c9a98b6c199539559e8b844e02e51e5efcfd1f614a2df.jpeg"
lain's avatar
lain committed
19
    end
eal's avatar
eal committed
20

Sir_Boops's avatar
Sir_Boops committed
21
22
23
    test "copies the file to the configured folder without deduping" do
      File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg")

lain's avatar
lain committed
24
      file = %Plug.Upload{
Sir_Boops's avatar
Sir_Boops committed
25
26
        content_type: "image/jpg",
        path: Path.absname("test/fixtures/image_tmp.jpg"),
lain's avatar
lain committed
27
28
29
        filename: "an [image.jpg"
      }

Sir_Boops's avatar
Sir_Boops committed
30
31
      data = Upload.store(file, false)
      assert data["name"] == "an [image.jpg"
eal's avatar
eal committed
32
33
    end

Sir_Boops's avatar
Sir_Boops committed
34
35
36
    test "fixes incorrect content type" do
      File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg")

lain's avatar
lain committed
37
      file = %Plug.Upload{
Sir_Boops's avatar
Sir_Boops committed
38
39
        content_type: "application/octet-stream",
        path: Path.absname("test/fixtures/image_tmp.jpg"),
lain's avatar
lain committed
40
41
42
        filename: "an [image.jpg"
      }

Sir_Boops's avatar
Sir_Boops committed
43
44
      data = Upload.store(file, true)
      assert hd(data["url"])["mediaType"] == "image/jpeg"
eal's avatar
eal committed
45
    end
46
47
48
49
50
51
52
53
54
55
56
57
58

    test "adds missing extension" do
      File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg")

      file = %Plug.Upload{
        content_type: "image/jpg",
        path: Path.absname("test/fixtures/image_tmp.jpg"),
        filename: "an [image"
      }

      data = Upload.store(file, false)
      assert data["name"] == "an [image.jpg"
    end
lain's avatar
lain committed
59
60
  end
end