import api from '../services/api'; // Test function to check API response structure export const testApiStructure = async () => { try { console.log('🧪 [TEST] Starting API structure test...'); // Test accounts endpoint console.log('🧪 [TEST] Testing /accounts endpoint...'); const response = await api.get('/accounts'); console.log('🧪 [TEST] Raw response:', response); console.log('🧪 [TEST] Response data:', response.data); console.log('🧪 [TEST] Response data type:', typeof response.data); console.log('🧪 [TEST] Response data is array:', Array.isArray(response.data)); if (response.data) { console.log('🧪 [TEST] Response data keys:', Object.keys(response.data)); if (response.data.success) { console.log('🧪 [TEST] Response is successful'); if (response.data.accounts) { console.log('🧪 [TEST] Accounts found:', response.data.accounts.length); console.log('🧪 [TEST] Accounts type:', typeof response.data.accounts); console.log('🧪 [TEST] Accounts is array:', Array.isArray(response.data.accounts)); // Filter LinkedIn accounts const linkedinAccounts = response.data.accounts.filter( account => account && account.social_network && account.social_network.toLowerCase() === 'linkedin' ); console.log('🧪 [TEST] LinkedIn accounts found:', linkedinAccounts.length); console.log('🧪 [TEST] LinkedIn accounts:', linkedinAccounts); } } else { console.log('🧪 [TEST] Response not successful'); } } return response; } catch (error) { console.error('🧪 [TEST] API test failed:', error); return error; } }; // Test function to simulate the service behavior export const testServiceBehavior = async () => { try { console.log('🧪 [TEST] Testing service behavior...'); const response = await api.get('/accounts'); // Simulate the service logic let accounts = []; if (response.data && response.data.success && response.data.accounts) { console.log('🧪 [TEST] Format 1: success + accounts structure'); accounts = response.data.accounts; } else if (Array.isArray(response.data)) { console.log('🧪 [TEST] Format 2: Direct array'); accounts = response.data; } else { console.error('🧪 [TEST] Unexpected response format:', response.data); throw new Error('Unexpected response format from API'); } console.log('🧪 [TEST] All accounts:', accounts); // Filter for LinkedIn accounts only const linkedinAccounts = accounts.filter( account => account && account.social_network && account.social_network.toLowerCase() === 'linkedin' ); console.log('🧪 [TEST] Filtered LinkedIn accounts:', linkedinAccounts); return linkedinAccounts; } catch (error) { console.error('🧪 [TEST] Service test failed:', error); return []; } }; // Run tests // if (typeof window !== 'undefined') { // // Browser environment - run tests on load // window.addEventListener('load', () => { // console.log('🧪 [TEST] Running API tests...'); // testApiStructure(); // testServiceBehavior(); // }); // }