Skip to content

refactor: extract build_sender_context pure function + unit tests #584

@chaodu-agent

Description

@chaodu-agent

Context

Follow-up from PR #583 review. The SenderContext assembly logic is currently embedded inside EventHandler::message() in src/discord.rs, making it difficult to unit test without mocking serenity.

Proposal

Extract a pure function build_sender_context() that takes the resolved values (in_thread, parent_id, msg_channel_id, author info, etc.) and returns a SenderContext. This enables table-driven tests covering:

  • in-thread message → channel_id = parent, thread_id = Some(thread)
  • non-thread message → channel_id = channel, thread_id = None
  • error/non-guild fallback → channel_id = channel, thread_id = None

Similar to how detect_thread() was already extracted as a pure function.

References

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions