import { test, expect } from '@playwright/test';

test('API测试：检查系统配置API', async ({ request }) => {
  console.log('开始测试系统配置API...');

  // 1. 先登录获取token
  const loginResponse = await request.post('http://localhost:8084/api/auth/login', {
    data: {
      username: 'admin',
      password: 'admin123'
    }
  });

  console.log('登录响应状态:', loginResponse.status());
  const loginData = await loginResponse.json();
  console.log('登录响应数据:', JSON.stringify(loginData, null, 2));

  expect(loginResponse.status()).toBe(200);

  // 2. 获取token
  const token = loginData.token || loginData.data?.token;
  console.log('获取到的token:', token ? token.substring(0, 20) + '...' : '未找到');

  // 3. 使用token访问系统配置API
  const configResponse = await request.get('http://localhost:8084/api/config', {
    headers: {
      'Authorization': `Bearer ${token}`
    }
  });

  console.log('系统配置API响应状态:', configResponse.status());
  const configData = await configResponse.json();
  console.log('系统配置数据:', JSON.stringify(configData, null, 2));

  expect(configResponse.status()).toBe(200);
});