Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Mandrill to return ok/error tuples #574

Merged
merged 1 commit into from
Feb 19, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/bamboo/adapters/mandrill_adapter.ex
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ defmodule Bamboo.MandrillAdapter do
filtered_params =
params |> Bamboo.json_library().decode!() |> Map.put("key", "[FILTERED]")

raise_api_error(@service_name, response, filtered_params)
{:error, build_api_error(@service_name, response, filtered_params)}

{:ok, status, headers, response} ->
%{status_code: status, headers: headers, body: response}
{:ok, %{status_code: status, headers: headers, body: response}}

{:error, reason} ->
raise_api_error(inspect(reason))
{:error, build_api_error(inspect(reason))}
end
end

Expand Down
20 changes: 13 additions & 7 deletions test/lib/bamboo/adapters/mandrill_adapter_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,12 @@ defmodule Bamboo.MandrillAdapterTest do
assert request_path == "/api/1.0/messages/send.json"
end

test "deliver/2 returns an {:ok, response} tuple on success" do
{:ok, response} = new_email() |> MandrillAdapter.deliver(@config)

assert %{status_code: 200, headers: _, body: _} = response
end

test "deliver/2 sends the to the right url for templates" do
new_email() |> MandrillHelper.template("hello") |> MandrillAdapter.deliver(@config)

Expand Down Expand Up @@ -195,20 +201,20 @@ defmodule Bamboo.MandrillAdapterTest do
assert template_content == [%{"content" => 'example content', "name" => 'example name'}]
end

test "raises if the response is not a success" do
test "returns an error if the response is not a success" do
email = new_email(from: "INVALID_EMAIL")

assert_raise Bamboo.ApiError, fn ->
email |> MandrillAdapter.deliver(@config)
end
{:error, error} = email |> MandrillAdapter.deliver(@config)

assert %Bamboo.ApiError{} = error
end

test "removes api key from error output" do
email = new_email(from: "INVALID_EMAIL")

assert_raise Bamboo.ApiError, ~r/"key" => "\[FILTERED\]"/, fn ->
email |> MandrillAdapter.deliver(@config)
end
{:error, error} = email |> MandrillAdapter.deliver(@config)

assert error.message =~ ~r/"key" => "\[FILTERED\]"/
end

defp new_email(attrs \\ []) do
Expand Down