From dc509c6c450071ebe7fdf299cd7d9aff4ed2f065 Mon Sep 17 00:00:00 2001 From: Neven DREAN Date: Wed, 20 Dec 2023 12:09:14 -0500 Subject: [PATCH] 100% coveralls --- lib/app_web/live/page_live.ex | 6 +++--- text.png => priv/static/images/test.png | 0 test/app_web/live/page_live_test.exs | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 3 deletions(-) rename text.png => priv/static/images/test.png (100%) diff --git a/lib/app_web/live/page_live.ex b/lib/app_web/live/page_live.ex index 8b3261a..bec6c82 100644 --- a/lib/app_web/live/page_live.ex +++ b/lib/app_web/live/page_live.ex @@ -94,8 +94,8 @@ defmodule AppWeb.PageLive do do: {:ok, {mimetype, width, height, variant}}, else: {:error, "MIME types do not correspond"} else - {:image_info, nil} -> {:error, "bad file"} |> dbg() - {:gen_magic, {:error, reason}} -> {:error, reason} |> dbg() + {:image_info, nil} -> {:error, "bad file"} + {:gen_magic, {:error, reason}} -> {:error, reason} end end @@ -175,7 +175,7 @@ defmodule AppWeb.PageLive do end # intermediate chunk consumption - def handle_progress(:image_list, _, socket), do: {:noreply, socket} + def handle_progress(_, _, socket), do: {:noreply, socket} @doc """ Every time an `async task` is created, this function is called. diff --git a/text.png b/priv/static/images/test.png similarity index 100% rename from text.png rename to priv/static/images/test.png diff --git a/test/app_web/live/page_live_test.exs b/test/app_web/live/page_live_test.exs index 1de13cb..d5c04c8 100644 --- a/test/app_web/live/page_live_test.exs +++ b/test/app_web/live/page_live_test.exs @@ -91,6 +91,17 @@ defmodule AppWeb.PageLiveTest do assert render(lv) =~ "Image too large. Upload a smaller image up to 5MB." end + test "check MIME type", %{conn: _conn} do + path = [:code.priv_dir(:app), "static", "images", "test.png"] |> Path.join() + file = build_upload(path, "image/xyz") + + assert AppWeb.PageLive.check_file(file, path) == {:error, "bad file"} + + accepted_mime = ~w(image/jpeg image/jpg image/png image/webp) + assert App.Image.gen_magic_eval(path, accepted_mime) == {:error, "not acceptable"} + assert App.Image.gen_magic_eval("", accepted_mime) == {:error, "invalid command"} + end + test "uploading an invalid image", %{conn: conn} do {:ok, lv, html} = live(conn, ~p"/") assert html =~ "Caption your image!" @@ -149,6 +160,11 @@ defmodule AppWeb.PageLiveTest do end end + test "handle_intermediate_progress", %{conn: _conn} do + ret = AppWeb.PageLive.handle_progress(:image_list, %{}, %{}) + assert ret == {:noreply, %{}} + end + test "noop event handler", %{conn: _conn} do ret = AppWeb.PageLive.handle_event("noop", %{}, %{})