# `ExGram.Updates.Test`
[🔗](https://github.com/rockneurotiko/ex_gram/blob/0.65.0/lib/ex_gram/updates/test.ex#L1)

Updates implementation for testing purposes.

This GenServer implements the updates interface for test environments. Instead of
fetching updates from Telegram, it provides `push_update/2` to inject updates
directly into the bot's dispatcher.

The actual synchrony of handler execution depends on the bot's `handler_mode`:

  * `:sync` (default when using `ExGram.Test.start_bot/3`) - the handler runs
    inline within the dispatcher's process; `push_update/2` blocks until it completes.
  * `:async` (production default) - the handler is spawned; `push_update/2` returns
    before the handler runs.

Configured with `config :ex_gram, updates: ExGram.Updates.Test`.

See the [Testing guide](testing.md) for more details.

# `child_spec`

Returns a specification to start this module under a supervisor.

See `Supervisor`.

# `init`

# `push_update`

Push an update through the bot's `ExGram.Dispatcher` pipeline.

The update is delivered via `GenServer.call/2`, so the dispatcher always receives it
synchronously. Whether this call blocks until the handler finishes depends on the
bot's `handler_mode`:

  * `:sync` (default from `ExGram.Test.start_bot/3`) - the handler runs inline inside
    the dispatcher's `handle_call`, so this function returns only after the full
    pipeline has executed and all API calls have been made.
  * `:async` - the handler is spawned in a separate process; this function returns as
    soon as the dispatcher has enqueued the update.

Process isolation is handled automatically by `ExGram.Test.start_bot/3`, which allows
the Dispatcher and Updates worker to use the test's stubs from startup. No manual
`allow/2` call is needed before calling this function.

## Parameters

  * `bot_name` - The bot's registered name (atom), which is also the Dispatcher's name
  * `update` - An `t:ExGram.Model.Update.t/0` struct

## Example

    update = %ExGram.Model.Update{
      update_id: 1,
      message: %ExGram.Model.Message{...}
    }

    # With handler_mode: :sync (default), the handler has completed when this returns
    ExGram.Updates.Test.push_update(:my_bot, update)

# `start_link`

---

*Consult [api-reference.md](api-reference.md) for complete listing*
