TypeSafeSDK.Test (TypeSafeSDK v0.4.0)

Copy Markdown View Source

Explicit, isolated application fixtures at the Pristine transport seam.

These helpers do not replace serialization, retry classification, decoding or semantic validation. The configured transport can never call the live API. A scenario monitors its creating process and can be shared explicitly with child tasks. Call verify!/1 before the owner exits, and close/1 when done.

client = TypeSafeSDK.Test.client()
client = TypeSafeSDK.Test.stub(client, urgent: {:noul, 0.9})
result = TypeSafeSDK.evaluate!(client, "synthetic example", urgent: TypeSafeSDK.noul("Urgent?"))
TypeSafeSDK.Test.verify!(client)
TypeSafeSDK.Test.close(client)

Default retries are disabled. Enable the real retry policy explicitly when using stub_sequence/2. Request history is bounded (default 1000) and contains the actual serialized request; use synthetic data and test credentials only.

Summary

Functions

Build a fixture from the actual request, for state-dependent or synchronized application tests.

Raw response escape hatch for testing malformed or future response contracts.

Finite request/attempt sequence. Exhaustion fails; verify!/1 checks consumption.

Functions

client(opts \\ [])

@spec client(keyword()) :: TypeSafeSDK.Client.t()

close(client)

@spec close(TypeSafeSDK.Client.t()) :: :ok

requests(client)

@spec requests(TypeSafeSDK.Client.t()) :: list()

stats(client)

@spec stats(TypeSafeSDK.Client.t()) :: map()

stub(client, answers, opts \\ [])

stub_callback(client, fun)

Build a fixture from the actual request, for state-dependent or synchronized application tests.

stub_http_error(client, status, opts \\ [])

@spec stub_http_error(TypeSafeSDK.Client.t(), integer(), keyword()) ::
  TypeSafeSDK.Client.t()

stub_models(client, models, opts \\ [])

@spec stub_models(TypeSafeSDK.Client.t(), list(), keyword()) :: TypeSafeSDK.Client.t()

stub_response(client, body, opts \\ [])

Raw response escape hatch for testing malformed or future response contracts.

stub_sequence(client, fixtures)

@spec stub_sequence(TypeSafeSDK.Client.t(), list()) :: TypeSafeSDK.Client.t()

Finite request/attempt sequence. Exhaustion fails; verify!/1 checks consumption.

Entries: {:answers, specs, opts}, {:models, models, opts}, {:http_error, status, opts}, {:transport_error, reason}, {:response, raw_body, opts}. The first, second, third and fifth accept omitted opts.

stub_transport_error(client, reason)

@spec stub_transport_error(TypeSafeSDK.Client.t(), term()) :: TypeSafeSDK.Client.t()

verify!(client)

@spec verify!(TypeSafeSDK.Client.t()) :: :ok