File size: 3,725 Bytes
76be78d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
"""
Script to create test users for Plus and Pro tiers.
Run with: python3 create_test_users.py
"""
import os
import sys
from datetime import datetime
import hashlib
from dotenv import load_dotenv

load_dotenv()

# Add parent directory to path to import MongoDBService
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))

from services.mongodb_service import MongoDBService

def hash_password(password: str) -> str:
    """Hash password using SHA256 (matches backend login logic)"""
    return hashlib.sha256(password.encode()).hexdigest()

def create_test_users():
    """Create Plus and Pro test users"""
    try:
        mongodb = MongoDBService()
        
        # Test user credentials
        test_users = [
            {
                "email": "plus_tester@projectaegis.com",
                "plain_password": "PlusTester!123",
                "password": hash_password("PlusTester!123"),
                "name": "Plus Test User",
                "subscription_tier": "Pro",  # Maps to Plus tier
                "domain_preferences": ["Technology", "Science"],
                "phone_number": "+1234567890",
                "age": 25,
            },
            {
                "email": "pro_tester@projectaegis.com",
                "plain_password": "ProTester!123",
                "password": hash_password("ProTester!123"),
                "name": "Pro Test User",
                "subscription_tier": "Enterprise",  # Maps to Pro tier
                "domain_preferences": ["Technology", "Science", "Politics", "Health"],
                "phone_number": "+1234567891",
                "age": 30,
            }
        ]
        
        print("πŸ” Creating test users...")
        
        for user_data in test_users:
            email = user_data["email"]
            
            # Check if user already exists
            existing = mongodb.users.find_one({"email": email})
            if existing:
                print(f"⚠️  User {email} already exists. Updating subscription tier...")
                mongodb.update_user_subscription_tier(
                    str(existing["_id"]),
                    user_data["subscription_tier"]
                )
                print(f"βœ… Updated {email} to {user_data['subscription_tier']} tier")
            else:
                # Create new user - remove plain_password before inserting
                user_insert_data = {k: v for k, v in user_data.items() if k != "plain_password"}
                user_insert_data["created_at"] = datetime.utcnow()
                user_insert_data["updated_at"] = datetime.utcnow()
                
                result = mongodb.users.insert_one(user_insert_data)
                user_data["_id"] = str(result.inserted_id)
                user_data["id"] = str(result.inserted_id)
                
                print(f"βœ… Created {email} with tier: {user_data['subscription_tier']}")
        
        print("\nβœ… Test users created/updated successfully!")
        print("\nπŸ“‹ Login credentials:")
        print("=" * 60)
        for user_data in test_users:
            print(f"\nEmail: {user_data['email']}")
            print(f"Password: {user_data['plain_password']}")
            if user_data['subscription_tier'] == "Pro":
                print("Tier: Plus (subscription_tier: Pro)")
            elif user_data['subscription_tier'] == "Enterprise":
                print("Tier: Pro (subscription_tier: Enterprise)")
        print("=" * 60)
        
        mongodb.close()
        
    except Exception as e:
        print(f"❌ Error creating test users: {e}")
        import traceback
        traceback.print_exc()
        sys.exit(1)

if __name__ == "__main__":
    create_test_users()