workflow.spec.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. const { test, expect } = require('@playwright/test');
  2. const { loginAs, BASE_URL } = require('../../../helpers/auth');
  3. const { assertApiSuccess, authHeaders } = require('../../../helpers/utils');
  4. test.describe('【管理员】文章发布流程', function() {
  5. var auth;
  6. test.beforeAll(async function({ browser }) {
  7. auth = await loginAs(browser, 'admin');
  8. });
  9. test('[场景1] 创建文章草稿 — 状态为draft', async function({ page }) {
  10. var resp = await page.request.post(BASE_URL + '/api/admin/article/create', {
  11. headers: authHeaders(auth),
  12. data: { title: 'E2E测试文章', content: '<p>测试内容</p>', categoryId: 1 },
  13. });
  14. var data = await assertApiSuccess(resp);
  15. expect(data.status || 'draft').toBe('draft');
  16. });
  17. test('[场景2] 提交审核 — 状态变为pending', async function({ page }) {
  18. var resp = await page.request.post(BASE_URL + '/api/admin/article/submit-review', {
  19. headers: authHeaders(auth),
  20. data: { articleId: 1001 },
  21. });
  22. var data = await assertApiSuccess(resp);
  23. expect(data.status).toBe('pending');
  24. });
  25. test('[场景3] 审核通过 — 状态变为published', async function({ page }) {
  26. var resp = await page.request.post(BASE_URL + '/api/admin/article/approve', {
  27. headers: authHeaders(auth),
  28. data: { articleId: 1001 },
  29. });
  30. var data = await assertApiSuccess(resp);
  31. expect(data.status).toBe('published');
  32. });
  33. test('[场景4] 下架已发布文章 — 状态变为withdrawn', async function({ page }) {
  34. var resp = await page.request.post(BASE_URL + '/api/admin/article/withdraw', {
  35. headers: authHeaders(auth),
  36. data: { articleId: 1002 },
  37. });
  38. var data = await assertApiSuccess(resp);
  39. expect(data.status).toBe('withdrawn');
  40. });
  41. });