telega/testing/context
Context and config builders for testing.
Provides functions to create bot.Context, config.Config,
and bot.SessionSettings with sensible test defaults.
import telega/testing/context
import telega/testing/factory
let ctx = context.context(session: MySession(count: 0))
let cfg = context.config()
Values
pub fn catch_handler() -> fn(
bot.Context(session, error, dependencies),
error,
) -> Result(Nil, error)
Creates a no-op catch handler.
pub fn config_with_client(
client: client.TelegramClient,
) -> @internal Config
Creates a test Config with the given Telegram client.
Use this with mock.message_client() to get a config that returns valid API responses.
pub fn context(
session session: session,
) -> bot.Context(session, error, Nil)
Creates a Context with the given session and default update/config.
dependencies defaults to Nil. To inject mock services, use context_with_dependencies
(or context_with_all).
pub fn context_with(
session session: session,
update update: update.Update,
) -> bot.Context(session, error, Nil)
Creates a Context with the given session and update. dependencies defaults to Nil.
pub fn context_with_all(
session session: session,
update update: update.Update,
key key: String,
bot_info bot_info: types.User,
dependencies dependencies: dependencies,
) -> bot.Context(session, error, dependencies)
Creates a Context with full customization, including injected dependencies.
pub fn context_with_dependencies(
session session: session,
dependencies dependencies: dependencies,
) -> bot.Context(session, error, dependencies)
Creates a Context with the given session and mock dependencies (services).
Use this to substitute mocked services in handler tests:
context.context_with_dependencies(session: MySession(..), dependencies: MockDependencies(db:, http:)).
pub fn session_settings(
default default: fn() -> session,
) -> bot.SessionSettings(session, error)
Creates SessionSettings with a no-op persist and get returning None.
pub fn session_settings_with(
default default: fn() -> session,
initial initial: session,
) -> bot.SessionSettings(session, error)
Creates SessionSettings where get returns Some(initial).