@@ -31,13 +31,14 @@ const MARKED = 'Publishing is temporarily unavailable. Nothing was changed.';
3131function answer ( response : { ok : boolean ; status : number ; json : ( ) => Promise < unknown > } ) : void {
3232 vi . stubGlobal (
3333 'fetch' ,
34- vi . fn ( async ( ) => response ) ,
34+ // With the headers a real Response carries: the list read goes through the authenticated fetch.
35+ vi . fn ( async ( ) => ( { headers : new Headers ( ) , ...response } ) ) ,
3536 ) ;
3637}
3738const listOk = ( packages : unknown [ ] ) =>
38- answer ( { headers : new Headers ( ) , ok : true , status : 200 , json : async ( ) => ( { success : true , data : { packages, total : packages . length } } ) } ) ;
39+ answer ( { ok : true , status : 200 , json : async ( ) => ( { success : true , data : { packages, total : packages . length } } ) } ) ;
3940const listFailure = ( status : number , error : Record < string , unknown > ) =>
40- answer ( { headers : new Headers ( ) , ok : false , status, json : async ( ) => ( { success : false , error } ) } ) ;
41+ answer ( { ok : false , status, json : async ( ) => ( { success : false , error } ) } ) ;
4142
4243/** The message the read throws with, for a failed answer. */
4344async function thrownFor ( status : number , error : Record < string , unknown > ) : Promise < string > {
@@ -78,7 +79,7 @@ describe('a failed read is not an empty result (objectui#7881)', () => {
7879
7980 it ( 'a non-JSON error body names the status, not a JSON syntax error' , async ( ) => {
8081 answer ( {
81- headers : new Headers ( ) , ok : false ,
82+ ok : false ,
8283 status : 502 ,
8384 json : async ( ) => {
8485 throw new SyntaxError ( "Unexpected token '<', \"<html>\"... is not valid JSON" ) ;
@@ -98,7 +99,7 @@ describe('a failed read is not an empty result (objectui#7881)', () => {
9899 } ) ;
99100
100101 it ( 'CONTROL — the bare-array body the endpoint also serves reads the same' , async ( ) => {
101- answer ( { headers : new Headers ( ) , ok : true , status : 200 , json : async ( ) => [ { manifest : { id : PACKAGE_ID , name : PACKAGE_ID } } ] } ) ;
102+ answer ( { ok : true , status : 200 , json : async ( ) => [ { manifest : { id : PACKAGE_ID , name : PACKAGE_ID } } ] } ) ;
102103 await expect ( fetchInstalledPackageRow ( PACKAGE_ID ) ) . resolves . toMatchObject ( { manifest : { id : PACKAGE_ID } } ) ;
103104 } ) ;
104105} ) ;
0 commit comments