|
6 | 6 | router as add_wallet_router, |
7 | 7 | StateAddWallet, |
8 | 8 | ) |
| 9 | +from routers.sign import PinState |
9 | 10 | from tests.conftest import ( |
10 | 11 | RouterTestMiddleware, |
11 | 12 | create_callback_update, |
@@ -306,3 +307,60 @@ async def test_add_wallet_no_password_persists_pin_type_zero( |
306 | 307 | pin_type=0, |
307 | 308 | ) |
308 | 309 | assert setup_add_wallet_mocks.change_password_uc.execute.await_count == 1 |
| 310 | + |
| 311 | + |
| 312 | +@pytest.mark.asyncio |
| 313 | +async def test_add_wallet_password_sets_password_state( |
| 314 | + mock_telegram, router_app_context, setup_add_wallet_mocks |
| 315 | +): |
| 316 | + """Selecting Password should move flow to password setup state.""" |
| 317 | + dp = router_app_context.dispatcher |
| 318 | + dp.callback_query.middleware(RouterTestMiddleware(router_app_context)) |
| 319 | + dp.include_router(add_wallet_router) |
| 320 | + |
| 321 | + user_id = 123 |
| 322 | + state_key = StorageKey( |
| 323 | + bot_id=router_app_context.bot.id, chat_id=user_id, user_id=user_id |
| 324 | + ) |
| 325 | + |
| 326 | + await dp.feed_update( |
| 327 | + router_app_context.bot, create_callback_update(user_id, "Password") |
| 328 | + ) |
| 329 | + |
| 330 | + assert await dp.storage.get_state(state_key) == PinState.ask_password_set |
| 331 | + data = await dp.storage.get_data(state_key) |
| 332 | + assert data.get("pin_type") == 2 |
| 333 | + |
| 334 | + req = get_latest_msg(mock_telegram) |
| 335 | + if req is None: |
| 336 | + raise AssertionError("Expected send message for password prompt") |
| 337 | + assert "send_password" in req["data"]["text"] |
| 338 | + |
| 339 | + |
| 340 | +@pytest.mark.asyncio |
| 341 | +async def test_add_wallet_pin_sets_pin_state( |
| 342 | + mock_telegram, router_app_context, setup_add_wallet_mocks |
| 343 | +): |
| 344 | + """Selecting PIN should move flow to PIN setup state.""" |
| 345 | + dp = router_app_context.dispatcher |
| 346 | + dp.callback_query.middleware(RouterTestMiddleware(router_app_context)) |
| 347 | + dp.include_router(add_wallet_router) |
| 348 | + |
| 349 | + user_id = 123 |
| 350 | + state_key = StorageKey( |
| 351 | + bot_id=router_app_context.bot.id, chat_id=user_id, user_id=user_id |
| 352 | + ) |
| 353 | + router_app_context.stellar_service.get_user_account = AsyncMock( |
| 354 | + return_value=MagicMock( |
| 355 | + account=MagicMock( |
| 356 | + account_id="GDLTH4KKMA4R2JGKA7XKI5DLHJBUT42D5RHVK6SS6YHZZLHVLCWJAYXI" |
| 357 | + ) |
| 358 | + ) |
| 359 | + ) |
| 360 | + await dp.storage.set_data(state_key, {"user_lang": "en"}) |
| 361 | + |
| 362 | + await dp.feed_update(router_app_context.bot, create_callback_update(user_id, "PIN")) |
| 363 | + |
| 364 | + assert await dp.storage.get_state(state_key) == PinState.set_pin |
| 365 | + data = await dp.storage.get_data(state_key) |
| 366 | + assert data.get("pin_type") == 1 |
0 commit comments