Skip to content

testing: use more the EventFactory to get rid of sync_timeline_event! and EventBuilder #3716

Open
@bnjbvr

Description

@bnjbvr

The EventBuilder struct/methods and sync_timeline_event! macros are used all over the place, but they're quite verbose and not the easier to use, when usually tests want simple things ("a plain text message with that content sent from this user") and don't care about low-level Matrix details.

So as to improve this, I've added an EventFactory struct that makes it easier to write such events, by chaining calls, and taking care of the fields that always need to be set (if necessary).

It would be great to fully get rid of EventBuilder and sync_timeline_event!, so we don't have three ways of defining test events, but a single one. I've started migrating in a few PRs, but I think this is a great way to get accointed with the code base by making relatively simple changes:

  • look at a use of EventBuilder or sync_timeline_event!
  • consider if it can be replaced by using an EventFactory instead
    • if yes, do the replacement
      • some tests do already have an EventFactory, often called factory, or a plain f in the code; reuse those if present, or follow that same naming convention for new uses.
    • if no: consider adding new methods/helpers to the EventFactory. This might be a bit more involved, so if you're chasing the good first issue part of this issue, then I'd recommend doing the plain replacements instead, aka the previous bullet item.

Metadata

Metadata

Assignees

No one assigned

    Labels

    good first issueGood for newcomershelp wantedInterested in working on the project? These are great additions we'd like to have!

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions