Skip to content

Commit

Permalink
fix: dialyzer typespec issue with partial env (#727)
Browse files Browse the repository at this point in the history
chore: add partial_env to test module
  • Loading branch information
yordis authored Nov 6, 2024
1 parent dd9f0a1 commit 0b79b0c
Showing 1 changed file with 18 additions and 6 deletions.
24 changes: 18 additions & 6 deletions lib/tesla/test.ex
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,8 @@ defmodule Tesla.Test do
@spec html(%Tesla.Env{}, binary) :: %Tesla.Env{}
def html(%Tesla.Env{} = env, body) when is_binary(body) do
env
|> Tesla.put_body(body)
|> Tesla.put_headers([{"content-type", "text/html; charset=utf-8"}])
|> put_body(body)
|> put_headers([{"content-type", "text/html; charset=utf-8"}])
end

@doc """
Expand All @@ -91,8 +91,8 @@ defmodule Tesla.Test do
body = encode!(body, "application/json")

env
|> Tesla.put_body(body)
|> Tesla.put_headers([{"content-type", "application/json; charset=utf-8"}])
|> put_body(body)
|> put_headers([{"content-type", "application/json; charset=utf-8"}])
end

@doc """
Expand All @@ -108,8 +108,8 @@ defmodule Tesla.Test do
@spec text(%Tesla.Env{}, binary) :: %Tesla.Env{}
def text(%Tesla.Env{} = env, body) when is_binary(body) do
env
|> Tesla.put_body(body)
|> Tesla.put_headers([{"content-type", "text/plain; charset=utf-8"}])
|> put_body(body)
|> put_headers([{"content-type", "text/plain; charset=utf-8"}])
end

@doc """
Expand Down Expand Up @@ -271,4 +271,16 @@ defmodule Tesla.Test do
adapter
end
end

defp put_body(%Tesla.Env{} = env, body) do
%{env | body: body}
end

defp put_headers(%Tesla.Env{headers: nil} = env, headers) when is_list(headers) do
%{env | headers: headers}
end

defp put_headers(%Tesla.Env{} = env, headers) when is_list(headers) do
%{env | headers: env.headers ++ headers}
end
end

0 comments on commit 0b79b0c

Please sign in to comment.