defmodule CartosnapApp.Workers.ProcessImageTest do
use CartosnapApp.DataCase, async: true
use Oban.Testing, repo: CartosnapApp.Repo
import CartosnapApp.AccountsFixtures
import CartosnapApp.PhotosFixtures
alias CartosnapApp.Photos
alias CartosnapApp.Photos.Photo
alias CartosnapApp.Storage
alias CartosnapApp.Workers.ProcessImage
setup do
scope = user_scope_fixture()
path =
Path.join(System.tmp_dir!(), "cartosnap-worker-#{System.unique_integer([:positive])}.png")
{_, 0} = System.cmd("magick", ["-size", "1200x900", "plasma:", path])
on_exit(fn -> File.rm(path) end)
{:ok, photo} =
Photos.ingest_upload(scope, path, %{client_name: "big.png", client_type: "image/png"})
%{scope: scope, photo: photo}
end
test "makes and stores the variants, then records them", %{scope: scope, photo: photo} do
Photos.subscribe(scope)
assert :ok = perform_job(ProcessImage, %{id: photo.id})
photo = Photos.get_photo!(scope, photo.id)
assert Photo.processed?(photo)
assert photo.url_thumb == "#{scope.user.id}/#{photo.id}/thumb.png"
for key <- [photo.url_full, photo.url_preview, photo.url_thumb] do
assert {:ok, _} = Storage.get(key)
end
assert_receive {:photo_updated, %Photo{id: id}}
assert id == photo.id
end
test "cancels for a photo deleted before its turn", %{scope: scope, photo: photo} do
{:ok, _} = Photos.delete_photo(scope, photo)
assert {:cancel, :photo_deleted} = perform_job(ProcessImage, %{id: photo.id})
end
test "enqueue_missing/0 queues every photo without its variants", %{scope: scope} do
done = photo_fixture(scope)
pending = photo_fixture(scope, processed: false)
assert ProcessImage.enqueue_missing() >= 1
assert_enqueued(worker: ProcessImage, args: %{id: pending.id})
refute_enqueued(worker: ProcessImage, args: %{id: done.id})
end
end
neiam
/cartosnap_ex
public · Issues · Pulls · Labels · Forks · Compare · Actions queued · Badges · Packages
⭐
Log in to mark this repository.
1.9 KiB · text
History
e569b6d