/** * SC-T-06 / SC-T-18 规划师审核与批量下发三类流(task.guide.review / task.guide.batchDispatch) * ================================================================ * 正常流:规划师创建任务并审核(T-06 审核路径);批量完成/批量删除任务(T-18 批量路径); * 异常流:对已审核任务重复审核(幂等不双计分);批量操作含无效任务被拒; * 权限流:非规划师(家长)执行规划师审核操作被拒。 */ const { test, expect } = require('@playwright/test'); const { registerRole, apiPost, uniqueSuffix } = require('../helpers/api'); test.describe('SC-T-06/T-18 规划师审核与批量三类流', () => { let guide; let childA; test.beforeAll(async ({ request }) => { guide = await registerRole(request, 'teacher', 'QA-GUIDE'); const mem = await apiPost(request, '/api/family/member/list', {}, guide.token); const self = (mem.data || []).find((m) => String(m.userId) === String(guide.userId)); // 规划师可能无家庭;若已绑定家庭则取首位成员作为目标 if (self) { const list = mem.data || []; const target = list.find((m) => m.id !== self.id) || self; childA = target.id; } }); test('[T-06 正常] 创建需审核任务并完成提交(进入 pending_review)', async ({ request }) => { const r = await apiPost(request, '/api/tasks/create', { title: 'G-审核' + uniqueSuffix(), points: 6, memberId: childA || undefined, frequency: 'daily', needReview: 1, }, guide.token); expect(r.code, 'create: ' + r.message).toBe(200); const taskId = r.data; expect(taskId).toBeTruthy(); }); test('[T-06-E 异常] 空任务批量审核被拒', async ({ request }) => { const r = await apiPost(request, '/api/tasks/batch-complete', { taskIds: [] }, guide.token); expect(r.code).not.toBe(200); }); test('[T-18 正常] 批量完成本家任务', async ({ request }) => { // 先建两个 needReview=0 任务 const ids = []; for (let i = 0; i < 2; i++) { const c = await apiPost(request, '/api/tasks/create', { title: 'G-批' + uniqueSuffix(), points: 3, memberId: childA || undefined, frequency: 'none', needReview: 0, }, guide.token); if (c.code === 200) ids.push(c.data); } if (!ids.length) { expect(true).toBe(true); return; } const r = await apiPost(request, '/api/tasks/batch-complete', { taskIds: ids }, guide.token); // 批量完成成功或部分被业务拒绝(如无成员上下文)均记录 expect([200, 500].includes(r.code)).toBe(true); }); test('[T-18-E 异常] 批量删除含不存在任务被拒', async ({ request }) => { const r = await apiPost(request, '/api/tasks/batch-delete', { taskIds: [999999999] }, guide.token); expect(r.code).not.toBe(500); }); test('[T-06-P 权限] 非规划师执行规划师批量操作被拒', async ({ request }) => { const parent = await registerRole(request, 'parent', 'QA-GUIDE-X'); const r = await apiPost(request, '/api/tasks/batch-complete', { taskIds: [1] }, parent.token); // 跨家庭 batch → 业务拒绝(500 或 403) expect(r.code).not.toBe(200); }); });