Do you write tests for your bots? Then how? #1064
Answered
by
jonnywilliamson
pavel-mironchik
asked this question in
Q&A
|
Hello. I'm wondering if you write tests for your bots. For example, to be sure that a command works as expected. I've tried but without a success. There are 2 things I've stumbled upon:
Will appreciate your tests examples. I use a typical approach to handle commands: P.S. related issues without answers: |
Answered by
jonnywilliamson
Apr 17, 2023
Replies: 1 comment
|
In case this is some help for you. I'm still at the begining of my testing learning career, and starting with PEST so what I'm doing might not be proper. But in general, I've found I can test what gets sent to my bot for delivery to a user. Here's an example of one of my tests at the moment. it('should notify admin if retrieving a flight duty statistics fails', function () {
$user = User::factory()->create(['telegram_id' => 987654321]);
$botMock = Mockery::mock(Bot::class)->expects('sendMessage')->with(Mockery::capture($params))->getMock();
Telegram::shouldReceive(['bot' => $botMock]);
//Doing some action that will send a message or photo or whatever at some stage during the process that I want to check
//has the right info.
$results = app(FlightTimeStatisticsAction::class)->for($user);
expect($results)->toHaveCount(0);
expect($results)->toBeInstanceOf(Collection::class);
expect($params['chat_id'])->toBe(987654321);
expect($params['text'])->toContain('Unable to parse flight/duty time statistics');
});Also bare in mind that I'm using the newer v4 (not fully released) version of the sdk and don't use any previous versions any more. |
0 replies
Answer selected by
pavel-mironchik
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In case this is some help for you.
I'm still at the begining of my testing learning career, and starting with PEST so what I'm doing might not be proper. But in general, I've found I can test what gets sent to my bot for delivery to a user.
Here's an example of one of my tests at the moment.