telega/testing/factory

Data factories for creating test instances of Telegram types.

All functions return deterministic default values, making tests reproducible and easy to write. Use _with variants for customization.

import telega/testing/factory

let update = factory.text_update("Hello")
let cmd = factory.command_update("start")

Values

pub fn audio() -> types.Audio

Creates an Audio with sensible defaults.

pub fn audio_message(audio audio: types.Audio) -> types.Message

Creates a message with audio attached.

pub fn audio_update() -> update.Update

Creates a typed AudioUpdate with default user/chat IDs.

pub fn audio_update_with(
  audio audio: types.Audio,
  from_id from_id: Int,
  chat_id chat_id: Int,
) -> update.Update

Creates a typed AudioUpdate with custom audio, from_id, and chat_id.

pub fn audio_with(
  file_id file_id: String,
  duration duration: Int,
) -> types.Audio

Creates an Audio with custom file_id and duration.

pub fn bot_user() -> types.User

Creates a bot user with sensible defaults.

pub fn callback_query_update(data data: String) -> update.Update

Creates a typed CallbackQueryUpdate with default user/chat IDs.

pub fn callback_query_update_with(
  data data: String,
  from_id from_id: Int,
  chat_id chat_id: Int,
) -> update.Update

Creates a typed CallbackQueryUpdate with custom from_id and chat_id.

pub fn chat() -> types.Chat

Creates a private chat with sensible defaults.

pub fn chat_with(id id: Int, type_ type_: String) -> types.Chat

Creates a chat with custom id and type.

pub fn command(command cmd: String) -> update.Command

Creates a Command record.

pub fn command_update(command cmd: String) -> update.Update

Creates a typed CommandUpdate with default user/chat IDs.

pub fn command_update_with(
  command cmd: String,
  payload payload: option.Option(String),
  from_id from_id: Int,
  chat_id chat_id: Int,
) -> update.Update

Creates a typed CommandUpdate with custom payload, from_id, and chat_id.

pub fn command_with(
  command cmd: String,
  payload payload: option.Option(String),
) -> update.Command

Creates a Command record with a payload.

pub fn message(text text: String) -> types.Message

Creates a message with the given text, using default user and chat.

pub fn message_update(
  message message: types.Message,
) -> update.Update

Creates a typed MessageUpdate with default user/chat IDs.

pub fn message_update_with(
  message message: types.Message,
  from_id from_id: Int,
  chat_id chat_id: Int,
) -> update.Update

Creates a typed MessageUpdate with custom from_id and chat_id.

pub fn message_with(
  text text: String,
  from from: types.User,
  chat chat: types.Chat,
) -> types.Message

Creates a message with custom text, from user, and chat.

pub fn photo_message(
  photos photos: List(types.PhotoSize),
) -> types.Message

Creates a message with photos attached.

pub fn photo_size() -> types.PhotoSize

Creates a PhotoSize with sensible defaults.

pub fn photo_size_with(
  file_id file_id: String,
) -> types.PhotoSize

Creates a PhotoSize with a custom file_id.

pub fn photo_update() -> update.Update

Creates a typed PhotoUpdate with default user/chat IDs.

pub fn photo_update_with(
  photos photos: List(types.PhotoSize),
  from_id from_id: Int,
  chat_id chat_id: Int,
) -> update.Update

Creates a typed PhotoUpdate with custom photos, from_id, and chat_id.

pub fn raw_update(message message: types.Message) -> types.Update

Creates a raw types.Update wrapping a message.

pub fn raw_update_with(
  message message: types.Message,
  update_id update_id: Int,
) -> types.Update

Creates a raw types.Update with custom update_id.

pub fn text_update(text text: String) -> update.Update

Creates a typed TextUpdate with default user/chat IDs.

pub fn text_update_with(
  text text: String,
  from_id from_id: Int,
  chat_id chat_id: Int,
) -> update.Update

Creates a typed TextUpdate with custom from_id and chat_id.

pub fn user() -> types.User

Creates a regular (non-bot) user with sensible defaults.

pub fn user_with(
  id id: Int,
  first_name first_name: String,
) -> types.User

Creates a user with custom id and first_name.

pub fn video() -> types.Video

Creates a Video with sensible defaults.

pub fn video_message(video video: types.Video) -> types.Message

Creates a message with a video attached.

pub fn video_update() -> update.Update

Creates a typed VideoUpdate with default user/chat IDs.

pub fn video_update_with(
  video video: types.Video,
  from_id from_id: Int,
  chat_id chat_id: Int,
) -> update.Update

Creates a typed VideoUpdate with custom video, from_id, and chat_id.

pub fn video_with(
  file_id file_id: String,
  duration duration: Int,
) -> types.Video

Creates a Video with custom file_id and duration.

pub fn voice() -> types.Voice

Creates a Voice with sensible defaults.

pub fn voice_message(voice voice: types.Voice) -> types.Message

Creates a message with a voice note attached.

pub fn voice_update() -> update.Update

Creates a typed VoiceUpdate with default user/chat IDs.

pub fn voice_update_with(
  voice voice: types.Voice,
  from_id from_id: Int,
  chat_id chat_id: Int,
) -> update.Update

Creates a typed VoiceUpdate with custom voice, from_id, and chat_id.

pub fn voice_with(
  file_id file_id: String,
  duration duration: Int,
) -> types.Voice

Creates a Voice with custom file_id and duration.

Search Document