From fbc6adadb912409f135935dedbe7203917817ddb Mon Sep 17 00:00:00 2001 From: Luca Patera Date: Wed, 17 Jul 2024 00:34:41 +0200 Subject: [PATCH] Fix tests --- tests/Feature/CommandsTest.php | 10 +- .../Conversations/DonateConversationTest.php | 112 ++---------------- 2 files changed, 19 insertions(+), 103 deletions(-) diff --git a/tests/Feature/CommandsTest.php b/tests/Feature/CommandsTest.php index 1035f0c..2847ad0 100644 --- a/tests/Feature/CommandsTest.php +++ b/tests/Feature/CommandsTest.php @@ -50,6 +50,14 @@ 'year' => 0, 'total' => 0, ], + 'videos_optimized' => [ + 'yesterday' => 0, + 'today' => 0, + 'week' => 0, + 'month' => 0, + 'year' => 0, + 'total' => 0, + ], 'active_users' => [ 'yesterday' => 0, 'today' => 0, @@ -74,7 +82,7 @@ ->hearText('/stats') ->reply() ->assertReplyText(message('stats.template', [ - 'title' => __('stats.category.optimized'), + 'title' => __('stats.category.optimized.stickers'), ...$stats['stickers_optimized'], 'lastUpdate' => $stats['last_update'], ])); diff --git a/tests/Feature/Conversations/DonateConversationTest.php b/tests/Feature/Conversations/DonateConversationTest.php index 4ef1a23..0387c17 100644 --- a/tests/Feature/Conversations/DonateConversationTest.php +++ b/tests/Feature/Conversations/DonateConversationTest.php @@ -6,27 +6,12 @@ use SergiX44\Nutgram\Telegram\Types\Keyboard\InlineKeyboardMarkup; beforeEach(function () { - $keyboard = InlineKeyboardMarkup::make() - ->addRow(InlineKeyboardButton::make('Telegram Payment', callback_data: 'donate.telegram')); - - foreach (config('donation.third_party_providers.url') as $service => $value) { - $keyboard->addRow(InlineKeyboardButton::make($service, url: $value)); - } - - foreach (config('donation.third_party_providers.text') as $service => $value) { - $keyboard->addRow(InlineKeyboardButton::make($service, - callback_data: $service)); - } - - $keyboard->addRow(InlineKeyboardButton::make('❌ '.trans('common.close'), callback_data: 'donate.cancel')); - $this->test = bot() ->willStartConversation() ->hearText('/donate') ->reply() ->assertReplyMessage([ - 'text' => message('donate.menu'), - 'reply_markup' => $keyboard, + 'text' => message('donate.main'), ]) ->assertActiveConversation(); @@ -39,102 +24,25 @@ $this->test; }); -it('clicks on Telegram Payment button + it generates donation invoice', function () { - $value = '1'; - +it('get amount', function () { $this->test - ->hearCallbackQueryData('donate.telegram') + ->hearText('93') ->reply() - ->assertReplyMessage([ - 'text' => message('donate.telegram'), - 'reply_markup' => InlineKeyboardMarkup::make() - ->addRow( - InlineKeyboardButton::make('1$', callback_data: '1'), - InlineKeyboardButton::make('5$', callback_data: '5'), - InlineKeyboardButton::make('10$', callback_data: '10'), - InlineKeyboardButton::make('25$', callback_data: '25'), - InlineKeyboardButton::make('50$', callback_data: '50'), - InlineKeyboardButton::make('100$', callback_data: '100') - ) - ->addRow(InlineKeyboardButton::make('🔙 '.trans('common.back'), - callback_data: 'donate.telegram.back')), - ]) - ->assertReply('answerCallbackQuery', index: 1) - ->hearCallbackQueryData($value) - ->reply() - ->assertReplyMessage([ - 'title' => trans('donate.donation'), - 'description' => trans('donate.support_by_donating'), - 'payload' => 'donation', - 'provider_token' => config('donation.provider_token'), - 'currency' => 'USD', - 'prices' => json_encode([['label' => "{$value}$", 'amount' => $value * 100]]), - ], 0, 'sendInvoice') - ->assertReply('deleteMessage', index: 1) - ->assertReply('answerCallbackQuery', index: 2); + ->assertReply('sendInvoice') + ->assertNoConversation(); - $this->assertDatabaseHas('statistics', [ - 'action' => 'donate.telegram', - ]); $this->assertDatabaseHas('statistics', [ 'action' => 'donate.invoice', - 'value' => json_encode(['value' => (int)$value]), + 'value' => json_encode(['value' => 93]), ]); }); -it('donates via donation invoice', function () { - bot() - ->hearUpdateType(UpdateType::PRE_CHECKOUT_QUERY) - ->reply() - ->assertReply('answerPreCheckoutQuery') - ->clearCache() - ->hearMessage(['successful_payment' => []]) - ->reply() - ->assertReplyText(__('donate.thanks')); - - $this->assertDatabaseHas('statistics', [ - 'action' => 'donate.precheckout', - ]); - - $this->assertDatabaseHas('statistics', [ - 'action' => 'donate.success', - ]); -}); - -it('clicks on a third-party donation button', function () { - $providerKey = array_key_first(config('donation.third_party_providers.text')); - $providerValue = Arr::first(config('donation.third_party_providers.text')); - - ImageUtils::shouldReceive('qrcode')->andReturn(fopen('php://temp', 'rb')); - +it('get invalid amount', function () { $this->test - ->hearCallbackQueryData($providerKey) + ->hearText('foo') ->reply() - ->assertReplyMessage([ - 'caption' => message('donate.third', [ - 'service' => $providerKey, - 'text' => $providerValue, - ]), - ], 0, 'sendPhoto') - ->assertReply('deleteMessage', index: 1) - ->assertReply('answerCallbackQuery', index: 2); - - $this->assertDatabaseHas('statistics', [ - 'action' => 'donate.third', - 'value' => json_encode(['service' => $providerKey]), - ]); -}); - -it('closes donate menu', function () { - $this->test - ->hearCallbackQueryData('donate.cancel') - ->reply() - ->assertReply('deleteMessage') - ->assertReply('answerCallbackQuery', index: 1); - - $this->assertDatabaseHas('statistics', [ - 'action' => 'donate.cancel', - ]); + ->assertReplyText(message('donate.invalid')) + ->assertActiveConversation(); });