Fork of Pleroma with site-specific changes and feature branches https://git.pleroma.social/pleroma/pleroma
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

61 lines
1.7KB

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