const axios = require('axios');

const api = axios.create({
  baseURL: 'http://localhost:3000',
  timeout: 10000
});

async function testInsuranceTypesAPI() {
  try {
    console.log('🔐 管理员登录...');
    
    // 管理员登录
    const loginResponse = await api.post('/api/auth/login', {
      username: 'admin',
      password: '123456'
    });
    
    if (loginResponse.data.code !== 200) {
      console.log('✗ 管理员登录失败:', loginResponse.data.message);
      return;
    }
    
    const token = loginResponse.data.data.token;
    api.defaults.headers.common['Authorization'] = `Bearer ${token}`;
    console.log('✓ 管理员登录成功');
    
    // 测试获取保险类型列表
    console.log('\n📋 测试获取保险类型列表...');
    const typesResponse = await api.get('/api/insurance-types');
    console.log('响应状态:', typesResponse.status);
    console.log('响应数据:', JSON.stringify(typesResponse.data, null, 2));
    
    if (typesResponse.data.code === 200) {
      console.log('✓ 获取保险类型列表成功');
      console.log('保险类型数量:', typesResponse.data.data.list?.length || 0);
    } else {
      console.log('✗ 获取保险类型列表失败:', typesResponse.data.message);
    }
    
  } catch (error) {
    console.log('✗ 测试失败:', error.response?.data?.message || error.message);
    if (error.response) {
      console.log('错误状态:', error.response.status);
      console.log('错误数据:', error.response.data);
    }
  }
}

testInsuranceTypesAPI();