| # Account Creation Testing Guide | |
| This guide provides instructions for testing the account creation functionality and debugging issues. | |
| ## Overview | |
| The account creation process involves several components: | |
| 1. Frontend OAuth initiation | |
| 2. LinkedIn authentication | |
| 3. OAuth callback handling | |
| 4. Database insertion | |
| 5. Account retrieval | |
| ## Testing Scripts | |
| ### 1. Database Connection Test | |
| **File**: `test_database_connection.py` | |
| **Purpose**: Test basic database connectivity and CRUD operations | |
| **Usage**: | |
| ```bash | |
| cd backend | |
| python test_database_connection.py | |
| ``` | |
| **Tests Performed**: | |
| - Supabase client initialization | |
| - Basic database connection | |
| - Record insertion, retrieval, and deletion | |
| - Authentication status check | |
| ### 2. OAuth Flow Test | |
| **File**: `test_oauth_flow.py` | |
| **Purpose**: Test the complete OAuth flow and account creation process | |
| **Usage**: | |
| ```bash | |
| cd backend | |
| python test_oauth_flow.py | |
| ``` | |
| **Tests Performed**: | |
| - LinkedIn service initialization | |
| - Authorization URL generation | |
| - Account creation flow simulation | |
| - OAuth callback simulation | |
| - Database operations with OAuth data | |
| ## Running the Tests | |
| ### Prerequisites | |
| 1. Ensure you have the required dependencies installed: | |
| ```bash | |
| pip install -r requirements.txt | |
| ``` | |
| 2. Verify environment variables are set in `.env` file: | |
| - `SUPABASE_URL` | |
| - `SUPABASE_KEY` | |
| - `CLIENT_ID` | |
| - `CLIENT_SECRET` | |
| - `REDIRECT_URL` | |
| ### Step-by-Step Testing | |
| #### Step 1: Database Connection Test | |
| ```bash | |
| cd backend | |
| python test_database_connection.py | |
| ``` | |
| **Expected Output**: | |
| ``` | |
| π Starting database connection tests... | |
| π Testing database connection... | |
| β Supabase client initialized successfully | |
| β Database connection successful | |
| β Insert test successful | |
| β Retrieve test successful | |
| β Delete test successful | |
| π All database tests passed! | |
| ``` | |
| #### Step 2: OAuth Flow Test | |
| ```bash | |
| cd backend | |
| python test_oauth_flow.py | |
| ``` | |
| **Expected Output**: | |
| ``` | |
| π Starting OAuth flow tests... | |
| π Testing LinkedIn service... | |
| β LinkedIn service initialized successfully | |
| β Authorization URL generated successfully | |
| π LinkedIn service test completed successfully! | |
| π Testing account creation flow... | |
| β Account insertion response: <response object> | |
| β Account inserted successfully with ID: <account_id> | |
| β Retrieved 1 accounts for user test_user_123 | |
| β Account deletion response: <response object> | |
| π Account creation flow test completed successfully! | |
| π Simulating OAuth callback process... | |
| β OAuth callback simulation response: <response object> | |
| β Response data: [<account_data>] | |
| π OAuth callback simulation completed successfully! | |
| π All tests passed! OAuth flow is working correctly. | |
| ``` | |
| ## Debugging the Account Creation Issue | |
| ### Step 1: Check Database Connection | |
| Run the database connection test to ensure: | |
| - Supabase client is properly initialized | |
| - Database operations work correctly | |
| - No permission issues | |
| ### Step 2: Check OAuth Configuration | |
| Run the OAuth flow test to verify: | |
| - LinkedIn service is properly configured | |
| - Authorization URL generation works | |
| - Database insertion with OAuth data works | |
| ### Step 3: Enhanced Logging | |
| The enhanced logging will help identify issues in the actual flow: | |
| #### Backend Logs | |
| Look for these log messages: | |
| - `π [OAuth] Starting callback for user: <user_id>` | |
| - `π [OAuth] Received data: <data>` | |
| - `π [OAuth] Supabase client available: <boolean>` | |
| - `π [OAuth] Token exchange successful` | |
| - `π [OAuth] User info fetched: <user_info>` | |
| - `π [OAuth] Database response: <response>` | |
| - `π [OAuth] Account linked successfully` | |
| #### Frontend Logs | |
| Look for these console messages: | |
| - `π [Frontend] LinkedIn callback handler started` | |
| - `π [Frontend] URL parameters: {code: '...', state: '...', error: null}` | |
| - `π [Frontend] Dispatching LinkedIn callback action...` | |
| - `π [Frontend] Callback result: {success: true, ...}` | |
| ### Step 4: Common Issues and Solutions | |
| #### Issue 1: Database Connection Fails | |
| **Symptoms**: Database connection test fails | |
| **Solutions**: | |
| - Check `SUPABASE_URL` and `SUPABASE_KEY` in `.env` file | |
| - Verify Supabase project is active | |
| - Check network connectivity | |
| #### Issue 2: OAuth Configuration Issues | |
| **Symptoms**: LinkedIn service test fails | |
| **Solutions**: | |
| - Check `CLIENT_ID`, `CLIENT_SECRET`, and `REDIRECT_URL` in `.env` file | |
| - Verify LinkedIn App is properly configured | |
| - Ensure redirect URL is whitelisted in LinkedIn App settings | |
| #### Issue 3: Database Insertion Fails | |
| **Symptoms**: OAuth flow test passes but actual account creation fails | |
| **Solutions**: | |
| - Check RLS policies on `Social_network` table | |
| - Verify user ID mapping between auth and database | |
| - Check for data validation issues | |
| #### Issue 4: Silent Failures | |
| **Symptoms**: No error messages but accounts don't appear | |
| **Solutions**: | |
| - Check enhanced logs for specific error messages | |
| - Verify database response data | |
| - Check for exceptions being caught and suppressed | |
| ### Step 5: Manual Testing | |
| #### Test the Complete Flow | |
| 1. Start the backend server: | |
| ```bash | |
| cd backend | |
| python app.py | |
| ``` | |
| 2. Start the frontend server: | |
| ```bash | |
| cd frontend | |
| npm run dev | |
| ``` | |
| 3. Navigate to the application and try to add a LinkedIn account | |
| 4. Check the browser console for frontend logs | |
| 5. Check the backend logs for detailed debugging information | |
| ## Monitoring and Maintenance | |
| ### Log Analysis | |
| Monitor these key log messages: | |
| - Successful OAuth callback processing | |
| - Database insertion success/failure | |
| - Error messages and exceptions | |
| - Performance metrics | |
| ### Regular Testing | |
| Run the test scripts regularly to ensure: | |
| - Database connectivity remains stable | |
| - OAuth configuration is correct | |
| - No new issues have been introduced | |
| ### Performance Monitoring | |
| Track these metrics: | |
| - Account creation success rate | |
| - Database query performance | |
| - OAuth token exchange time | |
| - User authentication time | |
| ## Troubleshooting Checklist | |
| ### Before Testing | |
| - [ ] Verify all environment variables are set | |
| - [ ] Check Supabase project is active | |
| - [ ] Verify LinkedIn App configuration | |
| - [ ] Ensure all dependencies are installed | |
| ### During Testing | |
| - [ ] Run database connection test first | |
| - [ ] Run OAuth flow test second | |
| - [ ] Check for any error messages | |
| - [ ] Verify all test cases pass | |
| ### After Testing | |
| - [ ] Review enhanced logs for the actual flow | |
| - [ ] Check for any patterns in failures | |
| - [ ] Document any issues found | |
| - [ ] Create fixes for identified problems | |
| ## Support | |
| If you encounter issues not covered in this guide: | |
| 1. Check the enhanced logs for specific error messages | |
| 2. Verify all configuration settings | |
| 3. Test each component individually | |
| 4. Document the issue and seek assistance |