fix(department): 兼容 JWT current_department_id 可能位于 top-level 或 sub 两种位置

添加 JWT 结构日志便于调试 CI 失败

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
2026-05-02 19:23:01 +08:00
parent 5a1effd521
commit 5a1d903ffc
+10 -2
View File
@@ -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<string, unknown> = {};
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');
}
});