add Printify client test coverage with Req.Test stubs
All checks were successful
deploy / deploy (push) Successful in 1m15s

Same pattern as the Printful work: wire up base_options/0 so tests can
inject a Req.Test plug, fix unreachable 204 clause in delete, add
HTTP-level client tests and provider integration tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
jamey
2026-02-22 10:35:24 +00:00
parent a45e85ef4c
commit b0aed4c1d6
4 changed files with 697 additions and 8 deletions

View File

@@ -26,7 +26,7 @@ defmodule Berrypod.Clients.Printify do
def get(path, _opts \\ []) do
url = @base_url <> path
case Req.get(url, headers: auth_headers(), receive_timeout: 30_000) do
case Req.get(url, [headers: auth_headers(), receive_timeout: 30_000] ++ base_options()) do
{:ok, %Req.Response{status: status, body: body}} when status in 200..299 ->
{:ok, body}
@@ -44,7 +44,10 @@ defmodule Berrypod.Clients.Printify do
def post(path, body, _opts \\ []) do
url = @base_url <> path
case Req.post(url, json: body, headers: auth_headers(), receive_timeout: 60_000) do
case Req.post(
url,
[json: body, headers: auth_headers(), receive_timeout: 60_000] ++ base_options()
) do
{:ok, %Req.Response{status: status, body: body}} when status in 200..299 ->
{:ok, body}
@@ -62,7 +65,10 @@ defmodule Berrypod.Clients.Printify do
def put(path, body, _opts \\ []) do
url = @base_url <> path
case Req.put(url, json: body, headers: auth_headers(), receive_timeout: 60_000) do
case Req.put(
url,
[json: body, headers: auth_headers(), receive_timeout: 60_000] ++ base_options()
) do
{:ok, %Req.Response{status: status, body: body}} when status in 200..299 ->
{:ok, body}
@@ -80,13 +86,13 @@ defmodule Berrypod.Clients.Printify do
def delete(path, _opts \\ []) do
url = @base_url <> path
case Req.delete(url, headers: auth_headers(), receive_timeout: 30_000) do
case Req.delete(url, [headers: auth_headers(), receive_timeout: 30_000] ++ base_options()) do
{:ok, %Req.Response{status: 204}} ->
{:ok, nil}
{:ok, %Req.Response{status: status, body: body}} when status in 200..299 ->
{:ok, body}
{:ok, %Req.Response{status: status}} when status == 204 ->
{:ok, nil}
{:ok, %Req.Response{status: status, body: body}} ->
{:error, {status, body}}
@@ -267,4 +273,8 @@ defmodule Berrypod.Clients.Printify do
{"Content-Type", "application/json"}
]
end
defp base_options do
Application.get_env(:berrypod, __MODULE__, [])[:req_options] || []
end
end