Skip to content

Commit

Permalink
add ginger.pdf (valid file) for API test #69
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonic committed Jul 12, 2023
1 parent c84c857 commit 84e5593
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Binary file added priv/static/images/ginger.pdf
Binary file not shown.
16 changes: 16 additions & 0 deletions test/app_web/api_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,15 @@ defmodule AppWeb.APITest do
}
}

# Valid PDF
@valid_pdf_attrs %{
"image" => %Plug.Upload{
content_type: "application/pdf",
filename: "ginger.pdf",
path: [:code.priv_dir(:app), "static", "images", "ginger.pdf"] |> Path.join()
}
}

# random non-existent pdf
@invalid_attrs %{
"" => %Plug.Upload{
Expand Down Expand Up @@ -74,6 +83,13 @@ defmodule AppWeb.APITest do
assert Jason.decode!(response(conn, 200)) == expected
end

test "upload pdf", %{conn: conn} do
conn = post(conn, ~p"/api/images", @valid_pdf_attrs)
assert Map.get(Jason.decode!(response(conn, 400)), "errors") == %{
"detail" => "Uploaded file is not a valid image."
}
end

test "wrong file extension", %{conn: conn} do
conn = post(conn, ~p"/api/images", @invalid_attrs)

Expand Down

0 comments on commit 84e5593

Please sign in to comment.