@@ -630,6 +630,61 @@ describe('ApimClient.putResource provisioning polling', () => {
630630 } ) ;
631631} ) ;
632632
633+ describe ( 'ApimClient.deleteResource provisioning polling' , ( ) => {
634+ let client : ApimClient ;
635+ let fetchSpy : ReturnType < typeof vi . fn > ;
636+
637+ beforeEach ( ( ) => {
638+ client = new ApimClient ( ) ;
639+ fetchSpy = vi . fn ( ) ;
640+ vi . stubGlobal ( 'fetch' , fetchSpy ) ;
641+
642+ /* eslint-disable @typescript-eslint/no-explicit-any */
643+ vi . spyOn ( client as any , 'getToken' ) . mockResolvedValue ( 'fake-token' ) ;
644+ vi . spyOn ( client as any , 'delay' ) . mockResolvedValue ( undefined ) ;
645+ /* eslint-enable @typescript-eslint/no-explicit-any */
646+ } ) ;
647+
648+ afterEach ( ( ) => {
649+ vi . restoreAllMocks ( ) ;
650+ vi . unstubAllGlobals ( ) ;
651+ } ) ;
652+
653+ const descriptor = { type : ResourceType . Api , nameParts : [ 'delay' ] } ;
654+
655+ it ( 'should treat 404 during delete polling as successful completion' , async ( ) => {
656+ fetchSpy
657+ // Initial DELETE accepted asynchronously
658+ . mockResolvedValueOnce ( new Response ( '' , { status : 202 } ) )
659+ // Poll GET returns 404 because delete completed
660+ . mockResolvedValueOnce ( new Response ( '' , { status : 404 } ) ) ;
661+
662+ const deleted = await client . deleteResource ( testContext , descriptor ) ;
663+
664+ expect ( deleted ) . toBe ( true ) ;
665+ expect ( fetchSpy ) . toHaveBeenCalledTimes ( 2 ) ;
666+ } ) ;
667+
668+ it ( 'should continue polling delete until resource disappears' , async ( ) => {
669+ fetchSpy
670+ . mockResolvedValueOnce ( new Response ( '' , { status : 202 } ) )
671+ // First poll: resource still exists and is deleting
672+ . mockResolvedValueOnce (
673+ makeResponse ( 200 , {
674+ name : 'delay' ,
675+ properties : { provisioningState : 'Deleting' } ,
676+ } )
677+ )
678+ // Second poll: gone
679+ . mockResolvedValueOnce ( new Response ( '' , { status : 404 } ) ) ;
680+
681+ const deleted = await client . deleteResource ( testContext , descriptor ) ;
682+
683+ expect ( deleted ) . toBe ( true ) ;
684+ expect ( fetchSpy ) . toHaveBeenCalledTimes ( 3 ) ;
685+ } ) ;
686+ } ) ;
687+
633688describe ( 'ApimClient HTTP 429 rate limiting' , ( ) => {
634689 let client : ApimClient ;
635690 let fetchSpy : ReturnType < typeof vi . fn > ;
0 commit comments