Skip to content

Commit 1d039ce

Browse files
authored
Allow Proxy to send Content-Type: application/merge-patch+json (#2956)
1 parent 965246f commit 1d039ce

2 files changed

Lines changed: 48 additions & 2 deletions

File tree

workspaces/dcm/plugins/dcm-backend/src/router.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,11 @@ export async function createRouter(
2828
): Promise<express.Router> {
2929
const router = Router();
3030

31-
router.use(express.json());
31+
router.use(
32+
express.json({
33+
type: ['application/json', 'application/merge-patch+json'],
34+
}),
35+
);
3236

3337
const permissionsIntegrationRouter = createPermissionIntegrationRouter({
3438
permissions: dcmPluginPermissions,

workspaces/dcm/plugins/dcm-backend/src/routes/proxy.test.ts

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)