| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- /**
- * SC-X-05 任务激励闭环全链路三类流(task.closedLoop.incentive)
- * ================================================================
- * 正常流:创建任务 → 完成 → 得积分/CF → 提心愿 → 申请兑换 → 批准 → 标记购买 → 确认收货(闭环);
- * 异常流:闭环中途非法状态操作被拒;重复完成不双计分;
- * 权限流:闭环中跨家庭干扰被拒。
- */
- const { test, expect } = require('@playwright/test');
- const { registerRole, apiPost, uniqueSuffix } = require('../helpers/api');
- test.describe('SC-X-05 任务激励闭环三类流', () => {
- let parent;
- let childA;
- test.beforeAll(async ({ request }) => {
- parent = await registerRole(request, 'parent', 'QA-LOOP');
- const mem = await apiPost(request, '/api/family/member/list', {}, parent.token);
- const self = (mem.data || []).find((m) => String(m.userId) === String(parent.userId));
- const addA = await apiPost(request, '/api/family/member/add', {
- relativeMemberId: self.id, generationLevel: 'child',
- nickname: 'A-Loop' + uniqueSuffix(), gender: 'female', birthday: '2016-02-01',
- }, parent.token);
- expect(addA.code, 'addA: ' + addA.message).toBe(200);
- childA = addA.data.id;
- });
- test('[X-05 正常] 任务→积分→心愿→兑换→批准→收货闭环', async ({ request }) => {
- // 1) 任务创建+完成得积分
- const task = await apiPost(request, '/api/tasks/create', {
- title: '闭环任务' + uniqueSuffix(), points: 50, memberId: childA, frequency: 'none', needReview: 0,
- }, parent.token);
- expect(task.code, 'task create: ' + task.message).toBe(200);
- const taskId = task.data;
- const done = await apiPost(request, `/api/tasks/${taskId}/complete`, { memberId: childA }, parent.token);
- expect(done.code, 'task complete: ' + done.message).toBe(200);
- expect(done.data.pointsEarned).toBeGreaterThan(0);
- // 2) 提心愿(CF 已由任务发放)
- const wish = await apiPost(request, '/api/wishes/create', {
- title: '闭环心愿' + uniqueSuffix(), memberId: childA, pointsRequired: 20, category: '文具',
- }, parent.token);
- expect(wish.code, 'wish create: ' + wish.message).toBe(200);
- const wishId = wish.data;
- // 3) 申请兑换 → 批准 → 标记购买 → 确认收货
- const req = await apiPost(request, `/api/wishes/${wishId}/exchange`, { memberId: childA }, parent.token);
- expect(req.code, 'exchange: ' + req.message).toBe(200);
- const approve = await apiPost(request, `/api/wishes/${wishId}/approve-exchange`, {
- memberId: childA, approved: true,
- }, parent.token);
- expect(approve.code, 'approve: ' + approve.message).toBe(200);
- const fulfill = await apiPost(request, `/api/wishes/${wishId}/fulfill`, {}, parent.token);
- expect(fulfill.code, 'fulfill: ' + fulfill.message).toBe(200);
- const confirm = await apiPost(request, `/api/wishes/${wishId}/confirm`, {}, parent.token);
- expect(confirm.code, 'confirm: ' + confirm.message).toBe(200);
- const detail = await apiPost(request, `/api/wishes/${wishId}`, {}, parent.token);
- expect(detail.data.status).toBe('fulfilled');
- });
- test('[X-05-E 异常] 重复完成已通过任务 → 不双计分', async ({ request }) => {
- const task = await apiPost(request, '/api/tasks/create', {
- title: '闭环幂等' + uniqueSuffix(), points: 10, memberId: childA, frequency: 'none', needReview: 0,
- }, parent.token);
- expect(task.code).toBe(200);
- const taskId = task.data;
- const first = await apiPost(request, `/api/tasks/${taskId}/complete`, { memberId: childA }, parent.token);
- expect(first.code).toBe(200);
- const second = await apiPost(request, `/api/tasks/${taskId}/complete`, { memberId: childA }, parent.token);
- // 幂等:第二次 pointsEarned=0
- expect(second.code).toBe(200);
- if (second.data && second.data.pointsEarned !== undefined) {
- expect(second.data.pointsEarned).toBe(0);
- }
- });
- test('[X-05-P 权限] 闭环中跨家庭干扰被拒', async ({ request }) => {
- const outsider = await registerRole(request, 'parent', 'QA-LOOP-X');
- const wish = await apiPost(request, '/api/wishes/create', {
- title: '闭环他人' + uniqueSuffix(), memberId: childA, pointsRequired: 5,
- }, parent.token);
- expect(wish.code).toBe(200);
- const wishId = wish.data;
- // 外人越权审批
- const xApprove = await apiPost(request, `/api/wishes/${wishId}/approve-exchange`, {
- memberId: childA, approved: true,
- }, outsider.token);
- expect(xApprove.code).not.toBe(200);
- });
- });
|