import asyncio
import sys
sys.path.insert(0, ".")

async def test_login():
    # Simulate what the login route does
    from common.sqlite_client import sqlite_client as db
    from common.sqlite_client import init_sqlite
    from common.jwt_auth import verify_password, create_access_token, create_refresh_token
    
    await init_sqlite()
    
    username = "e2etest"
    password = "Test12345!"
    
    user = await db.fetch_one(
        "SELECT * FROM cuccu_users WHERE username = ?", (username,)
    )
    if not user:
        print("ERROR: User not found")
        return
    
    print("User found:", dict(user))
    
    result = verify_password(password, user["password_hash"])
    print("verify_password result:", result)
    
    if result:
        user_id = str(user["id"])
        access_token = create_access_token(data={"sub": user_id})
        print("access_token created OK:", access_token[:30], "...")

asyncio.run(test_login())
