Merge branch 'feature/invites' into 'develop'
[akkoma] / test / upload_test.exs
1 defmodule Pleroma.UploadTest do
2 alias Pleroma.Upload
3 use Pleroma.DataCase
4
5 describe "Storing a file" do
6 test "copies the file to the configured folder with deduping" do
7 File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg")
8
9 file = %Plug.Upload{
10 content_type: "image/jpg",
11 path: Path.absname("test/fixtures/image_tmp.jpg"),
12 filename: "an [image.jpg"
13 }
14
15 data = Upload.store(file, true)
16
17 assert data["name"] ==
18 "e7a6d0cf595bff76f14c9a98b6c199539559e8b844e02e51e5efcfd1f614a2df.jpeg"
19 end
20
21 test "copies the file to the configured folder without deduping" do
22 File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg")
23
24 file = %Plug.Upload{
25 content_type: "image/jpg",
26 path: Path.absname("test/fixtures/image_tmp.jpg"),
27 filename: "an [image.jpg"
28 }
29
30 data = Upload.store(file, false)
31 assert data["name"] == "an [image.jpg"
32 end
33
34 test "fixes incorrect content type" do
35 File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg")
36
37 file = %Plug.Upload{
38 content_type: "application/octet-stream",
39 path: Path.absname("test/fixtures/image_tmp.jpg"),
40 filename: "an [image.jpg"
41 }
42
43 data = Upload.store(file, true)
44 assert hd(data["url"])["mediaType"] == "image/jpeg"
45 end
46
47 test "adds missing extension" do
48 File.cp!("test/fixtures/image.jpg", "test/fixtures/image_tmp.jpg")
49
50 file = %Plug.Upload{
51 content_type: "image/jpg",
52 path: Path.absname("test/fixtures/image_tmp.jpg"),
53 filename: "an [image"
54 }
55
56 data = Upload.store(file, false)
57 assert data["name"] == "an [image.jpg"
58 end
59 end
60 end