Files
hose-use/src/domains/contact/contact.test.ts
T
gitea 68d570022d
🚀 Release / 🚀 Build & Publish Multi-Platform Binaries (push) Has been cancelled
feat: release v0.5.2 with protected contact domain and bill web link
2026-09-03 15:58:20 +08:00

53 lines
1.9 KiB
TypeScript

import { describe, expect, test } from "bun:test";
import { StaffSchema, type Staff } from "./types.js";
describe("Contact Domain - 通讯录与人员模型", () => {
test("StaffSchema 正确解析包含 null 字段的员工对象", () => {
const raw = {
id: "corp123:staff456",
name: "测试员工",
email: null,
cellphone: null,
department: null,
};
const parsed = StaffSchema.parse(raw);
expect(parsed.id).toBe("corp123:staff456");
expect(parsed.name).toBe("测试员工");
expect(parsed.email).toBeNull();
});
test("StaffSchema 正确解析完整员工信息", () => {
const raw = {
id: "corp123:staff456",
name: "张三",
email: "zhangsan@example.com",
cellphone: "13800138000",
department: "研发部",
};
const parsed = StaffSchema.parse(raw);
expect(parsed.name).toBe("张三");
expect(parsed.email).toBe("zhangsan@example.com");
expect(parsed.cellphone).toBe("13800138000");
expect(parsed.department).toBe("研发部");
});
test("模糊搜索与过滤逻辑可正确按姓名、邮箱、工号匹配", () => {
const list: Staff[] = [
{ id: "corp:001", name: "王硕", email: "wangshuo@test.com", cellphone: "13911112222" },
{ id: "corp:002", name: "李雨笑", email: "liyuxiao@test.com", cellphone: null },
{ id: "corp:003", name: "谢子豪", email: "xiezihao@test.com", cellphone: "13933334444" },
];
const search = (kw: string) => {
const q = kw.toLowerCase();
return list.filter((s) => s.name.includes(q) || (s.email && s.email.includes(q)) || s.id.includes(q));
};
expect(search("王硕").length).toBe(1);
expect(search("wangshuo").length).toBe(1);
expect(search("003").length).toBe(1);
expect(search("003")[0].name).toBe("谢子豪");
expect(search("不存在").length).toBe(0);
});
});