Skip to content

Commit

Permalink
add fail.jpg (deliberately corrupted JPEG file) to test failure #69 / #…
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonic committed Jul 11, 2023
1 parent cc0e976 commit cb0a9a3
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 4 deletions.
Binary file added priv/static/images/fail.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
25 changes: 21 additions & 4 deletions test/app/upload_test.exs
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
defmodule App.UploadTest do
use ExUnit.Case, async: true

@compressed_bucket Application.compile_env(:ex_aws, :compressed_bucket)
@original_bucket Application.compile_env(:ex_aws, :original_bucket)

test "upload/1 happy path REAL Upload" do
image = %Plug.Upload{
content_type: "image/png",
Expand All @@ -10,9 +13,9 @@ defmodule App.UploadTest do

expected_response = %{
compressed_url:
"https://s3.eu-west-3.amazonaws.com/#{Application.get_env(:ex_aws, :compressed_bucket)}/zb2rhXACvyoVCaV1GF5ozeoNCXYdxcKAEWvBTpsnabo3moYwB.png",
"https://s3.eu-west-3.amazonaws.com/#{@compressed_bucket}/zb2rhXACvyoVCaV1GF5ozeoNCXYdxcKAEWvBTpsnabo3moYwB.png",
url:
"https://s3.eu-west-3.amazonaws.com/#{Application.get_env(:ex_aws, :original_bucket)}/zb2rhXACvyoVCaV1GF5ozeoNCXYdxcKAEWvBTpsnabo3moYwB.png"
"https://s3.eu-west-3.amazonaws.com/#{@original_bucket}/zb2rhXACvyoVCaV1GF5ozeoNCXYdxcKAEWvBTpsnabo3moYwB.png"
}

assert App.Upload.upload(image) == {:ok, expected_response}
Expand All @@ -27,9 +30,23 @@ defmodule App.UploadTest do

expected_response = %{
compressed_url:
"https://s3.eu-west-3.amazonaws.com/#{Application.get_env(:ex_aws, :compressed_bucket)}/zb2rhe5aFXPKonoWchLRYo9yJDqWyUdUeTQ6MQQJsTWnzzNum.jpg",
"https://s3.eu-west-3.amazonaws.com/#{@compressed_bucket}/zb2rhe5aFXPKonoWchLRYo9yJDqWyUdUeTQ6MQQJsTWnzzNum.jpg",
url:
"https://s3.eu-west-3.amazonaws.com/#{Application.get_env(:ex_aws, :original_bucket)}/zb2rhe5aFXPKonoWchLRYo9yJDqWyUdUeTQ6MQQJsTWnzzNum.jpg"
"https://s3.eu-west-3.amazonaws.com/#{@original_bucket}/zb2rhe5aFXPKonoWchLRYo9yJDqWyUdUeTQ6MQQJsTWnzzNum.jpg"
}
assert App.Upload.upload(image) == {:ok, expected_response}
end

test "upload/1 fail.jpg corrupted jpeg to test failure" do
image = %Plug.Upload{
content_type: "image/jpeg",
filename: "ginger.jpg",
path: [:code.priv_dir(:app), "static", "images", "fail.jpg"] |> Path.join()
}
# Even though the jpeg is *deliberately* corrupted the upload & CID still works!!
expected_response = %{
compressed_url: "https://s3.eu-west-3.amazonaws.com/#{@compressed_bucket}/zb2rhngHXWi8mR5YHX3Go4xDYpZqqcAtGefn8sktQMM7YzKEz.jpg",
url: "https://s3.eu-west-3.amazonaws.com/#{@original_bucket}/zb2rhngHXWi8mR5YHX3Go4xDYpZqqcAtGefn8sktQMM7YzKEz.jpg"
}
assert App.Upload.upload(image) == {:ok, expected_response}
end
Expand Down

0 comments on commit cb0a9a3

Please sign in to comment.