07-comments.spec.ts 1.2 KB

12345678910111213141516171819202122232425262728293031323334
  1. /**
  2. * L2 回归测试:评论系统
  3. * 注意:评论 API 需要认证,且路径为 /api/comments/:chapterId
  4. */
  5. import { test, expect } from '@playwright/test';
  6. import { apiGet, apiPost, apiDelete, initApiClient, disposeApiClient } from '../helpers/api-client';
  7. test.describe('评论系统 (Comments)', () => {
  8. test.beforeAll(async () => { await initApiClient(); });
  9. test.afterAll(async () => { await disposeApiClient(); });
  10. // 评论需要 chapterId 参数,且需要认证
  11. test('C01: 获取评论列表 GET /api/comments/:chapterId', async () => {
  12. const res = await apiGet('/api/comments/1');
  13. // 可能成功(0)、未找到(404)或需要认证(401)
  14. expect([0, 401, 404]).toContain(res.code);
  15. });
  16. test('C02: 创建评论 POST /api/comments', async () => {
  17. const res = await apiPost('/api/comments', {
  18. chapterId: 1,
  19. content: '[自动化测试] 测试评论内容',
  20. rating: 5,
  21. });
  22. // 可能成功(0)、参数错误(400)或需要认证(401)
  23. expect([0, 400, 401]).toContain(res.code);
  24. });
  25. test('C03: 删除评论 DELETE /api/comments/:id', async () => {
  26. const res = await apiDelete('/api/comments/99999');
  27. // 需要认证,未找到或成功
  28. expect([0, 401, 404]).toContain(res.code);
  29. });
  30. });