/**
 * L2 回归测试：评论系统
 * 注意：评论 API 需要认证，且路径为 /api/comments/:chapterId
 */
import { test, expect } from '@playwright/test';
import { apiGet, apiPost, apiDelete, initApiClient, disposeApiClient } from '../helpers/api-client';

test.describe('评论系统 (Comments)', () => {
  test.beforeAll(async () => { await initApiClient(); });
  test.afterAll(async () => { await disposeApiClient(); });

  // 评论需要 chapterId 参数，且需要认证
  test('C01: 获取评论列表 GET /api/comments/:chapterId', async () => {
    const res = await apiGet('/api/comments/1');
    // 可能成功(0)、未找到(404)或需要认证(401)
    expect([0, 401, 404]).toContain(res.code);
  });

  test('C02: 创建评论 POST /api/comments', async () => {
    const res = await apiPost('/api/comments', {
      chapterId: 1,
      content: '[自动化测试] 测试评论内容',
      rating: 5,
    });
    // 可能成功(0)、参数错误(400)或需要认证(401)
    expect([0, 400, 401]).toContain(res.code);
  });

  test('C03: 删除评论 DELETE /api/comments/:id', async () => {
    const res = await apiDelete('/api/comments/99999');
    // 需要认证，未找到或成功
    expect([0, 401, 404]).toContain(res.code);
  });
});