mobilizon.chapril.org-mobil.../test/mobilizon/media/media_test.exs

68 lines
1.8 KiB
Elixir
Raw Normal View History

defmodule Mobilizon.MediaTest do
use Mobilizon.DataCase
import Mobilizon.Factory
2019-09-08 00:05:54 +02:00
alias Mobilizon.{Config, Media}
2020-01-26 21:36:50 +01:00
alias Mobilizon.Web.Upload.Uploader
2020-01-23 21:59:50 +01:00
describe "media" do
setup [:ensure_local_uploader]
alias Mobilizon.Media.Picture
@valid_attrs %{
file: %{
url: "https://something.tld/media/something",
name: "something old"
}
}
@update_attrs %{
file: %{
url: "https://something.tld/media/something_updated",
name: "something new"
}
}
test "get_picture!/1 returns the picture with given id" do
picture = insert(:picture)
2019-05-31 17:58:03 +02:00
assert Media.get_picture!(picture.id).id == picture.id
end
test "create_picture/1 with valid data creates a picture" do
2019-05-31 17:58:03 +02:00
assert {:ok, %Picture{} = picture} =
Media.create_picture(Map.put(@valid_attrs, :actor_id, insert(:actor).id))
assert picture.file.name == "something old"
end
test "update_picture/2 with valid data updates the picture" do
picture = insert(:picture)
2019-05-31 17:58:03 +02:00
assert {:ok, %Picture{} = picture} =
Media.update_picture(picture, Map.put(@update_attrs, :actor_id, insert(:actor).id))
assert picture.file.name == "something new"
end
test "delete_picture/1 deletes the picture" do
picture = insert(:picture)
%URI{path: "/media/" <> path} = URI.parse(picture.file.url)
assert File.exists?(
2020-01-23 21:59:50 +01:00
Config.get!([Uploader.Local, :uploads]) <>
"/" <> path
)
assert {:ok, %Picture{}} = Media.delete_picture(picture)
assert_raise Ecto.NoResultsError, fn -> Media.get_picture!(picture.id) end
refute File.exists?(
2020-01-23 21:59:50 +01:00
Config.get!([Uploader.Local, :uploads]) <>
"/" <> path
)
end
end
end