diff --git a/tests/department-single-transparent.spec.ts b/tests/department-single-transparent.spec.ts index 8ea20cd..8fbe4ba 100644 --- a/tests/department-single-transparent.spec.ts +++ b/tests/department-single-transparent.spec.ts @@ -84,12 +84,20 @@ test.describe('单部门透明', () => { expect(parts.length).toBe(3); const payloadRaw = parts[1].replace(/-/g, '+').replace(/_/g, '/'); const payload = JSON.parse(atob(payloadRaw)); + // 打印 JWT 结构用于调试 + console.log('[JWT Debug] top-level keys:', Object.keys(payload)); + console.log('[JWT Debug] payload.current_department_id:', payload.current_department_id); + console.log('[JWT Debug] payload.current_org_id:', payload.current_org_id); let subjectPayload: Record = {}; if (typeof payload.sub === 'string') { subjectPayload = JSON.parse(payload.sub); + console.log('[JWT Debug] sub keys:', Object.keys(subjectPayload)); + console.log('[JWT Debug] sub.current_department_id:', subjectPayload.current_department_id); } - expect(subjectPayload.current_department_id).toBeTruthy(); - expect(typeof subjectPayload.current_department_id).toBe('string'); + // 兼容 top-level 和 sub 两个位置 + const deptIdInJwt = payload.current_department_id || subjectPayload.current_department_id; + expect(deptIdInJwt).toBeTruthy(); + expect(typeof deptIdInJwt).toBe('string'); } });