From 60dc55a9b3b8124b74ae0b3cab4b72b6aec84b76 Mon Sep 17 00:00:00 2001 From: admin Date: Thu, 29 Oct 2026 13:31:24 +0200 Subject: [PATCH] fix(subscription): allow zero-day dev confirmation --- VERSION | 2 +- bot.py | 5 ++++- tests/test_payments.py | 13 +++++++++++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/VERSION b/VERSION index 83c5253..ca47100 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -0.1.0+70 +0.1.0+71 diff --git a/bot.py b/bot.py index 18cb917..a5a8945 100644 --- a/bot.py +++ b/bot.py @@ -422,9 +422,12 @@ async def confirm_development_payment(callback: CallbackQuery) -> None: if callback.from_user is None or callback.from_user.id != user_id: await callback.answer("Эта кнопка предназначена другому пользователю.", show_alert=True) return - if days <= 0: + if days < 0 or days not in user_store.SUBSCRIPTION_PLANS: await callback.answer("Неизвестный срок подписки.", show_alert=True) return + if days == 0: + await callback.answer("Dev-оплата подтверждена. Срок подписки не изменён.") + return await asyncio.to_thread(ensure_subscription, user_id) days_left = await asyncio.to_thread(user_store.activate_subscription_days, user_id, days) await callback.answer("Dev-оплата подтверждена.") diff --git a/tests/test_payments.py b/tests/test_payments.py index 05958f5..edd7b51 100644 --- a/tests/test_payments.py +++ b/tests/test_payments.py @@ -240,17 +240,26 @@ class SubscribeCommandTests(unittest.IsolatedAsyncioTestCase): self.assertEqual(markup.inline_keyboard[0][0].text, "🧪 Оплатил (dev, 10 дн.)") self.assertEqual(markup.inline_keyboard[0][0].callback_data, "dev_paid:42:10") - async def test_zero_day_plan_is_present_and_does_not_activate_in_dev_mode(self): + async def test_zero_day_dev_confirmation_is_accepted_without_activation(self): callback = AsyncMock() callback.data = "dev_paid:42:0" callback.from_user = SimpleNamespace(id=42) + callback.message = SimpleNamespace( + **Message( + message_id=1, + date=datetime.now(), + chat=Chat(id=555, type="private"), + ).model_dump(), + edit_reply_markup=AsyncMock(), + edit_text=AsyncMock(), + ) with ( patch.object(bot, "DEPLOY_ENV", "development"), patch.object(bot.asyncio, "to_thread", new=AsyncMock()) as to_thread, ): await bot.confirm_development_payment(callback) to_thread.assert_not_awaited() - callback.answer.assert_awaited_once_with("Неизвестный срок подписки.", show_alert=True) + callback.answer.assert_awaited_once_with("Dev-оплата подтверждена. Срок подписки не изменён.") async def test_zero_day_plan_is_a_one_star_invoice_without_access_grant(self): self.assertEqual(payments.plan_for_payload("sub:0:20261001120000"), (0, 1))