| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596 |
- /**
- * task-reminders/upcoming/{memberId} 契约守卫(SC-P-65/79 提醒设置域 ·「即将到期提醒」)
- * ================================================================
- * 目标:SC-P-65/79 提醒设置 + /api/task-reminders/upcoming/{memberId} 的 API 契约守卫,
- * 补齐正常/异常/权限三流断言。reminder-config(/api/task/reminder-config/get|save)
- * 三流已由 tests/e2e/api/task-checkin-remind-18211a546.spec.js 覆盖,本轮不重复造用例。
- *
- * 【探针先行·真实契约】(忽略型 _probe_reminder_upcoming.spec.js,gitignore 不入库,无业务断言,
- * 对远端 cfc.iwintrue.com 实测):
- * - 正常流:属主 token POST /api/task-reminders/upcoming/{selfId} body{minutes:60}
- * → status=200 code=200 message=success data=数组(实测空数组)。
- * - 异常流:minutes="abc"(非数字)→ status=200 code=400 message="For input string: \"abc\""
- * (NumberFormatException 未友好化,但拒绝生效);minutes=0/-5/99999 → code=200 data=[]
- * (宽松,不拒绝)。
- * - 权限流:无 token → code=200 data=[](未拒绝);跨家庭他人 memberId → code=200(无归属校验)。
- * 对照组 无 token POST /api/tasks/today → status=401 code=401 "请先登录"
- * (证明登录门本身可用,缺陷在路径登记遗漏)。
- *
- * 【承袭·真实缺陷未修】/api/task-reminders 未列入 JwtInterceptor.LOGIN_REQUIRED_PATHS
- * (仅复数 /api/tasks/ 已登记):匿名被注入 userId=-1 后放行;TaskReminderController 的
- * {memberId} 系列端点(:41 upcoming / :31 reminder / :53 overdue / :63 history / :92 statistics)
- * 完全无 userId 参与、无「调用者家庭 ↔ 成员」归属校验 → 匿名/越权可按 memberId 遍历。
- * 本轮**不为该缺陷造绿用例、不写放水断言**,仅按实测记录契约;权限缺陷部分不设通过断言。
- * 缺陷修复合规路径见 docs/tdd/test-cases/2026-12-01-task-reminder-v3.md §0.4(R-09)。
- *
- * 【硬边界】仅写测试文件;禁 `?.`;禁直接 `new Date(string)`;探针文件保持 gitignore 不入库。
- *
- * 运行:cwd=tests;npx playwright test e2e/api/task-reminder-upcoming-sc-p65-p79.spec.js -c playwright.config.api.js --project=desktop
- */
- const { test, expect } = require('@playwright/test');
- const { registerRole, apiPost, pickMemberByUserId, uniqueSuffix } = require('../helpers/api');
- test.describe('SC-P-65/79 即将到期提醒 upcoming 契约守卫', () => {
- test.describe.configure({ mode: 'serial' });
- let owner; // 属主(本家庭家长)
- let selfId; // owner 自身成员 id
- let other; // 他人家庭家长(越权视角)
- let otherSelfId;
- test.beforeAll(async ({ request }) => {
- owner = await registerRole(request, 'parent', 'QA-UPP' + uniqueSuffix());
- const mem = await apiPost(request, '/api/family/member/list', {}, owner.token);
- const self = pickMemberByUserId(mem.data, owner.userId);
- expect(self && self.id, '应取到属主自身成员 id').toBeTruthy();
- selfId = self.id;
- other = await registerRole(request, 'parent', 'QA-UPX' + uniqueSuffix());
- const memOther = await apiPost(request, '/api/family/member/list', {}, other.token);
- const selfOther = pickMemberByUserId(memOther.data, other.userId);
- expect(selfOther && selfOther.id, '应取到他人自身成员 id').toBeTruthy();
- otherSelfId = selfOther.id;
- });
- // ---------------- 正常流 ----------------
- test('[N 正常] 属主 token → upcoming/{selfId} 返回 200 + 数组', async ({ request }) => {
- const r = await apiPost(request, '/api/task-reminders/upcoming/' + selfId, { minutes: 60 }, owner.token);
- expect(r.status, 'HTTP 应 200: ' + r.message).toBe(200);
- expect(r.code, '业务 code 应 200: ' + r.message).toBe(200);
- expect(Array.isArray(r.data), 'data 应为数组,实际 ' + typeof r.data).toBe(true);
- });
- // ---------------- 异常流(可用部分·严格断言) ----------------
- test('[E1 异常·非数字 minutes] "abc" → 拒绝(code≠200)', async ({ request }) => {
- const r = await apiPost(request, '/api/task-reminders/upcoming/' + selfId, { minutes: 'abc' }, owner.token);
- expect(r.code, '非数字 minutes 应拒绝,实际 code=' + r.code + ' msg=' + r.message).not.toBe(200);
- // 实测契约:NumberFormatException 原样上抛(未友好化),文案含 "For input string"
- expect(String(r.message || ''), '拒绝文案应含 For input string,实际 ' + r.message).toContain('For input string');
- });
- test('[E2 异常·非法 memberId 承袭] 0/-1/999999999 当前 200+空数组(成员校验缺失·记录契约不造绿)', async ({ request }) => {
- // 承袭·真实缺陷未修:TaskReminderController 无成员存在性/归属校验,非法 memberId 返回 200+空数组。
- // 按纪律不为该缺陷造绿(不断言 200 为"正确"),仅实测记录;不写放水断言。
- for (const m of [0, -1, 999999999]) {
- const r = await apiPost(request, '/api/task-reminders/upcoming/' + m, { minutes: 60 }, owner.token);
- console.log('[E2] 承袭·非法 memberId=' + m + ' → status=' + r.status + ' code=' + r.code + ' msg=' + r.message + ' data=' + (Array.isArray(r.data) ? 'array(' + r.data.length + ')' : typeof r.data));
- }
- });
- // ---------------- 权限流(缺陷·承袭,仅记录 + 对照断言) ----------------
- test('[P1 权限·对照] 无 token /api/tasks/today → 401(登录门本身可用)', async ({ request }) => {
- const ctl = await apiPost(request, '/api/tasks/today', {}, null);
- expect(ctl.status, '登录门应 401,实际 ' + ctl.status).toBe(401);
- expect(ctl.code, '登录门 code 应 401').toBe(401);
- });
- test('[P2 权限·匿名/越权 承袭] upcoming 无 token 与跨家庭他人 memberId → 实测 200(缺陷未修·记录不造绿)', async ({ request }) => {
- // 承袭·真实缺陷未修:/api/task-reminders 未登记 LOGIN_REQUIRED_PATHS → 匿名 userId=-1 放行;
- // {memberId} 无归属校验 → 越权可遍历。按纪律不为该缺陷造绿(不写放水断言),仅实测记录。
- const anon = await apiPost(request, '/api/task-reminders/upcoming/' + selfId, { minutes: 60 }, null);
- console.log('[P2] 承袭·匿名 upcoming → status=' + anon.status + ' code=' + anon.code + ' msg=' + anon.message + ' data=' + (Array.isArray(anon.data) ? 'array(' + anon.data.length + ')' : typeof anon.data));
- const cross = await apiPost(request, '/api/task-reminders/upcoming/' + otherSelfId, { minutes: 60 }, owner.token);
- console.log('[P2] 承袭·越权(他人memberId) upcoming → status=' + cross.status + ' code=' + cross.code + ' msg=' + cross.message + ' data=' + (Array.isArray(cross.data) ? 'array(' + cross.data.length + ')' : typeof cross.data));
- });
- });
|