Browse Source

test(cfc-e2e): SC-C-26 睡眠打卡记录三流用例(远程 cfc.iwintrue.com 实测:正常/异常绿 + 权限缺陷 expected-fail)

- 正常流:create(HH:mm)+list 200 绿;异常流:缺 sleepTime→500 绿
- 权限流:无 token list 应 401,实测 200 泄露(sleep/** 未纳入 LOGIN_REQUIRED_PATHS,承袭缺陷,expected-fail)
- 真实契约来源:远程探针 _probe_c26_v2(untracked,已删)
- 修正轮:早前 23:37 报告误判后端未启动,经用户校正测试目标=cfc.iwintrue.com
E2E Test Bot 2 hours ago
parent
commit
e12e9bfc35
1 changed files with 69 additions and 0 deletions
  1. 69 0
      tests/e2e/api/sleep-checkin-sc-c26.spec.js

+ 69 - 0
tests/e2e/api/sleep-checkin-sc-c26.spec.js

@@ -0,0 +1,69 @@
+/**
+ * 睡眠打卡记录 (SC-C-26) 三流断言
+ * 
+ * 真实契约来源(2026-11-28 远程 cfc.iwintrue.com 探针 _probe_c26_v2 实跑锁定):
+ *   1. 正常流:sleepTime/wakeTime 用 HH:mm 格式 → create 200 success(data.sleepTime=22:30:00);list 200 count>=1
+ *   2. 异常流:缺 sleepTime → code=500 "请选择入睡时间"(business error,非 400)
+ *   3. 权限流(已知缺陷·承袭):无 token list → 实测 200(数据泄露),应为 401;
+ *      对照兄弟接口 /api/health/checkin/list 无 token → 401(已强制登录)。
+ *      根因:HealthSleepController /api/health/sleep/** 未纳入 JwtInterceptor.LOGIN_REQUIRED_PATHS
+ *      (对比 /api/health/checkin/ 已在列)。
+ * 另注:SC-A-27 睡眠情况选项后台 CRUD 全部候选端点 404(远程未部署),本 spec 仅覆盖记录契约,
+ *       选项配置缺口承袭·真实缺陷未修,不为缺陷造绿。
+ */
+const { test, expect } = require('@playwright/test');
+const { registerRole, apiPost, uniqueSuffix, pickMemberByUserId } = require('../helpers/api');
+
+test.describe('sleep-checkin-sc-c26 · 睡眠打卡记录三流', () => {
+  // 1) 正常流:create(HH:mm) 200 + list 200 count>=1
+  test('TC-C26-01 正常流: 正常时间格式 create 并 list 200', async ({ request }) => {
+    const parent = await registerRole(request, 'parent', 'QA-SC26');
+    const mem = await apiPost(request, '/api/family/member/list', {}, parent.token);
+    const self = pickMemberByUserId(mem.data, parent.userId);
+    const child = await apiPost(request, '/api/family/member/add', {
+      relativeMemberId: self.id, generationLevel: 'child',
+      nickname: 'C26-' + uniqueSuffix(), gender: 'female', birthday: '2016-07-01',
+    }, parent.token);
+    expect(child.code, 'member/add: ' + child.message).toBe(200);
+    const childId = child.data.id;
+
+    const create = await apiPost(request, '/api/health/sleep/create', {
+      memberId: childId, sleepTime: '22:30', wakeTime: '07:00',
+      durationMinutes: 510, qualityScore: 85, remark: '正常',
+    }, parent.token);
+    expect(create.code, 'create: ' + create.message).toBe(200);
+    expect(create.data).toBeTruthy();
+    expect(create.data.sleepTime).toBe('22:30:00');
+
+    const list = await apiPost(request, '/api/health/sleep/list', { memberId: childId }, parent.token);
+    expect(list.code, 'list: ' + list.message).toBe(200);
+    expect(Array.isArray(list.data)).toBe(true);
+    expect(list.data.length).toBeGreaterThanOrEqual(1);
+  });
+
+  // 2) 异常流:缺 sleepTime → 500 "请选择入睡时间"
+  test('TC-C26-02 异常流: 缺 sleepTime → 500 业务错误', async ({ request }) => {
+    const parent = await registerRole(request, 'parent', 'QA-SC26');
+    const mem = await apiPost(request, '/api/family/member/list', {}, parent.token);
+    const self = pickMemberByUserId(mem.data, parent.userId);
+    const child = await apiPost(request, '/api/family/member/add', {
+      relativeMemberId: self.id, generationLevel: 'child',
+      nickname: 'C26-' + uniqueSuffix(), gender: 'female', birthday: '2016-07-01',
+    }, parent.token);
+    const childId = child.data.id;
+
+    const missing = await apiPost(request, '/api/health/sleep/create', {
+      memberId: childId, wakeTime: '07:00',
+    }, parent.token);
+    expect(missing.code, 'missing sleepTime → 应业务 500: ' + missing.message).toBe(500);
+    expect(missing.message).toBe('请选择入睡时间');
+  });
+});
+
+// 3) 权限流(已知缺陷·承袭):真正无 token(不携带 Authorization 头)list 应 401,
+//    实测 200(泄露睡眠记录)→ 标记 expected-fail(真实缺陷)
+test.fail('TC-C26-03 权限流(已知缺陷): 无 token list 应 401,实测 200 泄露', async ({ request }) => {
+  // token=undefined → apiPost 不注入 Authorization 头 → 真正匿名
+  const list = await apiPost(request, '/api/health/sleep/list', { memberId: 18978 }, undefined);
+  expect(list.code).toBe(401); // 期望 401,实测 200 → 标记 expected-fail(真实缺陷)
+});