13-playlists.spec.ts 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. /**
  2. * L2 回归测试:播放列表、草稿箱、视频生成、订阅支付
  3. * 批量覆盖模块 13-16
  4. */
  5. import { test, expect } from '@playwright/test';
  6. import { apiGet, apiPost, apiPut, apiDelete, initApiClient, disposeApiClient } from '../helpers/api-client';
  7. // ===== 13: 播放列表 =====
  8. test.describe('播放列表 (Playlists)', () => {
  9. test.beforeAll(async () => { await initApiClient(); });
  10. test.afterAll(async () => { await disposeApiClient(); });
  11. test('PL01: 获取播放列表 GET /api/playlists', async () => {
  12. const res = await apiGet('/api/playlists');
  13. expect(res.code).toBe(0);
  14. });
  15. test('PL02: 创建播放列表 POST /api/playlists', async () => {
  16. const res = await apiPost('/api/playlists', { name: '[自动化测试] 列表' });
  17. expect(res.code).toBe(0);
  18. const id = res.data?.id;
  19. if (id) {
  20. await apiDelete(`/api/playlists/${id}`).catch(() => {});
  21. }
  22. });
  23. test('PL03: 获取播放列表详情 GET /api/playlists/:id', async () => {
  24. const res = await apiGet('/api/playlists/1');
  25. expect([0, 404]).toContain(res.code);
  26. });
  27. });
  28. // ===== 14: 草稿箱 =====
  29. test.describe('草稿箱 (Drafts)', () => {
  30. test.beforeAll(async () => { await initApiClient(); });
  31. test.afterAll(async () => { await disposeApiClient(); });
  32. test('DR01: 获取草稿列表 GET /api/drafts', async () => {
  33. const res = await apiGet('/api/drafts');
  34. expect(res.code).toBe(0);
  35. });
  36. test('DR02: 创建草稿 POST /api/drafts', async () => {
  37. const res = await apiPost('/api/drafts', {
  38. type: 'tts',
  39. data: { text: '测试', voiceId: 'Cherry' },
  40. });
  41. expect([0, 400, 404]).toContain(res.code);
  42. });
  43. test('DR03: 删除草稿 DELETE /api/drafts/:id', async () => {
  44. const res = await apiDelete('/api/drafts/99999');
  45. expect([0, 404]).toContain(res.code);
  46. });
  47. });
  48. // ===== 15: 视频生成 =====
  49. test.describe('视频生成 (VideoGenerator)', () => {
  50. test.beforeAll(async () => { await initApiClient(); });
  51. test.afterAll(async () => { await disposeApiClient(); });
  52. test('VG01: 获取视频项目列表 GET /api/video/projects', async () => {
  53. const res = await apiGet('/api/video/projects');
  54. expect(res.code).toBe(0);
  55. });
  56. test('VG02: 创建视频项目 POST /api/video/projects', async () => {
  57. const res = await apiPost('/api/video/projects', { title: '[自动化测试] 视频' });
  58. expect(res.code).toBe(0);
  59. const id = res.data?.id || res.data?.project?.id;
  60. if (id) {
  61. await apiDelete(`/api/video/projects/${id}`).catch(() => {});
  62. }
  63. });
  64. test('VG03: 获取素材列表 GET /api/video/materials', async () => {
  65. const res = await apiGet('/api/video/materials');
  66. expect(res.code).toBe(0);
  67. });
  68. });
  69. // ===== 16: 订阅支付 =====
  70. test.describe('订阅支付 (Subscription)', () => {
  71. test.beforeAll(async () => { await initApiClient(); });
  72. test.afterAll(async () => { await disposeApiClient(); });
  73. test('SU01: 获取套餐列表 GET /api/subscription/plans', async () => {
  74. const res = await apiGet('/api/subscription/plans');
  75. expect(res.code).toBe(0);
  76. });
  77. test('SU02: 获取余额 GET /api/subscription/balance', async () => {
  78. const res = await apiGet('/api/subscription/balance');
  79. expect(res.code).toBe(0);
  80. });
  81. test('SU03: 创建订单 POST /api/subscription/orders', async () => {
  82. const res = await apiPost('/api/subscription/orders', { planId: 1 });
  83. expect([0, 400, 401]).toContain(res.code);
  84. });
  85. });