Skip to content

Commit

Permalink
Cambia error de mapa a tupla y agrega test para manejar los posibles …
Browse files Browse the repository at this point in the history
…errores
  • Loading branch information
poncho committed Apr 23, 2021
1 parent c1df433 commit 9e657fe
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/auth/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ defmodule Whatsapp.Auth.Server do
rescue
error ->
previous_errors = Map.get(credentials, :errors, [])
errors = [%{provider.name => inspect(error)} | previous_errors]
errors = [{provider.name, inspect(error)} | previous_errors]
Map.put(credentials, :errors, errors)
end
end)
Expand Down
41 changes: 41 additions & 0 deletions test/auth/server_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,45 @@ defmodule Whatsapp.Auth.ServerTest do
assert auth_header == {"Authorization", "Bearer dXNlcm5hbWU6cGFzc3dvcmQ="}
end
end

test "Should catch login errors if the Auth server has problems logging in a Whatsapp Server" do
error = %HTTPoison.Error{id: nil, reason: :nxdomain}

with_mocks([
{
WhatsappApiRequest,
[],
[
post!: fn _, _, _ ->
raise error
end
]
}
]) do
providers = [
%{
name: "rtd-mx-test",
username: "username",
password: "password",
url: "https://wa.resuelve.test/v1"
},
%{
name: "rtd-es-test",
username: "user_es",
password: "pwd_ws",
url: "https://wa.es.resuelve.test:9090/v1"
}
]

{:ok, _pid} = Server.start_link()
:ok = Server.load_config(providers)

%{tokens: tokens} = Server.list_tokens() |> IO.inspect()

assert tokens.errors == [
{"rtd-es-test", inspect(error)},
{"rtd-mx-test", inspect(error)}
]
end
end
end

0 comments on commit 9e657fe

Please sign in to comment.