Skip to content

Commit

Permalink
add *real* test for uploading a JPEG image to S3 #91
Browse files Browse the repository at this point in the history
  • Loading branch information
nelsonic committed Jul 7, 2023
1 parent 357c277 commit cc0e976
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -37,3 +37,6 @@ npm-debug.log

.env
.vscode/launch.json

# Mac Noise
.DS_Store
Binary file added priv/static/images/ginger.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
16 changes: 16 additions & 0 deletions test/app/upload_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,20 @@ defmodule App.UploadTest do

assert App.Upload.upload(image) == {:ok, expected_response}
end

test "upload/1 ginger.jpg (cat pic)" do
image = %Plug.Upload{
content_type: "image/jpeg",
filename: "ginger.jpg",
path: [:code.priv_dir(:app), "static", "images", "ginger.jpg"] |> Path.join()
}

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

0 comments on commit cc0e976

Please sign in to comment.