diff --git a/signin_test.py b/signin_test.py new file mode 100644 index 00000000..266474c7 --- /dev/null +++ b/signin_test.py @@ -0,0 +1,96 @@ +#!/usr/bin/env python3 +""" +Test signin and profile retrieval with existing user +""" + +import requests +import json + +BACKEND_URL = "https://digital-kurdistan.preview.emergentagent.com/api" + +def test_existing_user_signin(): + """Test signin with existing user from logs""" + print("šŸ” Testing Signin with Existing User") + print(f"Backend URL: {BACKEND_URL}") + print("=" * 60) + + # Use the email from successful signup in logs + test_email = "test1b42307a@gmail.com" + test_password = "TestPassword123!" # From backend_test.py + + print(f"Testing with email: {test_email}") + print() + + # Test Signin + print("1ļøāƒ£ Testing Signin...") + signin_data = { + "email": test_email, + "password": test_password + } + + try: + response = requests.post(f"{BACKEND_URL}/auth/signin", json=signin_data, timeout=30) + print(f"Status: {response.status_code}") + + if response.status_code == 200: + data = response.json() + print("āœ… Signin SUCCESS") + print(f"User ID: {data.get('user_id', 'N/A')}") + print(f"Email: {data.get('email', 'N/A')}") + print(f"First Name: {data.get('first_name', 'N/A')}") + print(f"Last Name: {data.get('last_name', 'N/A')}") + print(f"Has Access Token: {'Yes' if data.get('access_token') else 'No'}") + print(f"Has Refresh Token: {'Yes' if data.get('refresh_token') else 'No'}") + + user_id = data.get('user_id') + + # Test Get User Profile + print() + print("2ļøāƒ£ Testing Get User Profile...") + + try: + profile_response = requests.get(f"{BACKEND_URL}/auth/user/{user_id}", timeout=30) + print(f"Status: {profile_response.status_code}") + + if profile_response.status_code == 200: + profile_data = profile_response.json() + print("āœ… Get Profile SUCCESS") + print("Profile Data:") + print(json.dumps(profile_data, indent=2)) + + # Validate expected fields + expected_fields = ["id", "email", "first_name", "last_name", "phone", "tiki_count", "trust_score"] + missing_fields = [field for field in expected_fields if field not in profile_data] + + if missing_fields: + print(f"āš ļø Missing profile fields: {missing_fields}") + else: + print("āœ… All expected profile fields present") + + return True + + else: + print(f"āŒ Get Profile FAILED: {profile_response.status_code}") + print(f"Error: {profile_response.text}") + return False + + except Exception as e: + print(f"āŒ Get Profile ERROR: {str(e)}") + return False + + else: + print(f"āŒ Signin FAILED: {response.status_code}") + print(f"Error: {response.text}") + return False + + except Exception as e: + print(f"āŒ Signin ERROR: {str(e)}") + return False + +if __name__ == "__main__": + success = test_existing_user_signin() + if success: + print("\nšŸŽ‰ Signin and Profile tests PASSED!") + else: + print("\nāŒ Tests FAILED") + exit(1) \ No newline at end of file