11-book-generator.spec.ts 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. /**
  2. * L2 回归测试:AI书籍生成(核心模块)
  3. * 覆盖:书籍 CRUD、大纲生成、章节生成、音频生成、合并、发布
  4. */
  5. import { test, expect } from '@playwright/test';
  6. import { apiGet, apiPost, apiPut, apiDelete, initApiClient, disposeApiClient } from '../helpers/api-client';
  7. import { trackResource } from '../helpers/test-data';
  8. let testBookId: number;
  9. test.describe('AI书籍生成 (BookGenerator)', () => {
  10. test.beforeAll(async () => { await initApiClient(); });
  11. test.afterAll(async () => { await disposeApiClient(); });
  12. // ===== 书籍 CRUD =====
  13. test('BG01: 获取书籍列表 GET /api/book-generator/langgraph/books', async () => {
  14. const res = await apiGet('/api/book-generator/langgraph/books');
  15. expect(res.code).toBe(0);
  16. });
  17. test('BG02: 创建书籍 POST /api/book-generator/langgraph/books', async () => {
  18. const res = await apiPost('/api/book-generator/langgraph/books', {
  19. title: `[自动化测试] 测试书籍 ${Date.now()}`,
  20. description: '由自动化回归测试创建',
  21. });
  22. expect(res.code).toBe(0);
  23. testBookId = res.data?.id || res.data?.book?.id;
  24. expect(testBookId).toBeDefined();
  25. if (testBookId) {
  26. trackResource('book', testBookId, async () => {
  27. await apiDelete(`/api/book-generator/langgraph/books/${testBookId}`);
  28. });
  29. }
  30. });
  31. test('BG03: 获取书籍详情 GET /api/book-generator/langgraph/books/:id', async () => {
  32. if (!testBookId) return test.skip();
  33. const res = await apiGet(`/api/book-generator/langgraph/books/${testBookId}`);
  34. expect(res.code).toBe(0);
  35. });
  36. test('BG04: 获取工作流状态 GET /api/book-generator/langgraph/workflow/:id', async () => {
  37. if (!testBookId) return test.skip();
  38. const res = await apiGet(`/api/book-generator/langgraph/workflow/${testBookId}`);
  39. expect([0, 404]).toContain(res.code);
  40. });
  41. test('BG05: 获取生成进度 GET /api/book-generator/langgraph/books/:id/progress', async () => {
  42. if (!testBookId) return test.skip();
  43. const res = await apiGet(`/api/book-generator/langgraph/books/${testBookId}/progress`);
  44. expect([0, 404]).toContain(res.code);
  45. });
  46. test('BG06: 获取完整内容 GET /api/book-generator/langgraph/books/:id/full-content', async () => {
  47. if (!testBookId) return test.skip();
  48. const res = await apiGet(`/api/book-generator/langgraph/books/${testBookId}/full-content`);
  49. expect([0, 404]).toContain(res.code);
  50. });
  51. // ===== 生成操作 =====
  52. test('BG07: 生成大纲 POST /api/book-generator/langgraph/books/:id/outline', async () => {
  53. if (!testBookId) return test.skip();
  54. const res = await apiPost(`/api/book-generator/langgraph/books/${testBookId}/outline`);
  55. expect([0, 400, 409]).toContain(res.code);
  56. });
  57. test('BG08: 切换发布状态 PUT /api/book-generator/langgraph/books/:id/publish', async () => {
  58. if (!testBookId) return test.skip();
  59. const res = await apiPut(`/api/book-generator/langgraph/books/${testBookId}/publish`);
  60. expect([0, 400, 404]).toContain(res.code);
  61. });
  62. // ===== AI生成接口 =====
  63. test('BG09: AI生成接口 - 仅 POST /api/book-generator/ai-generate,跳过 GET', async () => {
  64. // /api/book-generator/books 是 POST /ai-generate,不是 GET
  65. test.skip();
  66. });
  67. // ===== 清理测试数据 =====
  68. test('BG10: 删除测试书籍 DELETE /api/book-generator/langgraph/books/:id', async () => {
  69. if (!testBookId) return test.skip();
  70. const res = await apiDelete(`/api/book-generator/langgraph/books/${testBookId}`);
  71. expect([0, 404, 403]).toContain(res.code);
  72. });
  73. });