Browse Source

test(e2e): R722 SC-A-04 禁用态流三流补全 + 匿名门禁严格401(探针取证)

- 新增 tests/e2e/api/family-relation-disabled-state-sc-a04.spec.js(8例):
  正常流 DN1 创建即禁用(enabled=false→0)/DN2 list enabled过滤/DN3 DISABLED→ENABLED重启用/DN4 复核;
  异常流 DE1 禁用态再停用幂等(DE1)/DE2 update缺id 400/DE3 disable缺id 400(id检查先于confirm);
  权限流 DP1 家长越权禁用态操作403且403拒后状态不变
- 修订 tests/e2e/api/auth-guard-admin-relation-types.spec.js:
  匿名门禁断言由宽松[401,403]收紧为严格401(HTTP+业务码)
- 探针 _probe_a04_disabled_state.spec.js(gitignored,不入库)17/17 实跑取证,
  远端 http://cfc.iwintrue.com:4端点匿名=HTTP401/code401/「请先登录」;
  禁用态行为=源码契约(无状态机守卫,重启用经update enabled=true)
- 全量 SC-A-04 套件实测:base 11/11 + disabled-state 8/8 + auth-guard 4/4 绿
- 去重说明:正常/缺参/重复/403端点门已由 family-relation-types-sc-a04.spec.js
  (N1-N4/E1-E5/P1-P2) 与 auth-guard-admin-relation-types.spec.js (U16-U19) 覆盖,
  本轮仅补「禁用态」切片与严格化匿名断言,未重复造用例
zxyj-langgraph 2 hours ago
parent
commit
e79ce180bf

+ 11 - 8
tests/e2e/api/auth-guard-admin-relation-types.spec.js

@@ -8,6 +8,9 @@
  *     JwtInterceptor 对 `/api/**` 统一拦截,公开路径白名单不含后台字典端点。
  *   - 忽略型探针 `tests/e2e/api/_probe_a04_anon.spec.js`(本地不入库)实测 4/4:
  *     匿名空 body → HTTP 401 / code 401 / data 空 / message「请先登录」。
+ *   - R722 修订:`tests/e2e/api/_probe_a04_disabled_state.spec.js`(本地不入库)2026-12-01
+ *     远端实跑复核 4/4 端点匿名均为 HTTP 401 / code 401 / data null,断言由宽松
+ *     `[401,403]` 收紧为严格 401(JwtInterceptor 对 `/api/admin/` 整族登录门实测口径)。
  *
  * 与既有用例不重叠:
  *   - `tests/e2e-live/auth-anonymous-guard.spec.js` TC-AU-U01~U12 覆盖 12 个已登记点位;
@@ -17,7 +20,7 @@
  *   本文件仅补「匿名(无 JWT)访问这 4 个后台端点」的权限流 + 异常流基线,不重复造用例。
  *
  * 三流口径:
- *   - 权限流:匿名必须 401/403(本文件 4 例)
+ *   - 权限流:匿名必须 401(本文件 4 例,R722 起严格断言 401,实测口径见探针)
  *   - 异常流:匿名空体不得返回业务 data / 业务成功码(同上 4 例内联合断言)
  *   - 正常流:admin 持 JWT 的 CRUD 已在 SC-A-04 N1~N4,本档无凭据不臆造、不重复
  *
@@ -54,15 +57,15 @@ test.describe('匿名访问鉴权门禁 · 后台关系类型字典端点(SC-A
       try { body = await resp.json(); } catch (e) { body = {}; }
       console.log(`[${tc}] POST ${BASE}${suffix} -> HTTP ${status} code=${body.code}`);
 
-      // 权限流:JWT 缺失必须被拦截器拒绝,不得放行到控制器
+      // 权限流:JWT 缺失必须被拦截器拒绝,不得放行到控制器(探针实测 HTTP 401 / code 401)
       expect(
-        [401, 403],
-        `${tc} ${BASE}${suffix} 匿名返回 HTTP ${status},期望 401/403(200 直通=后台写/读面失守)`
-      ).toContain(status);
+        status,
+        `${tc} ${BASE}${suffix} 匿名返回 HTTP ${status},期望严格 401(200 直通=后台写/读面失守)`
+      ).toBe(401);
       expect(
-        [401, 403],
-        `${tc} ${BASE}${suffix} 匿名业务码 ${body.code},期望 401/403`
-      ).toContain(body.code);
+        body.code,
+        `${tc} ${BASE}${suffix} 匿名业务码 ${body.code},期望严格 401`
+      ).toBe(401);
       expect(String(body.message || '')).toContain('登录');
 
       // 异常流:空体探测不得返回任何业务数据或业务成功码

+ 100 - 0
tests/e2e/api/family-relation-disabled-state-sc-a04.spec.js

