@@ -42,7 +42,11 @@ function makeApp(configData: Record<string, Record<string, string>> = {}) {
4242 cache : mockServices . cache . mock ( ) ,
4343 } ;
4444 const app = express ( ) ;
45- app . use ( express . json ( ) ) ;
45+ app . use (
46+ express . json ( {
47+ type : [ 'application/json' , 'application/merge-patch+json' ] ,
48+ } ) ,
49+ ) ;
4650 // Mount using a wildcard path matching the router convention
4751 app . all ( '/proxy/*' , createDcmProxy ( options ) ) ;
4852 return app ;
@@ -185,6 +189,44 @@ describe('createDcmProxy', () => {
185189 expect ( JSON . parse ( upstreamCall [ 1 ] . body ) ) . toEqual ( requestBody ) ;
186190 } ) ;
187191
192+ it ( 'proxies a PATCH request with application/merge-patch+json and forwards the body' , async ( ) => {
193+ const patch = { display_name : 'updated' , spec : { fields : [ ] } } ;
194+ fetchSpy = jest
195+ . spyOn ( globalThis , 'fetch' )
196+ . mockResolvedValueOnce ( TOKEN_RESPONSE )
197+ . mockResolvedValueOnce ( {
198+ status : 200 ,
199+ ok : true ,
200+ headers : {
201+ get : ( h : string ) =>
202+ h === 'content-type' ? 'application/json' : null ,
203+ } ,
204+ text : async ( ) => JSON . stringify ( patch ) ,
205+ } as unknown as Response ) ;
206+
207+ const app = makeApp ( {
208+ dcm : {
209+ apiGatewayUrl : 'https://gateway.example.com' ,
210+ clientId : 'id' ,
211+ clientSecret : 'secret' ,
212+ } ,
213+ } ) ;
214+
215+ const res = await request ( app )
216+ . patch ( '/proxy/catalog-items/test-id' )
217+ . send ( patch )
218+ . set ( 'Content-Type' , 'application/merge-patch+json' ) ;
219+
220+ expect ( res . status ) . toBe ( 200 ) ;
221+
222+ const upstreamCall = fetchSpy . mock . calls [ 1 ] ;
223+ expect ( upstreamCall [ 1 ] . method ) . toBe ( 'PATCH' ) ;
224+ expect ( upstreamCall [ 1 ] . headers [ 'Content-Type' ] ) . toBe (
225+ 'application/merge-patch+json' ,
226+ ) ;
227+ expect ( JSON . parse ( upstreamCall [ 1 ] . body ) ) . toEqual ( patch ) ;
228+ } ) ;
229+
188230 it ( 'handles 204 No Content upstream responses without a body' , async ( ) => {
189231 fetchSpy = jest
190232 . spyOn ( globalThis , 'fetch' )
0 commit comments