const { maskEmail, maskExternalUserId, maskPhone, normalizeWecomHrProfile, __testables, } = require("../../src/services/integrations/wecomHrMaster"); describe("wecom HR master sync helpers", () => { it("normalizes contact and HR assistant data without leaking full sensitive values in summary", () => { const departmentMap = new Map([ ["1", { externalId: "1", name: "研发部" }], ]); const profile = normalizeWecomHrProfile({ departmentMap, contact: { userid: "oa_smoke002", name: "测试员工", mobile: "19912345678", email: "smoke002@hyinda.com", position: "测试工程师", department: [1], direct_leader: ["manager001"], enable: 1, }, staff: { staff_info: [ { fieldid: "入职日期", value: "2026-05-01" }, { fieldid: "在职状态", value: "在职" }, ], }, }); expect(profile.externalUserId).toBe("oa_smoke002"); expect(profile.departmentName).toBe("研发部"); expect(profile.managerExternalUserId).toBe("manager001"); expect(profile.hireDate).toBe("2026-05-01"); expect(profile.sourceStatus).toBe("active"); expect(profile.missingRequiredFields).toEqual([]); expect(JSON.stringify(profile.sourceSummary)).not.toContain("19912345678"); expect(JSON.stringify(profile.sourceSummary)).not.toContain("smoke002@hyinda.com"); expect(JSON.stringify(profile.sourceSummary)).not.toContain("oa_smoke002"); }); it("skips profiles missing OA-required source fields", () => { const profile = normalizeWecomHrProfile({ contact: { userid: "missing-email", name: "缺邮箱", mobile: "19900000001", department: [1], }, staff: {}, departmentMap: new Map([["1", { externalId: "1", name: "行政部" }]]), }); expect(profile.missingRequiredFields).toContain("email"); }); it("marks inactive WeCom members as confirmation-required instead of active", () => { const profile = normalizeWecomHrProfile({ contact: { userid: "inactive001", name: "离职测试", mobile: "19900000002", email: "inactive001@hyinda.com", department: [1], enable: 0, }, staff: {}, departmentMap: new Map([["1", { externalId: "1", name: "行政部" }]]), }); expect(profile.sourceStatus).toBe("inactive"); }); it("builds masked field changes for contact fields", () => { const changes = __testables.buildEmployeeChanges( { id: "employee-1", name: "旧员工", phone: "19911112222", email: "old@hyinda.com", department_id: "dept-old", title: "旧岗位", wecom_identity_binding: null, }, { externalUserId: "oa_smoke002", name: "新员工", phone: "19933334444", email: "new@hyinda.com", title: "新岗位", }, { id: "dept-new", name: "研发部" }, ); expect(changes.phone.before).toBe(maskPhone("19911112222")); expect(changes.phone.after).toBe(maskPhone("19933334444")); expect(changes.email.before).toBe(maskEmail("old@hyinda.com")); expect(changes.externalUserId.after).toBe(maskExternalUserId("oa_smoke002")); }); });