#!/usr/bin/env python3 """Manual test script for danding_points plugin.""" import asyncio import sys from pathlib import Path # Add project root to path sys.path.insert(0, str(Path(__file__).parent.parent.parent)) from danding_bot.plugins.danding_points import points_api async def test_basic_operations(): """Test basic points operations.""" print("Testing basic operations...") # Test 1: Get balance for non-existent user balance = await points_api.get_balance("test_user_1") assert balance == 0, f"Expected 0, got {balance}" print("✓ Non-existent user returns 0 balance") # Test 2: Add points (auto-create user) success, new_balance = await points_api.add_points( "test_user_1", 100, "test_source", "test reason" ) assert success and new_balance == 100, f"Add failed: {success}, {new_balance}" print("✓ Add points works and auto-creates user") # Test 3: Get balance after add balance = await points_api.get_balance("test_user_1") assert balance == 100, f"Expected 100, got {balance}" print("✓ Balance updated correctly") # Test 4: Spend points success, new_balance = await points_api.spend_points( "test_user_1", 30, "test_source", "spend reason" ) assert success and new_balance == 70, f"Spend failed: {success}, {new_balance}" print("✓ Spend points works") # Test 5: Spend more than balance (should fail) success, new_balance = await points_api.spend_points( "test_user_1", 100, "test_source", "should fail" ) assert not success, "Should fail when spending more than balance" print("✓ Spend fails when insufficient balance") # Test 6: Set points success, new_balance = await points_api.set_points( "test_user_1", 50, "test_source", "set reason" ) assert success and new_balance == 50, f"Set failed: {success}, {new_balance}" print("✓ Set points works") # Test 7: Get transactions transactions = await points_api.get_transactions("test_user_1", limit=10) assert len(transactions) > 0, "Should have transactions" print(f"✓ Get transactions works ({len(transactions)} transactions)") # Test 8: Get ranking ranking = await points_api.get_ranking(limit=10) assert len(ranking) > 0, "Should have ranking entries" assert "rank" in ranking[0], "Ranking should have rank field" print(f"✓ Get ranking works ({len(ranking)} entries)") print("\n✅ All tests passed!") if __name__ == "__main__": asyncio.run(test_basic_operations())