CampaignFlow.MockServer (CampaignFlow Client v2.2.0)

View Source

Mock Campaign Flow server for development and testing.

This module provides a mock implementation of the Campaign Flow API that can run embedded in your application. It's useful for:

  • Local development without API credentials
  • Integration testing without hitting the real API
  • End-to-end testing of referral workflows

Configuration

Add to your config files:

# config/test.exs
config :campaign_flow, :mock_server,
  enabled: true,
  repo: MyApp.Repo

Migrations

Generate a migration in your application:

mix ecto.gen.migration add_campaign_flow_mock_server

Then call the migration functions:

defmodule MyApp.Repo.Migrations.AddCampaignFlowMockServer do
  use Ecto.Migration

  def up, do: CampaignFlow.MockServer.Migrations.up(version: 1)
  def down, do: CampaignFlow.MockServer.Migrations.down(version: 1)
end

Embedded Mode (Phoenix Integration)

Mount the mock server router in your Phoenix router:

# In your Phoenix router
forward "/campaign-flow-mock", CampaignFlow.MockServer.Router

Configure your Campaign Flow client to use your Phoenix URL:

config :campaign_flow,
  environments: [
    mock: [
      base_url: "http://localhost:4000/campaign-flow-mock/api/v2",
      client_id: "test_key",
      client_secret: "test_secret"
    ]
  ]

Summary

Functions

Returns the configured base URL for the mock server.

Returns the child spec for starting the mock server under a supervisor.

Clears all mock server state.

Returns all stored webhook events, newest first.

Sets the status of a mock campaign and enqueues a campaign_status_change webhook for delivery.

Starts the mock server.

Functions

base_url()

@spec base_url() :: String.t()

Returns the configured base URL for the mock server.

child_spec(opts \\ [])

Returns the child spec for starting the mock server under a supervisor.

clear_all()

Clears all mock server state.

Useful for resetting state between tests.

list_webhook_events()

Returns all stored webhook events, newest first.

See CampaignFlow.MockServer.Test.list_webhook_events/0.

set_campaign_status(campaign_id, new_status)

Sets the status of a mock campaign and enqueues a campaign_status_change webhook for delivery.

See CampaignFlow.MockServer.Test.set_campaign_status/2.

start_link(opts \\ [])

Starts the mock server.

Returns :ignore if the mock server is not enabled in config.