Printful HTTP client (v2 + v1 for sync products), Provider behaviour implementation with all callbacks (test_connection, fetch_products, submit_order, get_order_status, fetch_shipping_rates), and multi-provider order routing that looks up the provider connection from the order's product instead of hardcoding "printify". Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
49 lines
1.2 KiB
Elixir
49 lines
1.2 KiB
Elixir
defmodule SimpleshopTheme.Clients.PrintfulTest do
|
|
use ExUnit.Case, async: true
|
|
|
|
alias SimpleshopTheme.Clients.Printful
|
|
|
|
describe "api_token/0" do
|
|
test "reads from process dictionary when set" do
|
|
Process.put(:printful_api_key, "test_token_123")
|
|
|
|
assert Printful.api_token() == "test_token_123"
|
|
after
|
|
Process.delete(:printful_api_key)
|
|
end
|
|
|
|
test "raises when no token available" do
|
|
Process.delete(:printful_api_key)
|
|
_original = System.get_env("PRINTFUL_API_TOKEN")
|
|
System.delete_env("PRINTFUL_API_TOKEN")
|
|
|
|
assert_raise RuntimeError, ~r/PRINTFUL_API_TOKEN/, fn ->
|
|
Printful.api_token()
|
|
end
|
|
after
|
|
Process.delete(:printful_api_key)
|
|
# Restore env if it was set
|
|
case System.get_env("PRINTFUL_API_TOKEN") do
|
|
nil -> :ok
|
|
_ -> :ok
|
|
end
|
|
end
|
|
end
|
|
|
|
describe "store_id/0" do
|
|
test "reads from process dictionary" do
|
|
Process.put(:printful_store_id, 12345)
|
|
|
|
assert Printful.store_id() == 12345
|
|
after
|
|
Process.delete(:printful_store_id)
|
|
end
|
|
|
|
test "returns nil when not set" do
|
|
Process.delete(:printful_store_id)
|
|
|
|
assert Printful.store_id() == nil
|
|
end
|
|
end
|
|
end
|