@@ -116,6 +116,55 @@ describe("Update network failure behavior. __rest __core", () => {
116116 . send ( { "@id" : rerumUriOrig , testing : "item" } )
117117 assert . equal ( response . statusCode , 502 )
118118 } )
119+
120+ it ( "Preserves upstream text error message when update returns non-ok." , async ( ) => {
121+ global . fetch = async ( ) => ( {
122+ ok : false ,
123+ status : 503 ,
124+ text : async ( ) => "Upstream update failure"
125+ } )
126+
127+ const response = await request ( routeTester )
128+ . put ( "/update" )
129+ . set ( "Content-Type" , "application/json" )
130+ . send ( { "@id" : rerumUriOrig , testing : "item" } )
131+
132+ assert . equal ( response . statusCode , 502 )
133+ assert . match ( response . text , / U p s t r e a m u p d a t e f a i l u r e / )
134+ } )
135+
136+ it ( "Falls back to generic RERUM error text when upstream .text() throws." , async ( ) => {
137+ global . fetch = async ( ) => ( {
138+ ok : false ,
139+ status : 500 ,
140+ text : async ( ) => {
141+ throw new Error ( "text stream consumed" )
142+ }
143+ } )
144+
145+ const response = await request ( routeTester )
146+ . put ( "/update" )
147+ . set ( "Content-Type" , "application/json" )
148+ . send ( { "@id" : rerumUriOrig , testing : "item" } )
149+
150+ assert . equal ( response . statusCode , 502 )
151+ assert . match ( response . text , / A R E R U M e r r o r o c c u r r e d / )
152+ } )
153+
154+ it ( "Maps successful upstream payload without id fields to 502." , async ( ) => {
155+ global . fetch = async ( ) => ( {
156+ ok : true ,
157+ json : async ( ) => ( { testing : "item" } )
158+ } )
159+
160+ const response = await request ( routeTester )
161+ . put ( "/update" )
162+ . set ( "Content-Type" , "application/json" )
163+ . send ( { "@id" : rerumUriOrig , testing : "item" } )
164+
165+ assert . equal ( response . statusCode , 502 )
166+ assert . match ( response . text , / A R E R U M e r r o r o c c u r r e d / )
167+ } )
119168} )
120169
121170describe ( "Check that the properly used update endpoints function and interact with RERUM. __e2e" , ( ) => {
0 commit comments