|
| 1 | +/** |
| 2 | + * @vitest-environment node |
| 3 | + */ |
| 4 | +import { describe, expect, it } from 'vitest' |
| 5 | +import { phoneNumberEnrichment } from '@/enrichments/phone-number/phone-number' |
| 6 | +import type { EnrichmentProvider } from '@/enrichments/types' |
| 7 | + |
| 8 | +function provider(id: string): EnrichmentProvider { |
| 9 | + const p = phoneNumberEnrichment.providers.find((x) => x.id === id) |
| 10 | + if (!p) throw new Error(`Provider ${id} not found in phone-number cascade`) |
| 11 | + return p |
| 12 | +} |
| 13 | + |
| 14 | +const inputs = { fullName: 'John Doe', companyDomain: 'https://www.acme.com/careers' } |
| 15 | + |
| 16 | +describe('phone-number enrichment cascade', () => { |
| 17 | + it('chains PDL then the phone-capable hosted providers', () => { |
| 18 | + expect(phoneNumberEnrichment.providers.map((p) => p.id)).toEqual(['pdl', 'wiza', 'prospeo']) |
| 19 | + }) |
| 20 | + |
| 21 | + describe('wiza', () => { |
| 22 | + const p = provider('wiza') |
| 23 | + it('reveals phone (5 credits) and maps mobile_phone/phones', () => { |
| 24 | + expect(p.toolId).toBe('wiza_individual_reveal') |
| 25 | + expect(p.buildParams(inputs)).toEqual({ |
| 26 | + full_name: 'John Doe', |
| 27 | + domain: 'acme.com', |
| 28 | + enrichment_level: 'phone', |
| 29 | + }) |
| 30 | + expect(p.mapOutput({ mobile_phone: '+1555', phones: [] })).toEqual({ phone: '+1555' }) |
| 31 | + expect(p.mapOutput({ phones: [{ number: '+1777' }] })).toEqual({ phone: '+1777' }) |
| 32 | + expect(p.mapOutput({ mobile_phone: null, phone_number: null, phones: [] })).toBeNull() |
| 33 | + }) |
| 34 | + it('skips without a company domain', () => { |
| 35 | + expect(p.buildParams({ fullName: 'John Doe', companyDomain: '' })).toBeNull() |
| 36 | + }) |
| 37 | + }) |
| 38 | + |
| 39 | + describe('prospeo', () => { |
| 40 | + const p = provider('prospeo') |
| 41 | + it('requests mobile enrichment and maps person.mobile.mobile', () => { |
| 42 | + expect(p.toolId).toBe('prospeo_enrich_person') |
| 43 | + expect(p.buildParams(inputs)).toEqual({ |
| 44 | + full_name: 'John Doe', |
| 45 | + company_website: 'acme.com', |
| 46 | + enrich_mobile: true, |
| 47 | + }) |
| 48 | + expect(p.mapOutput({ person: { mobile: { mobile: '+1555', status: 'VERIFIED' } } })).toEqual({ |
| 49 | + phone: '+1555', |
| 50 | + }) |
| 51 | + expect(p.mapOutput({ person: { mobile: { mobile: '' } } })).toBeNull() |
| 52 | + }) |
| 53 | + it('skips without a company domain', () => { |
| 54 | + expect(p.buildParams({ fullName: 'John Doe', companyDomain: '' })).toBeNull() |
| 55 | + }) |
| 56 | + }) |
| 57 | +}) |
0 commit comments