@@ -177,6 +177,44 @@ describe("version-mutations", () => {
177177 const step3Body = JSON . parse ( mockAscFetch . mock . calls [ 2 ] [ 1 ] . body ) ;
178178 expect ( step3Body . data . attributes . submitted ) . toBe ( true ) ;
179179 } ) ;
180+
181+ it ( "cleans up dangling submission when step 2 fails" , async ( ) => {
182+ mockAscFetch
183+ . mockResolvedValueOnce ( { data : { id : "sub-1" } } ) // step 1: create
184+ . mockRejectedValueOnce ( new Error ( "add item failed" ) ) // step 2: fails
185+ . mockResolvedValueOnce ( null ) ; // cleanup DELETE
186+
187+ await expect ( submitForReview ( "app-1" , "ver-1" , "IOS" ) ) . rejects . toThrow ( "add item failed" ) ;
188+
189+ expect ( mockAscFetch ) . toHaveBeenCalledWith (
190+ "/v1/reviewSubmissions/sub-1" ,
191+ expect . objectContaining ( { method : "DELETE" } ) ,
192+ ) ;
193+ } ) ;
194+
195+ it ( "cleans up dangling submission when step 3 fails" , async ( ) => {
196+ mockAscFetch
197+ . mockResolvedValueOnce ( { data : { id : "sub-1" } } ) // step 1: create
198+ . mockResolvedValueOnce ( { } ) // step 2: add item
199+ . mockRejectedValueOnce ( new Error ( "confirm failed" ) ) // step 3: fails
200+ . mockResolvedValueOnce ( null ) ; // cleanup DELETE
201+
202+ await expect ( submitForReview ( "app-1" , "ver-1" , "IOS" ) ) . rejects . toThrow ( "confirm failed" ) ;
203+
204+ expect ( mockAscFetch ) . toHaveBeenCalledWith (
205+ "/v1/reviewSubmissions/sub-1" ,
206+ expect . objectContaining ( { method : "DELETE" } ) ,
207+ ) ;
208+ } ) ;
209+
210+ it ( "still throws original error when cleanup DELETE also fails" , async ( ) => {
211+ mockAscFetch
212+ . mockResolvedValueOnce ( { data : { id : "sub-1" } } ) // step 1: create
213+ . mockRejectedValueOnce ( new Error ( "add item failed" ) ) // step 2: fails
214+ . mockRejectedValueOnce ( new Error ( "delete also failed" ) ) ; // cleanup also fails
215+
216+ await expect ( submitForReview ( "app-1" , "ver-1" , "IOS" ) ) . rejects . toThrow ( "add item failed" ) ;
217+ } ) ;
180218 } ) ;
181219
182220 describe ( "releaseVersion" , ( ) => {
0 commit comments