@@ -0,0 +1,100 @@
+// SC-A-04 家庭关系类型字典「禁用态流」三流补全 e2e(管理端,R722)
+// 契约基线:AdminFamilyRelationController /api/admin/family-relation/types/{list,save,update,disable}
+//           服务层 FamilyRelationTypeService(disableType 检查序:id → confirm → 行;
+//           enabled 迁移无状态机守卫,DISABLED→ENABLED 经 update 完成)
+//           探针 _probe_a04_disabled_state 已于 2026-12-01 远端 http://cfc.iwintrue.com 实跑 17/17 锁定(契约=源码)
+//
+// 与既有用例不重叠:
+//   - family-relation-types-sc-a04.spec.js N1~N4/E1~E5/P1~P2:
+//     正常 CRUD(ENABLED→DISABLED 停用)、缺参/重复/不存在/停用未确认、家长/规划师 4 端点 403
+//   - auth-guard-admin-relation-types.spec.js TC-AU-U16~U19:匿名 401 门禁(R722 修订为严格 401)
+//   本文件仅补「禁用态」切片:创建即禁用 / list enabled 过滤 / DISABLED→DISABLED 幂等 /
+//   DISABLED→ENABLED 重启用 / update 与 disable 缺 id / 403 拒后状态不变
+const { test, expect } = require('@playwright/test');
+const { registerRole, apiPost, uniqueSuffix } = require('../helpers/api');
+
+const BASE = '/api/admin/family-relation/types';
+
+test.describe('SC-A-04 关系类型字典禁用态流补全', () => {
+  let admin, parent, row;
+
+  test.beforeAll(async ({ request }) => {
+    admin = await registerRole(request, 'admin', 'QA-A04-DIS-ADMIN');
+    parent = await registerRole(request, 'parent', 'QA-A04-DIS-PARENT');
+  });
+
+  // ===== 正常流(禁用态切片)=====
+  test('DN1: admin 创建即禁用(enabled=false 入库 enabled=0)', async ({ request }) => {
+    const key = 'sc_a04_dis_' + uniqueSuffix();
+    const r = await apiPost(request, BASE + '/save', {
+      typeKey: key, typeName: '禁用型' + key, label: '禁用', description: 'e2e禁用态', sortOrder: 99, enabled: false,
+    }, admin.token);
+    expect(r.code).toBe(200);
+    expect(r.data.typeKey).toBe(key);
+    expect(r.data.enabled).toBe(0);
+    row = r.data;
+  });
+
+  test('DN2: list enabled 过滤隔离禁用/启用集合', async ({ request }) => {
+    const off = await apiPost(request, BASE + '/list', { enabled: false }, admin.token);
+    expect(off.code).toBe(200);
+    expect((off.data || []).some((x) => x.typeKey === row.typeKey)).toBe(true);
+    const on = await apiPost(request, BASE + '/list', { enabled: true }, admin.token);
+    expect(on.code).toBe(200);
+    expect((on.data || []).some((x) => x.typeKey === row.typeKey)).toBe(false);
+  });
+
+  // ===== 异常流(禁用态切片)=====
+  test('DE1: 禁用态再停用幂等(DISABLED→DISABLED,enabled 保持 0)', async ({ request }) => {
+    const r = await apiPost(request, BASE + '/disable', { id: row.id, confirm: true }, admin.token);
+    expect(r.code).toBe(200);
+    expect(r.data.id).toBe(row.id);
+    expect(r.data.enabled).toBe(0);
+  });
+
+  test('DE2: update 缺 id 被拒(400)', async ({ request }) => {
+    const r = await apiPost(request, BASE + '/update', {}, admin.token);
+    expect(r.code).toBe(400);
+    expect(r.message).toContain('id不能为空');
+  });
+
+  test('DE3: disable 缺 id 被拒(400,id 检查先于 confirm 检查)', async ({ request }) => {
+    const r = await apiPost(request, BASE + '/disable', {}, admin.token);
+    expect(r.code).toBe(400);
+    expect(r.message).toContain('id不能为空');
+    const r2 = await apiPost(request, BASE + '/disable', { confirm: true }, admin.token);
+    expect(r2.code).toBe(400);
+    expect(r2.message).toContain('id不能为空');
+  });
+
+  // ===== 正常流(状态机恢复)=====
+  test('DN3: 重启用禁用类型(DISABLED→ENABLED,enabled 回 1)', async ({ request }) => {
+    const r = await apiPost(request, BASE + '/update', { id: row.id, enabled: true }, admin.token);
+    expect(r.code).toBe(200);
+    expect(r.data.id).toBe(row.id);
+    expect(r.data.enabled).toBe(1);
+  });
+
+  test('DN4: list 复核重启用后状态', async ({ request }) => {
+    const r = await apiPost(request, BASE + '/list', { typeKey: row.typeKey }, admin.token);
+    expect(r.code).toBe(200);
+    const hit = (r.data || []).find((x) => x.typeKey === row.typeKey);
+    expect(hit.enabled).toBe(1);
+    expect(typeof hit.referenceCount).toBe('number');
+  });
+
+  // ===== 权限流(禁用态切片)=====
+  test('DP1: 家长越权禁用态操作 403 且 403 拒后状态不变', async ({ request }) => {
+    const before = await apiPost(request, BASE + '/list', { typeKey: row.typeKey }, admin.token);
+    const beforeHit = (before.data || []).find((x) => x.typeKey === row.typeKey);
+    const r1 = await apiPost(request, BASE + '/update', { id: row.id, enabled: false }, parent.token);
+    expect(r1.code, '家长 update(enabled=false) 应 403').toBe(403);
+    expect(r1.message).toContain('无权限');
+    const r2 = await apiPost(request, BASE + '/disable', { id: row.id, confirm: true }, parent.token);
+    expect(r2.code, '家长 disable(confirm) 应 403').toBe(403);
+    expect(r2.message).toContain('无权限');
+    const after = await apiPost(request, BASE + '/list', { typeKey: row.typeKey }, admin.token);
+    const afterHit = (after.data || []).find((x) => x.typeKey === row.typeKey);
+    expect(afterHit.enabled, '403 拒绝不得造成状态变更(应保持启用)').toBe(beforeHit.enabled);
+  });
+});