|
|
@@ -0,0 +1,246 @@
|
|
|
+/**
|
|
|
+ * SC-P-15 积分明细查看 + SC-P-16 积分流水对账 三类流(points.ledger.view,S-cfc-263 RED)
|
|
|
+ * ================================================================
|
|
|
+ * 任务:R729 主目标 #3/#4(discovery-2026-12-01-0814.md F-0812-12/F-0812-11 建议 #1;
|
|
|
+ * 增量纠正 0828 §3.3/§3.4:实现侧 S-cfc-482 已合入(fe32d96bf),但 e2e 三流 0 覆盖。)
|
|
|
+ *
|
|
|
+ * 编号裁决(本文件执行 · F-0812-11 TC-P-15 三重语义冲突):
|
|
|
+ * 裁决:TC-P-15 归属「积分明细查看」(SC-P-15),依据 TC-P-nn ↔ SC-P-nn 编号对齐纪律
|
|
|
+ * (parent.md 其余 TC-P-01~16 行均与 SC-P-nn 对齐);F-0812-11 建议双角色门禁(现 parent.md L30
|
|
|
+ * TC-P-15「双角色边界,门禁」,内容属 SC-P-03)改 TC-P-03-G 类后缀——台账改名**待人工核实**
|
|
|
+ * (本节点硬边界不改 tests/test-cases、tests/user-scenarios)。本 spec 的 TC 标签按裁决口径执行。
|
|
|
+ *
|
|
|
+ * 真实契约来源(探针 _probe_p14_p15_p16.spec.js / _probe_p14_p15_p16_r3.spec.js,
|
|
|
+ * 2026-12-01 远端 http://cfc.iwintrue.com 实测):
|
|
|
+ * - 正流水载体:/api/mini-game/list(启用 3 款)+ /api/mini-game/complete {memberId,gameCode,
|
|
|
+ * completionTime,score} → 200 {pointsEarned,newBalance,gameName};写 points_logs(type=earn,
|
|
|
+ * category=task, description=「完成游戏: {名}」)+ family_members.total_points 同额累加
|
|
|
+ * (探针 r3:7+10=17,balance=17=logSum);
|
|
|
+ * - /api/points/logs {memberId,page,size,startTime?,endTime?} → Page{records[],total,size,current,pages},
|
|
|
+ * records 字段 {id,familyMemberId,taskId,amount,type,category,description,sourceName,createdAt,
|
|
|
+ * expireAt,expired,childId},createdAt 降序;sourceName 映射 earn+task→「完成任务」;
|
|
|
+ * 空明细(新成员)→ total=0/records=[]/pages=0;时间筛选整日边界、非法值忽略不抛错(200 全量);
|
|
|
+ * - /api/points/balance {memberId} → {balance,totalPoints,expireDate}(balance=totalPoints=
|
|
|
+ * family_members.total_points);
|
|
|
+ * - /api/points/adjust:家庭主账号密码校验(错/缺密码 → 400「家庭主账号密码校验失败」),
|
|
|
+ * 且 F19 改投 CF 账本(cf_balance_log),**不写 points_logs**(负流水无 API 载体)。
|
|
|
+ *
|
|
|
+ * 承袭缺陷(fixme 占位,不为缺陷造绿、不写放水断言):
|
|
|
+ * - P-15-P / P-16-P 越权面(G-304-1 族新增点位,探针 r3 实测):
|
|
|
+ * ① 越权(outsider token)查他家庭 /api/points/logs、/api/points/balance → 200 返回其真实流水/余额
|
|
|
+ * (PointsController 无家庭范围守卫,memberId 参数直查);
|
|
|
+ * ② 匿名(无 token)同端点 → 200(/api/points/** 不在 JwtInterceptor LOGIN_REQUIRED_PATHS,
|
|
|
+ * 走 setAnonymousUser 放行);
|
|
|
+ * 转绿条件:越权/匿名均 401/403 拒绝且他家庭数据不可见;
|
|
|
+ * - P-16-E 负流水报警:points_logs 负流水无 API 载体(任务域 penalty/回退被 B-275-1 任务域 500
|
|
|
+ * 阻塞;F19 adjust 走 CF 账本+密码门;service 层 reconcile() 的 alert/negativeCount 仅服务侧
|
|
|
+ * 计算、无 HTTP 端点暴露、无报警动作);
|
|
|
+ * 转绿条件:负流水载体存在(删除/回退负流水)+ 对账暴露(端点或字段)总额仍=流水合计。
|
|
|
+ *
|
|
|
+ * 写库纪律:仅在自建 QA 家庭内对自建成员发小游戏积分(uniqueSuffix 命名隔离),无共享数据污染;
|
|
|
+ * P-15-P/P-16-P fixme 体为只读断言(越权读),P-16-E fixme 体的 adjust 必 400 拒绝零写。
|
|
|
+ *
|
|
|
+ * 运行:cd tests && npx playwright test e2e/api/points-ledger-sc-p15-p16.spec.js -c playwright.config.api.js --project=desktop
|
|
|
+ */
|
|
|
+const { test, expect } = require('@playwright/test');
|
|
|
+const { registerRole, apiPost, pickMemberByUserId, uniqueSuffix } = require('../helpers/api');
|
|
|
+
|
|
|
+/** 本地 yyyy-MM-dd(偏移天),不解析日期字符串(小程序/Node 口径一致,禁 new Date(string)) */
|
|
|
+function localDateStr(offsetDays) {
|
|
|
+ const d = new Date();
|
|
|
+ d.setDate(d.getDate() + offsetDays);
|
|
|
+ return d.getFullYear() + '-' + String(d.getMonth() + 1).padStart(2, '0') + '-' + String(d.getDate()).padStart(2, '0');
|
|
|
+}
|
|
|
+
|
|
|
+test.describe('SC-P-15/P-16 积分明细与流水对账 三类流(points.ledger.view)', () => {
|
|
|
+ let parent;
|
|
|
+ let outsider;
|
|
|
+ let childA; // 有流水(2 条小游戏 earn)
|
|
|
+ let childB; // 空明细
|
|
|
+ let c1; // 第一次完成 {pointsEarned,newBalance}
|
|
|
+ let c2; // 第二次完成
|
|
|
+ let doneCount; // 实际完成的流水条数(2,启用小游戏 <2 款时自适应降级)
|
|
|
+
|
|
|
+ test.beforeAll(async ({ request }) => {
|
|
|
+ // N-R373-1 现象:网关多实例轮询偶发 502,注册步骤本地加重试(不改共享 helper)
|
|
|
+ async function registerWithRetry(role, nick) {
|
|
|
+ for (let i = 0; i < 5; i++) {
|
|
|
+ try {
|
|
|
+ return await registerRole(request, role, nick);
|
|
|
+ } catch (e) {
|
|
|
+ if (i === 4) throw e;
|
|
|
+ await new Promise((r) => setTimeout(r, 10000));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ parent = await registerWithRetry('parent', 'QA-P15-PARENT');
|
|
|
+ outsider = await registerWithRetry('parent', 'QA-P15-OUT');
|
|
|
+ const memList = await apiPost(request, '/api/family/member/list', {}, parent.token);
|
|
|
+ expect(memList.code, 'member/list: ' + memList.message).toBe(200);
|
|
|
+ const self = pickMemberByUserId(memList.data, parent.userId);
|
|
|
+ expect(self, 'parent 自身成员记录').toBeTruthy();
|
|
|
+ const addA = await apiPost(request, '/api/family/member/add', {
|
|
|
+ relativeMemberId: self.id, generationLevel: 'child',
|
|
|
+ nickname: 'P15-A' + uniqueSuffix(), gender: 'male', birthday: '2015-06-01',
|
|
|
+ }, parent.token);
|
|
|
+ expect(addA.code, 'member/add childA: ' + addA.message).toBe(200);
|
|
|
+ childA = addA.data.id;
|
|
|
+ const addB = await apiPost(request, '/api/family/member/add', {
|
|
|
+ relativeMemberId: self.id, generationLevel: 'child',
|
|
|
+ nickname: 'P15-B' + uniqueSuffix(), gender: 'female', birthday: '2014-09-09',
|
|
|
+ }, parent.token);
|
|
|
+ expect(addB.code, 'member/add childB: ' + addB.message).toBe(200);
|
|
|
+ childB = addB.data.id;
|
|
|
+
|
|
|
+ // 正流水载体:完成 2 款启用小游戏(探针 r3:启用 3 款,score=80 → pointsEarned 7/10)
|
|
|
+ const games = await apiPost(request, '/api/mini-game/list', {}, parent.token);
|
|
|
+ expect(games.code, 'mini-game/list: ' + games.message).toBe(200);
|
|
|
+ const codes = ((games.data || []).map((g) => g.gameCode) || []).filter(Boolean);
|
|
|
+ const plan = [];
|
|
|
+ if (codes.length >= 2) { plan.push(codes[0], codes[1]); }
|
|
|
+ else if (codes.length === 1) { plan.push(codes[0], codes[0]); }
|
|
|
+ c1 = { code: 0, data: {} };
|
|
|
+ c2 = { code: 0, data: {} };
|
|
|
+ doneCount = 0;
|
|
|
+ for (let i = 0; i < plan.length; i++) {
|
|
|
+ const r = await apiPost(request, '/api/mini-game/complete', {
|
|
|
+ memberId: childA, gameCode: plan[i], completionTime: 30, score: 80,
|
|
|
+ }, parent.token);
|
|
|
+ if (i === 0) c1 = r; else c2 = r;
|
|
|
+ if (r.code === 200 && r.data && r.data.pointsEarned > 0) doneCount++;
|
|
|
+ }
|
|
|
+ });
|
|
|
+
|
|
|
+ function noGamesGate() {
|
|
|
+ test.skip(doneCount === 0, '无启用小游戏或小游戏完成全部失败(环境门禁,不造绿):mini-game/list 为空或 complete 非 200');
|
|
|
+ }
|
|
|
+
|
|
|
+ // ============ SC-P-15 积分明细查看(TC-P-15-N/-E/-P) ============
|
|
|
+
|
|
|
+ test('TC-P-15-N 正常: 明细分页(total/pages/降序/来源名映射)', async ({ request }) => {
|
|
|
+ noGamesGate();
|
|
|
+ const p1 = await apiPost(request, '/api/points/logs', { memberId: childA, page: 1, size: 1 }, parent.token);
|
|
|
+ expect(p1.code, 'logs page1: ' + p1.message).toBe(200);
|
|
|
+ expect(p1.data.total, '总数=完成流水条数').toBe(doneCount);
|
|
|
+ expect(p1.data.pages).toBe(doneCount);
|
|
|
+ expect(p1.data.current).toBe(1);
|
|
|
+ expect(p1.data.records.length).toBe(1);
|
|
|
+ const r1 = p1.data.records[0];
|
|
|
+ // 来源名映射:earn+task → 「完成任务」(S-cfc-482 enrichSourceNames)
|
|
|
+ expect(r1.sourceName, 'sourceName 映射为可读来源名').toBe('完成任务');
|
|
|
+ expect(r1.type).toBe('earn');
|
|
|
+ expect(r1.amount, '流水金额为正').toBeGreaterThan(0);
|
|
|
+ expect(r1.description).toContain('完成游戏');
|
|
|
+ expect(r1.createdAt, '流水含创建时间').toBeTruthy();
|
|
|
+
|
|
|
+ const p2 = await apiPost(request, '/api/points/logs', { memberId: childA, page: 2, size: 1 }, parent.token);
|
|
|
+ expect(p2.code, 'logs page2: ' + p2.message).toBe(200);
|
|
|
+ expect(p2.data.records.length).toBe(1);
|
|
|
+ const r2 = p2.data.records[0];
|
|
|
+ expect(String(r1.id), '两页应为不同流水').not.toBe(String(r2.id));
|
|
|
+ // createdAt 降序(orderByDesc):page1(最新)时间不减于 page2
|
|
|
+ expect(String(r1.createdAt) >= String(r2.createdAt), '明细应按 createdAt 降序').toBe(true);
|
|
|
+ });
|
|
|
+
|
|
|
+ test('TC-P-15-N 正常: 时间筛选(整日边界/未来窗口空/非法值忽略不抛错)', async ({ request }) => {
|
|
|
+ noGamesGate();
|
|
|
+ // [昨天, 今天] 窗口必含刚产生的流水(跨 TZ 确定性:容器本地 2 日跨度覆盖当日 0 点两侧)
|
|
|
+ const inWindow = await apiPost(request, '/api/points/logs', {
|
|
|
+ memberId: childA, page: 1, size: 50, startTime: localDateStr(-1), endTime: localDateStr(0),
|
|
|
+ }, parent.token);
|
|
|
+ expect(inWindow.code, 'logs(时间窗): ' + inWindow.message).toBe(200);
|
|
|
+ expect(inWindow.data.total, '昨天~今天窗口含全部新流水').toBe(doneCount);
|
|
|
+
|
|
|
+ // 未来窗口 → 空
|
|
|
+ const future = await apiPost(request, '/api/points/logs', {
|
|
|
+ memberId: childA, page: 1, size: 50, startTime: localDateStr(1), endTime: localDateStr(2),
|
|
|
+ }, parent.token);
|
|
|
+ expect(future.code).toBe(200);
|
|
|
+ expect(future.data.total, '未来窗口应为 0 条').toBe(0);
|
|
|
+ expect(future.data.records.length).toBe(0);
|
|
|
+
|
|
|
+ // 非法时间值 → 忽略不抛错(parseTimeBoundary 契约:warn 后忽略)
|
|
|
+ const bad = await apiPost(request, '/api/points/logs', {
|
|
|
+ memberId: childA, page: 1, size: 50, startTime: 'not-a-date',
|
|
|
+ }, parent.token);
|
|
|
+ expect(bad.code, '非法时间筛选应 200(忽略非法值)').toBe(200);
|
|
|
+ expect(bad.data.total, '非法值忽略后按全量返回').toBe(doneCount);
|
|
|
+ });
|
|
|
+
|
|
|
+ test('TC-P-15-E 异常: 空明细(新成员 total=0/records 空/pages=0,余额零值齐全)', async ({ request }) => {
|
|
|
+ const empty = await apiPost(request, '/api/points/logs', { memberId: childB, page: 1, size: 10 }, parent.token);
|
|
|
+ expect(empty.code, 'logs(空成员): ' + empty.message).toBe(200);
|
|
|
+ expect(empty.data.total).toBe(0);
|
|
|
+ expect(empty.data.records.length, '空明细 records 为空数组').toBe(0);
|
|
|
+ expect(empty.data.pages).toBe(0);
|
|
|
+
|
|
|
+ const bal = await apiPost(request, '/api/points/balance', { memberId: childB }, parent.token);
|
|
|
+ expect(bal.code, 'balance: ' + bal.message).toBe(200);
|
|
|
+ expect(bal.data.balance, '新成员余额 0').toBe(0);
|
|
|
+ expect(bal.data.totalPoints).toBe(0);
|
|
|
+ expect(bal.data.expireDate, '余额含过期日').toBeTruthy();
|
|
|
+ });
|
|
|
+
|
|
|
+ test.fixme('TC-P-15-P 承袭: 越权/匿名查他家庭明细被拒(G-304-1 族新增点位:/api/points/** 无家庭守卫+免登录)', async ({ request }) => {
|
|
|
+ // 转绿条件:越权(outsider)与匿名(无 token)调 /api/points/logs 均 401/403 拒绝且他家庭流水不可见。
|
|
|
+ // 现状(探针 r3 实测):越权 200 返回他家庭真实流水(total=2 含 description);
|
|
|
+ // 匿名(无 token)亦 200 返回同数据(/api/points/** 不在 LOGIN_REQUIRED_PATHS,setAnonymousUser 放行)。
|
|
|
+ noGamesGate();
|
|
|
+ const x = await apiPost(request, '/api/points/logs', { memberId: childA, page: 1, size: 50 }, outsider.token);
|
|
|
+ expect([401, 403].indexOf(x.code), '越权查明细应 401/403 拒绝(实 ' + x.code + ')').toBeGreaterThan(-1);
|
|
|
+ const anon = await apiPost(request, '/api/points/logs', { memberId: childA, page: 1, size: 50 }, undefined);
|
|
|
+ expect([401, 403].indexOf(anon.code), '匿名查明细应 401/403 拒绝(实 ' + anon.code + ')').toBeGreaterThan(-1);
|
|
|
+ });
|
|
|
+
|
|
|
+ // ============ SC-P-16 积分流水对账(TC-P-16-N/-E/-P) ============
|
|
|
+
|
|
|
+ test('TC-P-16-N 正常: 总额=流水合计(balance==Σ流水,完成回显链自洽)', async ({ request }) => {
|
|
|
+ noGamesGate();
|
|
|
+ // 全量拉流水求和(对账口径:账面 total_points vs points_logs 代数和)
|
|
|
+ let logSum = 0;
|
|
|
+ let page = 1;
|
|
|
+ let guard = 0;
|
|
|
+ while (guard < 10) {
|
|
|
+ const pg = await apiPost(request, '/api/points/logs', { memberId: childA, page, size: 50 }, parent.token);
|
|
|
+ expect(pg.code, 'logs page' + page + ': ' + pg.message).toBe(200);
|
|
|
+ const rs = pg.data.records || [];
|
|
|
+ for (const r of rs) { logSum += (r.amount || 0); if (r.amount < 0) { /* 负流水计入代数和 */ } }
|
|
|
+ guard++;
|
|
|
+ if (rs.length < 50 || rs.length * page >= (pg.data.total || 0)) break;
|
|
|
+ page++;
|
|
|
+ }
|
|
|
+ const bal = await apiPost(request, '/api/points/balance', { memberId: childA }, parent.token);
|
|
|
+ expect(bal.code, 'balance: ' + bal.message).toBe(200);
|
|
|
+ // 完成回显链(newBalance 从 0 起累加)自洽
|
|
|
+ expect(c1.data.newBalance, '首笔完成 newBalance=pointsEarned(新成员 0 起)').toBe(c1.data.pointsEarned);
|
|
|
+ expect(c2.data.newBalance, '第二笔 newBalance 累加自洽').toBe(c1.data.newBalance + c2.data.pointsEarned);
|
|
|
+ // 对账恒等式
|
|
|
+ expect(bal.data.balance, '账面余额').toBe(c2.data.newBalance);
|
|
|
+ expect(logSum, '流水合计=账面余额(总额=流水合计)').toBe(bal.data.balance);
|
|
|
+ });
|
|
|
+
|
|
|
+ test.fixme('TC-P-16-E 承袭: 负流水(删除/回退)存在且对账报警暴露(负流水无 API 载体,reconcile 无端点)', async ({ request }) => {
|
|
|
+ // 转绿条件:存在可产出负 points_logs 的载体(任务回退/删除负流水,B-275-1 修复后)
|
|
|
+ // + 对账报警暴露(reconcile 端点/字段:consistent=false 时 alert),且总额仍=流水合计。
|
|
|
+ // 现状(探针 r1/r3 实测):/api/points/adjust 负值 → 400「家庭主账号密码校验失败」(密码门+CF 账本,
|
|
|
+ // 不写 points_logs);tasks/create 稳定 500(B-275-1)阻塞任务 penalty/回退负流水;
|
|
|
+ // service 层 PointsService.reconcile(balance/logSum/consistent/alert/negativeCount)无 HTTP 端点、无报警动作。
|
|
|
+ const adj = await apiPost(request, '/api/points/adjust', {
|
|
|
+ memberId: childA, amount: -1, reason: '负流水载体探测',
|
|
|
+ }, parent.token);
|
|
|
+ expect(adj.code, '负值 adjust 应可产出负流水(实 400 密码门/CF 账本,非 points_logs 载体)').toBe(200);
|
|
|
+ const neg = await apiPost(request, '/api/points/logs', { memberId: childA, page: 1, size: 50 }, parent.token);
|
|
|
+ const negRecs = ((neg.data && neg.data.records) || []).filter((r) => r.amount < 0);
|
|
|
+ expect(negRecs.length, '应存在负流水(amount<0)').toBeGreaterThan(0);
|
|
|
+ });
|
|
|
+
|
|
|
+ test.fixme('TC-P-16-P 承袭: 越权查他家庭流水/余额被拒(G-304-1 族:/api/points/balance·logs 无家庭守卫)', async ({ request }) => {
|
|
|
+ // 转绿条件:越权(outsider)调 /api/points/balance、/api/points/logs 均 401/403 拒绝。
|
|
|
+ // 现状(探针 r3 实测):越权 balance 200 返回他家庭真实余额(17);logs 200 返回其全部流水。
|
|
|
+ noGamesGate();
|
|
|
+ const xBal = await apiPost(request, '/api/points/balance', { memberId: childA }, outsider.token);
|
|
|
+ expect([401, 403].indexOf(xBal.code), '越权查余额应 401/403 拒绝(实 ' + xBal.code + ')').toBeGreaterThan(-1);
|
|
|
+ const xLogs = await apiPost(request, '/api/points/logs', { memberId: childA, page: 1, size: 50 }, outsider.token);
|
|
|
+ expect([401, 403].indexOf(xLogs.code), '越权查流水应 401/403 拒绝(实 ' + xLogs.code + ')').toBeGreaterThan(-1);
|
|
|
+ });
|
|
|
+});
|