03-player.spec.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /**
  2. * L2 回归测试:音频播放器
  3. * 覆盖:播放列表、播放进度CRUD、最近播放、章节音频详情、公开状态
  4. */
  5. import { test, expect } from '@playwright/test';
  6. import { apiGet, apiPost, apiPut, apiDelete, initApiClient, disposeApiClient } from '../helpers/api-client';
  7. test.describe('音频播放器 (Player)', () => {
  8. test.beforeAll(async () => { await initApiClient(); });
  9. test.afterAll(async () => { await disposeApiClient(); });
  10. test('P01: 获取音频播放列表 GET /api/player/audio/list', async () => {
  11. const res = await apiGet('/api/player/audio/list');
  12. expect(res.code).toBe(0);
  13. expect(res.data).toBeDefined();
  14. });
  15. test('P02: 获取播放进度 GET /api/player/progress', async () => {
  16. const res = await apiGet('/api/player/progress');
  17. expect(res.code).toBe(0);
  18. });
  19. test('P03: 保存播放进度 POST /api/player/progress', async () => {
  20. const res = await apiPost('/api/player/progress', {
  21. audioId: 1,
  22. progress: 30.5,
  23. duration: 120,
  24. });
  25. // 可能成功(0)或需要认证(401)
  26. expect([0, 401]).toContain(res.code);
  27. });
  28. test('P04: 更新播放进度 PUT /api/player/progress/1', async () => {
  29. const res = await apiPut('/api/player/progress/1', { progress: 60.0 });
  30. // 可能成功(0)、未找到(404)或需要认证(401)
  31. expect([0, 401, 404]).toContain(res.code);
  32. });
  33. test('P05: 获取最近播放 GET /api/player/recent', async () => {
  34. const res = await apiGet('/api/player/recent');
  35. expect(res.code).toBe(0);
  36. });
  37. test('P06: 获取章节音频详情 GET /api/player/audio/:id', async () => {
  38. const res = await apiGet('/api/player/audio/1');
  39. expect([0, 404]).toContain(res.code);
  40. });
  41. test('P07: 更新公开状态 PUT /api/player/audio/:id/public', async () => {
  42. const res = await apiPut('/api/player/audio/1/public', { isPublic: true });
  43. expect([0, 403, 404]).toContain(res.code);
  44. });
  45. });