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

Wire up Req.Test plug for the Printful HTTP client so tests can stub
responses. Adds HTTP-level tests for the client, provider integration
tests, and mockup enricher tests.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
jamey
2026-02-22 10:20:49 +00:00
parent f1b4e55cc7
commit a45e85ef4c
5 changed files with 1023 additions and 6 deletions

View File

@@ -41,7 +41,7 @@ defmodule Berrypod.Clients.Printful 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, unwrap_response(path, body)}
@@ -59,7 +59,10 @@ defmodule Berrypod.Clients.Printful 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, unwrap_response(path, body)}
@@ -77,13 +80,13 @@ defmodule Berrypod.Clients.Printful do
def delete(path, _opts \\ []) do
url = @base_url <> path
case Req.delete(url, headers: auth_headers(), receive_timeout: 30_000) do
{:ok, %Req.Response{status: status, body: body}} when status in 200..299 ->
{:ok, unwrap_response(path, body)}
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, unwrap_response(path, body)}
{:ok, %Req.Response{status: status, body: body}} ->
{:error, {status, body}}
@@ -362,4 +365,8 @@ defmodule Berrypod.Clients.Printful do
id -> [{"X-PF-Store-Id", to_string(id)} | headers]
end
end
defp base_options do
Application.get_env(:berrypod, __MODULE__, [])[:req_options] || []
end
end