Skip to content

Commit

Permalink
[#27] fixing test coverage in config and httpoison_adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
flaviogranero committed May 19, 2016
1 parent f984c65 commit f5ba767
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
11 changes: 11 additions & 0 deletions test/lib/dayron/adapters/httpoison_adapter_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,17 @@ defmodule Dayron.HTTPoisonAdapterTest do
assert body == %{}
end

test "handles invalid json body", %{bypass: bypass, api_url: api_url} do
Bypass.expect bypass, fn conn ->
assert "/resources/id" == conn.request_path
assert "GET" == conn.method
Plug.Conn.resp(conn, 200, "{invalid_json=1}")
end
response = HTTPoisonAdapter.get("#{api_url}/resources/id")
assert {:ok, %Dayron.Response{status_code: 200, body: body}} = response
assert body == "{invalid_json=1}"
end

test "returns a decoded body for a response list", %{bypass: bypass, api_url: api_url} do
Bypass.expect bypass, fn conn ->
assert "/resources" == conn.request_path
Expand Down
7 changes: 7 additions & 0 deletions test/lib/dayron/config_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,13 @@ defmodule Dayron.ConfigTest do
assert config[:headers] == [access_token: "token"]
end

test "raises an exception if no config is present" do
msg = "configuration for Dayron.Repo not specified in :invalid_app environment"
assert_raise ArgumentError, msg, fn ->
Config.get(Dayron.Repo, :invalid_app)
end
end

test "raises an exception if url is missing in config" do
Application.put_env(:dayron_test, Dayron.Repo, [])
msg = "missing :url configuration in config :dayron_test, Dayron.Repo"
Expand Down

0 comments on commit f5ba767

Please sign in to comment.