@@ -201,6 +201,37 @@ test('does not remove local state when remote deletion fails', async () => {
201201 expect ( removeDevelopmentTheme ) . not . toHaveBeenCalled ( )
202202} )
203203
204+ test . each ( [ false , true ] ) ( 'preserves the first fatal error when all deletions fail (multiple: %s)' , async ( multiple ) => {
205+ const error = new AbortError ( 'Missing theme access scope' , 'Check the access token scopes.' , [
206+ 'Request the required theme access scope.' ,
207+ ] )
208+ error . code = 'MISSING_THEME_SCOPE'
209+ error . customSections = [ { title : 'Required access' , body : 'write_themes' } ]
210+ error . details = { requiredScope : 'write_themes' }
211+ vi . mocked ( findThemes ) . mockResolvedValue ( multiple ? [ theme1 , theme2 ] : [ theme1 ] )
212+ vi . mocked ( themeDelete ) . mockRejectedValueOnce ( error ) . mockRejectedValueOnce ( new Error ( 'Another deletion failed' ) )
213+
214+ await expect ( executeDelete ( session , { ...options , themes : [ '1' , '2' ] , force : true } ) ) . rejects . toBe ( error )
215+ expect ( error . details ) . toEqual ( { requiredScope : 'write_themes' } )
216+ } )
217+
218+ test ( 'includes each theme failure when ordinary errors cause total failure' , async ( ) => {
219+ vi . mocked ( findThemes ) . mockResolvedValue ( [ theme1 , theme2 ] )
220+ vi . mocked ( themeDelete )
221+ . mockRejectedValueOnce ( new Error ( 'First deletion failed' ) )
222+ . mockRejectedValueOnce ( new Error ( 'Second deletion failed' ) )
223+
224+ await expect ( executeDelete ( session , { ...options , themes : [ '1' , '2' ] , force : true } ) ) . rejects . toMatchObject ( {
225+ message : 'First deletion failed' ,
226+ details : {
227+ errors : [
228+ { themeId : '1' , message : 'First deletion failed' } ,
229+ { themeId : '2' , message : 'Second deletion failed' } ,
230+ ] ,
231+ } ,
232+ } )
233+ } )
234+
204235test ( 'preserves the environment label in terminal output' , ( ) => {
205236 renderThemeDeleteResult ( { status : 'success' , themes : [ { ...theme1 , shop : session . storeFqdn } ] } , 'text' , {
206237 store : session . storeFqdn ,
0 commit comments