@@ -241,6 +241,32 @@ describe('Client', () => {
241241 expect ( global . fetch ) . toHaveBeenCalledTimes ( 2 ) ;
242242 } ) ;
243243
244+ test ( 'run treats deleted status as terminal failure' , async ( ) => {
245+ const mockSubmitResponse = {
246+ ok : true ,
247+ status : 200 ,
248+ json : async ( ) => ( { data : { id : 'req-123' } } ) ,
249+ } ;
250+ const mockGetResponse = {
251+ ok : true ,
252+ status : 200 ,
253+ json : async ( ) => ( {
254+ data : { status : 'deleted' , error : 'Task was deleted' }
255+ } ) ,
256+ } ;
257+
258+ ( global . fetch as jest . Mock )
259+ . mockResolvedValueOnce ( mockSubmitResponse )
260+ . mockResolvedValueOnce ( mockGetResponse ) ;
261+
262+ const client = new Client ( 'test-key' ) ;
263+
264+ await expect (
265+ client . run ( 'wavespeed-ai/z-image/turbo' , { prompt : 'test' } )
266+ ) . rejects . toThrow ( 'Task was deleted' ) ;
267+ expect ( global . fetch ) . toHaveBeenCalledTimes ( 2 ) ;
268+ } ) ;
269+
244270 test ( 'run timeout' , async ( ) => {
245271 const mockSubmitResponse = {
246272 ok : true ,
@@ -324,7 +350,6 @@ describe('Client', () => {
324350 status : 'processing' ,
325351 code : 5004 ,
326352 error : 'Sync mode timed out after 90 seconds. The prediction is still processing asynchronously.' ,
327- urls : { get : resultUrl }
328353 }
329354 } ) ,
330355 } ;
@@ -353,7 +378,6 @@ describe('Client', () => {
353378 status : 'processing' ,
354379 code : 5004 ,
355380 error : 'Sync mode timed out after 90 seconds. The prediction is still processing asynchronously.' ,
356- urls : { get : resultUrl }
357381 }
358382 } ) ,
359383 } ;
0 commit comments