Framework.Test.MockWebhookService (Framework v0.5.0)

View Source

Mock webhook service for testing retry scenarios and uniqueness verification.

This GenServer tracks webhook calls by idempotency key to prove that duplicate requests/retries result in single external calls.

Features

  • Track calls by Idempotency-Key header
  • Simulate different HTTP status codes (2xx, 4xx, 5xx)
  • Count attempts vs successful outcomes per idempotency key
  • Reset state for clean test runs
  • Query call history for verification

Architecture

This service only tracks webhook calls. Bypass HTTP server setup is handled in test setup to maintain ExUnit/Bypass compatibility.

Summary

Functions

Returns a specification to start this module under a supervisor.

Configure a webhook endpoint to return specific status codes.

Get all idempotency keys that have been called.

Get call history for a specific idempotency key. Returns: %{attempts: count, successful_outcomes: count, last_status: integer}

Helper function for Bypass test setup. Extracts header value from connection.

Helper function for Bypass test setup. Extracts webhook name from request path.

Reset all call tracking - useful for clean test runs.

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

configure_response(webhook_name, opts)

Configure a webhook endpoint to return specific status codes.

Examples: configure_response("user.created", status: 200) configure_response("billing.charge", status: 500, attempts: 3) configure_response("notifications.send", status: 422)

get_all_idempotency_keys()

Get all idempotency keys that have been called.

get_call_history(idempotency_key)

Get call history for a specific idempotency key. Returns: %{attempts: count, successful_outcomes: count, last_status: integer}

get_header(conn, header_name)

Helper function for Bypass test setup. Extracts header value from connection.

get_webhook_name_from_path(arg1)

Helper function for Bypass test setup. Extracts webhook name from request path.

reset()

Reset all call tracking - useful for clean test runs.

start_link(opts \\ [])