@@ -262,6 +262,57 @@ describe("preview-url pagination (#7450)", () => {
262262 vi . stubGlobal ( "fetch" , fetchMock ) ;
263263 await expect ( getLatestDeploymentStatus ( { token : "t" , repo : REPO , sha : "status-down" } ) ) . resolves . toEqual ( { url : null , failed : false } ) ;
264264 } ) ;
265+
266+ it ( "getLatestDeploymentStatus skips deployments without an id and still finds a preview URL" , async ( ) => {
267+ vi . stubGlobal ( "fetch" , async ( input : RequestInfo | URL ) => {
268+ const url = String ( input ) ;
269+ if ( url . includes ( "/deployments?" ) ) return Response . json ( [ { } , { id : 2 } ] ) ;
270+ return Response . json ( [ { state : "success" , environment_url : "https://valid-id.app.workers.dev" } ] ) ;
271+ } ) ;
272+ await expect ( getLatestDeploymentStatus ( { token : "t" , repo : REPO , sha : "skip-id" } ) ) . resolves . toEqual ( {
273+ url : "https://valid-id.app.workers.dev" ,
274+ failed : false ,
275+ } ) ;
276+ } ) ;
277+
278+ it ( "getLatestDeploymentStatus accepts in_progress statuses with an environment_url" , async ( ) => {
279+ vi . stubGlobal ( "fetch" , async ( input : RequestInfo | URL ) => {
280+ const url = String ( input ) ;
281+ if ( url . includes ( "/deployments?" ) ) return Response . json ( [ { id : 3 } ] ) ;
282+ return Response . json ( [ { state : "in_progress" , environment_url : "https://building.app.workers.dev" } ] ) ;
283+ } ) ;
284+ await expect ( getLatestDeploymentStatus ( { token : "t" , repo : REPO , sha : "building" } ) ) . resolves . toEqual ( {
285+ url : "https://building.app.workers.dev" ,
286+ failed : false ,
287+ } ) ;
288+ } ) ;
289+
290+ it ( "getLatestDeploymentStatus treats a latest error status as failed when nothing is pending" , async ( ) => {
291+ vi . stubGlobal ( "fetch" , async ( input : RequestInfo | URL ) => {
292+ const url = String ( input ) ;
293+ if ( url . includes ( "/deployments?" ) ) return Response . json ( [ { id : 4 } ] ) ;
294+ return Response . json ( [ { state : "error" } ] ) ;
295+ } ) ;
296+ await expect ( getLatestDeploymentStatus ( { token : "t" , repo : REPO , sha : "error-state" } ) ) . resolves . toEqual ( { url : null , failed : true } ) ;
297+ } ) ;
298+
299+ it ( "getLatestDeploymentStatus keeps failed:false when the latest status is still in_progress without a URL" , async ( ) => {
300+ vi . stubGlobal ( "fetch" , async ( input : RequestInfo | URL ) => {
301+ const url = String ( input ) ;
302+ if ( url . includes ( "/deployments?" ) ) return Response . json ( [ { id : 5 } ] ) ;
303+ return Response . json ( [ { state : "in_progress" } ] ) ;
304+ } ) ;
305+ await expect ( getLatestDeploymentStatus ( { token : "t" , repo : REPO , sha : "in-progress" } ) ) . resolves . toEqual ( { url : null , failed : false } ) ;
306+ } ) ;
307+
308+ it ( "getLatestDeploymentStatus treats non-array deployment and status payloads as empty" , async ( ) => {
309+ vi . stubGlobal ( "fetch" , async ( input : RequestInfo | URL ) => {
310+ const url = String ( input ) ;
311+ if ( url . includes ( "/deployments?" ) ) return Response . json ( { message : "unexpected" } ) ;
312+ return Response . json ( { message : "unexpected" } ) ;
313+ } ) ;
314+ await expect ( getLatestDeploymentStatus ( { token : "t" , repo : REPO , sha : "shape" } ) ) . resolves . toEqual ( { url : null , failed : false } ) ;
315+ } ) ;
265316} ) ;
266317
267318describe ( "extractPreviewUrl" , ( ) => {
0 commit comments