Skip to content

Commit

Permalink
Add an api test for invalid json
Browse files Browse the repository at this point in the history
If a client has a malformed response it's treated like all other fatal errors
and a default move is chosen.
  • Loading branch information
Dylan Kendal committed Jan 17, 2017
1 parent be8a157 commit ad85d30
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions test/battle_snake/api_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,17 @@ defmodule BattleSnake.ApiTest do
assert move == {:ok, %Move{move: "up"}}
end

test "on parsing error returns the error" do
body = "{"

mock = fn (@move_url, _, _, _) ->
{:ok, %HTTPoison.Response{body: body}}
end

assert({:error, :invalid} ==
BattleSnake.Api.move(@snake, @world, mock))
end

test "on error returns the error" do
mock = fn (@move_url, _, _, _) ->
{:error, %HTTPoison.Error{}}
Expand Down

0 comments on commit ad85d30

Please sign in to comment.