Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add test Context class for testing middlewares #712

Closed
freak12techno opened this issue Jul 6, 2024 · 2 comments
Closed

Add test Context class for testing middlewares #712

freak12techno opened this issue Jul 6, 2024 · 2 comments

Comments

@freak12techno
Copy link

I use telebot in a few of my apps, and I have a bunch of functions similar to these I want to test:

func (reporter *Reporter) HandleHelp(c tele.Context) error {

So I want to construct tele.Context instance to pass it as an argument, however nativeContext is not exporter, and to implement tele.Context I need to create a new struct that would implement all of these methods (more than 20).
Would be lovely if telebot would include some implementation of tele.Context that can be used in tests, that would not do any real requests but would return some data that might be configurable.
Something like this would be ideal:

ctx := tele.TestContext{
    Sender: { Username: "test" },
    Reply: { Error: errors.New("some error"),
}
reporter.HandleHelp(ctx)
// add some asserts that it actually worked correctly

Also pretty sure this might be handy in using the telebot itself.

@freak12techno
Copy link
Author

@demget do you mind if I add this by making a PR?

@freak12techno
Copy link
Author

Nevermind, I figured it out, you can just call bot.NewContext(tele.Update{}) to generate it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant