From 289deaedfda65c250012a92c52ae6a59e6bd96c0 Mon Sep 17 00:00:00 2001 From: Yordis Prieto Date: Wed, 6 Nov 2024 11:41:54 -0500 Subject: [PATCH] chore: add partial_env to test module --- lib/tesla/test.ex | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/tesla/test.ex b/lib/tesla/test.ex index e23463e5..44cd34a0 100644 --- a/lib/tesla/test.ex +++ b/lib/tesla/test.ex @@ -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 """ @@ -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 """ @@ -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 """ @@ -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