fix(subscription): allow zero-day dev confirmation

This commit is contained in:
admin committed 2026-10-29 13:31:24 +02:00
1 parent dc2ec6344b
commit 60dc55a9b3
3 files changed
+16 -4

No files matched your search

+1 -1
View File
@@ -1 +1 @@
0.1.0+70
0.1.0+71
+4 -1
View File
@@ -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-оплата подтверждена.")
+11 -2
View File
@@ -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))