@@ -137,60 +137,60 @@ describe('hunter email_finder', () => {
137137describe ( 'hunter discover' , ( ) => {
138138 const transform = discoverTool . transformResponse !
139139
140- it ( 'maps companies array (not data.data) ' , async ( ) => {
140+ it ( 'maps documented data array shape ' , async ( ) => {
141141 const result = await transform (
142142 respond ( {
143- companies : [
143+ data : [
144144 {
145- name : 'Stripe' ,
146- domain : 'stripe.com' ,
147- logo : 'https://logo.png' ,
148- linkedin_url : 'https://linkedin.com/company/stripe' ,
149- company_type : 'Privately Held' ,
150- meta : {
151- industry : 'Fintech' ,
152- size : '1000+' ,
153- location : 'San Francisco, CA' ,
154- founded_year : 2010 ,
155- crunchbase_url : 'https://crunchbase.com/org/stripe' ,
156- } ,
145+ domain : 'hunter.io' ,
146+ organization : 'Hunter' ,
147+ emails_count : { personal : 23 , generic : 5 , total : 28 } ,
157148 } ,
158149 ] ,
159150 } )
160151 )
161152
162- expect ( result . output . results ) . toHaveLength ( 1 )
163- expect ( result . output . results [ 0 ] ) . toEqual ( {
164- name : 'Stripe' ,
165- domain : 'stripe.com' ,
166- logo : 'https://logo.png' ,
167- linkedin_url : 'https://linkedin.com/company/stripe' ,
168- company_type : 'Privately Held' ,
169- industry : 'Fintech' ,
170- size : '1000+' ,
171- location : 'San Francisco, CA' ,
172- founded_year : 2010 ,
173- crunchbase_url : 'https://crunchbase.com/org/stripe' ,
174- } )
153+ expect ( result . output . results ) . toEqual ( [
154+ {
155+ domain : 'hunter.io' ,
156+ organization : 'Hunter' ,
157+ personal_emails : 23 ,
158+ generic_emails : 5 ,
159+ total_emails : 28 ,
160+ } ,
161+ ] )
175162 } )
176163
177- it ( 'returns empty array when companies is missing' , async ( ) => {
164+ it ( 'returns empty array when data is missing' , async ( ) => {
178165 const result = await transform ( respond ( { } ) )
179166 expect ( result . output . results ) . toEqual ( [ ] )
180167 } )
181168
169+ it ( 'falls back to zero counts when emails_count is missing' , async ( ) => {
170+ const result = await transform (
171+ respond ( { data : [ { domain : 'acme.com' , organization : 'Acme' } ] } )
172+ )
173+ expect ( result . output . results [ 0 ] ) . toEqual ( {
174+ domain : 'acme.com' ,
175+ organization : 'Acme' ,
176+ personal_emails : 0 ,
177+ generic_emails : 0 ,
178+ total_emails : 0 ,
179+ } )
180+ } )
181+
182182 it ( 'throws when no search params provided' , ( ) => {
183183 const buildUrl = discoverTool . request . url as ( p : Record < string , unknown > ) => string
184184 expect ( ( ) => buildUrl ( { apiKey : 'k' } ) ) . toThrow ( / A t l e a s t o n e s e a r c h p a r a m e t e r / )
185185 } )
186186
187- it ( 'wraps headcount in include array' , ( ) => {
187+ it ( 'builds body per docs ( headcount as plain array, technology wrapped) ' , ( ) => {
188188 const buildBody = discoverTool . request . body as (
189189 p : Record < string , unknown >
190190 ) => Record < string , unknown >
191191 const body = buildBody ( { apiKey : 'k' , headcount : '11-50' , technology : 'react' } )
192192 expect ( body ) . toEqual ( {
193- headcount : { include : [ '11-50' ] } ,
193+ headcount : [ '11-50' ] ,
194194 technology : { include : [ 'react' ] } ,
195195 } )
196196 } )
@@ -243,6 +243,16 @@ describe('hunter companies_find', () => {
243243 } )
244244 } )
245245
246+ it ( 'prefers employeesRange and coerces numeric employees' , async ( ) => {
247+ const rangeResult = await transform (
248+ respond ( { data : { metrics : { employees : 5432 , employeesRange : '1001-5000' } } } )
249+ )
250+ expect ( rangeResult . output . size ) . toBe ( '1001-5000' )
251+
252+ const numericResult = await transform ( respond ( { data : { metrics : { employees : 5432 } } } ) )
253+ expect ( numericResult . output . size ) . toBe ( '5432' )
254+ } )
255+
246256 it ( 'survives missing nested objects' , async ( ) => {
247257 const result = await transform ( respond ( { data : { } } ) )
248258 expect ( result . output ) . toMatchObject ( {
0 commit comments