@@ -150,6 +150,18 @@ describe('Oracle Eloqua server selector adapter', () => {
150150 expect ( new URL ( String ( mockFetch . mock . calls [ 0 ] ?. [ 0 ] ) ) . pathname ) . toBe ( path )
151151 } )
152152
153+ it ( 'rejects a detail response whose ID differs from the requested asset' , async ( ) => {
154+ mockFetch . mockResolvedValueOnce (
155+ Response . json ( { id : '999' , name : 'Different asset' , type : 'Asset' } )
156+ )
157+
158+ await expect (
159+ eloquaSelectorAttachments [ 'eloqua.forms' ] . execute (
160+ args ( { kind : 'detail' , id : '123' } , 'eloqua.forms' )
161+ )
162+ ) . rejects . toThrow ( 'Options unavailable' )
163+ } )
164+
153165 it ( 'rejects a credential with an unsafe destination before fetching' , async ( ) => {
154166 mockGetCredential . mockResolvedValue ( {
155167 providerId : 'eloqua' ,
@@ -203,15 +215,35 @@ describe('Oracle Eloqua server selector adapter', () => {
203215 expect ( mockFetch ) . not . toHaveBeenCalled ( )
204216 } )
205217
206- it ( 'fails closed on malformed provider responses and forwards cancellation' , async ( ) => {
207- const controller = new AbortController ( )
218+ it ( 'fails closed on malformed provider responses' , async ( ) => {
208219 mockFetch . mockResolvedValueOnce ( Response . json ( { elements : 'not-an-array' } ) )
209220
210221 await expect (
211- eloquaSelectorAttachments [ 'eloqua.emails' ] . execute (
212- args ( { kind : 'list' } , 'eloqua.emails' , controller . signal )
213- )
214- ) . rejects . toThrow ( )
215- expect ( mockFetch . mock . calls [ 0 ] ?. [ 1 ] ?. signal ) . toBeInstanceOf ( AbortSignal )
222+ eloquaSelectorAttachments [ 'eloqua.emails' ] . execute ( args ( { kind : 'list' } , 'eloqua.emails' ) )
223+ ) . rejects . toThrow ( 'Options unavailable' )
224+ } )
225+
226+ it ( 'forwards caller cancellation to the provider request' , async ( ) => {
227+ const controller = new AbortController ( )
228+ const abortError = new DOMException ( 'The operation was aborted' , 'AbortError' )
229+ let markFetchStarted : ( ( ) => void ) | undefined
230+ const fetchStarted = new Promise < void > ( ( resolve ) => {
231+ markFetchStarted = resolve
232+ } )
233+ mockFetch . mockImplementationOnce ( ( _input : RequestInfo | URL , init ?: RequestInit ) => {
234+ markFetchStarted ?.( )
235+ return new Promise < Response > ( ( _resolve , reject ) => {
236+ init ?. signal ?. addEventListener ( 'abort' , ( ) => reject ( init . signal ?. reason ) , { once : true } )
237+ } )
238+ } )
239+
240+ const pending = eloquaSelectorAttachments [ 'eloqua.emails' ] . execute (
241+ args ( { kind : 'list' } , 'eloqua.emails' , controller . signal )
242+ )
243+ await fetchStarted
244+ controller . abort ( abortError )
245+
246+ await expect ( pending ) . rejects . toBe ( abortError )
247+ expect ( mockFetch ) . toHaveBeenCalledTimes ( 1 )
216248 } )
217249} )
0 commit comments