@@ -83,6 +83,72 @@ describe('Icypeas verify-email pricing', () => {
8383 } )
8484} )
8585
86+ describe ( 'Icypeas transformResponse validation errors' , ( ) => {
87+ it ( 'verify-email maps a 200 validationErrors body to a BAD_INPUT verdict' , async ( ) => {
88+ const response = new Response (
89+ JSON . stringify ( {
90+ success : false ,
91+ validationErrors : [
92+ { expected : 'email' , type : 'required' , field : 'email' , message : 'validation_required' } ,
93+ ] ,
94+ } ) ,
95+ { status : 200 , headers : { 'Content-Type' : 'application/json' } }
96+ )
97+
98+ const result = await icypeasVerifyEmailTool . transformResponse ! ( response , {
99+ apiKey : 'test-key' ,
100+ email : 'support@stripe.com' ,
101+ } as any )
102+
103+ expect ( result . success ) . toBe ( true )
104+ expect ( ( result . output as any ) . status ) . toBe ( 'BAD_INPUT' )
105+ expect ( ( result . output as any ) . valid ) . toBe ( false )
106+ expect ( ( result . output as any ) . email ) . toBe ( 'support@stripe.com' )
107+ expect ( ( result . output as any ) . searchId ) . toBeNull ( )
108+ } )
109+
110+ it ( 'find-email maps a 200 validationErrors body to a BAD_INPUT verdict' , async ( ) => {
111+ const response = new Response (
112+ JSON . stringify ( {
113+ success : false ,
114+ validationErrors : [
115+ {
116+ expected : 'string' ,
117+ type : 'required' ,
118+ field : 'domainOrCompany' ,
119+ message : 'validation_required' ,
120+ } ,
121+ ] ,
122+ } ) ,
123+ { status : 200 , headers : { 'Content-Type' : 'application/json' } }
124+ )
125+
126+ const result = await icypeasFindEmailTool . transformResponse ! ( response , {
127+ apiKey : 'test-key' ,
128+ domainOrCompany : 'stripe.com' ,
129+ } as any )
130+
131+ expect ( result . success ) . toBe ( true )
132+ expect ( ( result . output as any ) . status ) . toBe ( 'BAD_INPUT' )
133+ expect ( ( result . output as any ) . email ) . toBeNull ( )
134+ expect ( ( result . output as any ) . searchId ) . toBeNull ( )
135+ } )
136+
137+ it ( 'verify-email still throws when a success body has no item _id' , async ( ) => {
138+ const response = new Response ( JSON . stringify ( { success : true , item : { } } ) , {
139+ status : 200 ,
140+ headers : { 'Content-Type' : 'application/json' } ,
141+ } )
142+
143+ await expect (
144+ icypeasVerifyEmailTool . transformResponse ! ( response , {
145+ apiKey : 'test-key' ,
146+ email : 'jane@example.com' ,
147+ } as any )
148+ ) . rejects . toThrow ( / i t e m _ i d / )
149+ } )
150+ } )
151+
86152describe ( 'Icypeas find-email postProcess poll' , ( ) => {
87153 it ( 'polls the results endpoint until terminal status and returns the email' , async ( ) => {
88154 vi . useFakeTimers ( )
0 commit comments