IbkrApi.Support.HTTPMock (ibkr_api v1.0.3)

View Source

Helper functions for creating mock HTTP responses.

This module provides functions for creating standard response formats for success responses, error responses, and network errors.

Summary

Functions

Creates an error HTTP response.

Creates a network error response.

Creates a successful HTTP response.

Functions

error(error_body, status \\ 400, headers \\ [])

Creates an error HTTP response.

Parameters

  • error_body: The error response body (map)
  • status: HTTP status code (default: 400)
  • headers: Response headers (default: [])

Examples

HTTPMock.error(%{"error" => "Invalid request"}, 400)
# Returns: {:error, %Response{status: 400, body: %{"error" => "Invalid request"}}}

network_error(reason)

Creates a network error response.

Parameters

  • reason: The error reason (:timeout, :closed, etc.)

Examples

HTTPMock.network_error(:timeout)
# Returns: {:error, :timeout}

success(body, status \\ 200, headers \\ [])

Creates a successful HTTP response.

Parameters

  • body: The response body (map or list)
  • status: HTTP status code (default: 200)
  • headers: Response headers (default: [])

Examples

HTTPMock.success(%{"id" => 1, "name" => "Item"})
# Returns: {:ok, {%{"id" => 1, "name" => "Item"}, %Response{status: 200}}}