文件
OmniCard/backend/test/modules/crm/enrichment.test.ts

79 行
3.2 KiB
TypeScript

import {
LeadCompanyEnrichmentService,
extractDomainFromEmail,
isPublicFreeMailbox,
enrichCompanyProfile,
CompanyProfileResult,
} from '../../../src/modules/crm/service/enrichment';
describe('Point 49: 潜客企业邮箱域名解析与商业主页自动富化', () => {
let service: LeadCompanyEnrichmentService;
beforeEach(() => {
service = new LeadCompanyEnrichmentService();
});
describe('1. 邮箱域名解析与公用免费邮箱过滤 (extractDomainFromEmail & isPublicFreeMailbox)', () => {
it('应正确提取企业邮箱域名', () => {
expect(extractDomainFromEmail('alex@siemens.com')).toBe('siemens.com');
expect(extractDomainFromEmail('tariq@aramco.com.sa')).toBe('aramco.com.sa');
expect(extractDomainFromEmail(' JOHN.DOE@VOLVO.SE ')).toBe('volvo.se');
});
it('非法或无效邮箱应安全返回空字符串', () => {
expect(extractDomainFromEmail('')).toBe('');
expect(extractDomainFromEmail('invalid-email-format')).toBe('');
expect(extractDomainFromEmail(null as any)).toBe('');
});
it('应准确判定常见公用免费邮箱 (Gmail, Hotmail, 163, QQ, Yahoo 等)', () => {
expect(isPublicFreeMailbox('gmail.com')).toBe(true);
expect(isPublicFreeMailbox('yahoo.com')).toBe(true);
expect(isPublicFreeMailbox('outlook.com')).toBe(true);
expect(isPublicFreeMailbox('163.com')).toBe(true);
expect(isPublicFreeMailbox('qq.com')).toBe(true);
// 企业独立域名应判定为 false
expect(isPublicFreeMailbox('bmw.de')).toBe(false);
expect(isPublicFreeMailbox('omnicard.ai')).toBe(false);
});
});
describe('2. enrichCompanyProfile (企业画像与社交网络自动补全)', () => {
it('针对企业域名应提取标准官网、LinkedIn 公司页与品牌展示名称', () => {
const profile = enrichCompanyProfile('faisal@emiratessteel.ae', 'Emirates Steel Arkan');
expect(profile.isEnterpriseDomain).toBe(true);
expect(profile.domain).toBe('emiratessteel.ae');
expect(profile.websiteUrl).toBe('https://emiratessteel.ae');
expect(profile.linkedinCompanyUrl).toBe('https://www.linkedin.com/company/emiratessteel');
expect(profile.brandName).toBe('Emirates Steel Arkan');
});
it('针对免费个人邮箱应标记非企业域名,并提取备用展示', () => {
const profile = enrichCompanyProfile('freelancer2026@gmail.com');
expect(profile.isEnterpriseDomain).toBe(false);
expect(profile.domain).toBe('gmail.com');
expect(profile.websiteUrl).toBeUndefined();
expect(profile.linkedinCompanyUrl).toBeUndefined();
});
});
describe('3. LeadCompanyEnrichmentService 综合线索富化', () => {
it('应能为潜客线索生成完整的企业富化数据对象', async () => {
const enriched = await service.enrichLead({
leadId: 301,
name: 'Carlos Mendez',
email: 'carlos@iberia.es',
company: 'Iberia Airlines',
});
expect(enriched.leadId).toBe(301);
expect(enriched.companyProfile.isEnterpriseDomain).toBe(true);
expect(enriched.companyProfile.domain).toBe('iberia.es');
expect(enriched.suggestedIndustry).toBeDefined();
});
});
});