#!/usr/bin/env node

console.log('🔍 Testing improved TradingView automation...')

async function testLoginSystem() {
  try {
    const response = await fetch('http://localhost:9001/api/enhanced-screenshot', {
      method: 'POST',
      headers: { 'Content-Type': 'application/json' },
      body: JSON.stringify({
        symbol: 'BTCUSD',
        timeframe: '4h',
        layouts: ['ai'],
        analyze: false
      })
    })

    const result = await response.json()
    
    console.log('📊 Test Results:')
    console.log('Success:', result.success)
    console.log('Session ID:', result.sessionId)
    console.log('Screenshots:', result.screenshots?.length || 0)
    console.log('Message:', result.message)
    
    if (result.success) {
      console.log('✅ System is working! The login automation improvements are successful.')
      if (result.screenshots?.length === 0) {
        console.log('📝 Note: No screenshots captured, but API is responding correctly.')
        console.log('💡 This suggests login detection needs refinement for already-logged-in users.')
      }
    } else {
      console.log('❌ Test failed:', result.error)
    }
    
  } catch (error) {
    console.error('❌ Test error:', error.message)
  }
}

testLoginSystem()
