02-tts.spec.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /**
  2. * L2 回归测试:TTS语音合成
  3. * 覆盖:音色列表、提供商列表、音频生成、状态查询、预览、下载
  4. */
  5. import { test, expect } from '@playwright/test';
  6. import { apiGet, apiPost, initApiClient, disposeApiClient } from '../helpers/api-client';
  7. import { trackResource } from '../helpers/test-data';
  8. let testAudioId: string;
  9. test.describe('TTS语音合成 (TTS)', () => {
  10. test.beforeAll(async () => {
  11. await initApiClient();
  12. });
  13. test.afterAll(async () => {
  14. await disposeApiClient();
  15. });
  16. test('T01: 获取音色列表 GET /api/tts/voices', async () => {
  17. const res = await apiGet('/api/tts/voices');
  18. expect(res.code).toBe(0);
  19. expect(res.data?.voices).toBeDefined();
  20. expect(Array.isArray(res.data.voices)).toBe(true);
  21. });
  22. test('T02: 获取提供商列表 GET /api/tts/providers', async () => {
  23. const res = await apiGet('/api/tts/providers');
  24. expect(res.code).toBe(0);
  25. expect(res.data?.providers).toBeDefined();
  26. });
  27. test('T03: 生成音频任务 POST /api/tts/generate', async () => {
  28. const res = await apiPost('/api/tts/generate', {
  29. text: '这是一段自动化测试文本,用于验证TTS音频生成功能。',
  30. voiceId: 'Cherry',
  31. voiceParams: { speed: 1.0, pitch: 0, volume: 50 },
  32. });
  33. // 异步任务应该返回 0
  34. expect(res.code).toBe(0);
  35. testAudioId = res.data?.audioId;
  36. expect(testAudioId).toBeDefined();
  37. });
  38. test('T04: 查询音频状态 GET /api/tts/status/:audioId', async () => {
  39. if (!testAudioId) return test.skip();
  40. const res = await apiGet(`/api/tts/status/${testAudioId}`);
  41. expect([0, 404]).toContain(res.code);
  42. });
  43. test('T05: 获取下载信息 GET /api/tts/download/:audioId', async () => {
  44. // 使用一个可能存在的音频ID测试路由可达性
  45. const res = await apiGet('/api/tts/download/1');
  46. expect([0, 404, 500]).toContain(res.code);
  47. });
  48. });