Merge branch 'feature/unrepeat-tests' into feature/unrepeats
[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" do
7 file = %Plug.Upload{
8 content_type: "image/jpg",
9 path: Path.absname("test/fixtures/image.jpg"),
10 filename: "an [image.jpg"
11 }
12
13 data = Upload.store(file)
14 assert data["name"] == "an [image.jpg"
15
16 assert List.first(data["url"])["href"] ==
17 "http://localhost:4001/media/#{data["uuid"]}/an%20%5Bimage.jpg"
18 end
19
20 test "fixes an incorrect content type" do
21 file = %Plug.Upload{
22 content_type: "application/octet-stream",
23 path: Path.absname("test/fixtures/image.jpg"),
24 filename: "an [image.jpg"
25 }
26
27 data = Upload.store(file)
28 assert hd(data["url"])["mediaType"] == "image/jpeg"
29 end
30
31 test "does not modify a valid content type" do
32 file = %Plug.Upload{
33 content_type: "image/png",
34 path: Path.absname("test/fixtures/image.jpg"),
35 filename: "an [image.jpg"
36 }
37
38 data = Upload.store(file)
39 assert hd(data["url"])["mediaType"] == "image/png"
40 end
41 end
42 end