Skip to content

Commit

Permalink
100% coveralls
Browse files Browse the repository at this point in the history
  • Loading branch information
ndrean committed Dec 20, 2023
1 parent ec283a5 commit dc509c6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/app_web/live/page_live.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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.
Expand Down
File renamed without changes
16 changes: 16 additions & 0 deletions test/app_web/live/page_live_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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!"
Expand Down Expand Up @@ -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", %{}, %{})

Expand Down

0 comments on commit dc509c6

Please sign in to comment.