Skip to content

Commit

Permalink
Set fixture Content-Type based on extension
Browse files Browse the repository at this point in the history
  • Loading branch information
lnikkila committed Mar 13, 2017
1 parent e3b714c commit 345b361
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions test/support/api_case.ex
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,27 @@ defmodule ExQuickBooks.APICase do
end

def load_response(file) do
body =
"test/fixtures/#{file}"
|> File.read!
|> String.strip

content_type =
file
|> String.split(".")
|> List.last
|> type_for_extension

%Response{
body: "test/fixtures/#{file}" |> File.read! |> String.strip,
headers: [],
body: body,
headers: [{"Content-Type", content_type}],
status_code: 200
}
end

defdelegate take_request, to: MockBackend
defdelegate send_response(response), to: MockBackend

defp type_for_extension("json"), do: "application/json"
defp type_for_extension(_), do: "text/plain"
end

0 comments on commit 345b361

Please sign in to comment.