diff --git a/packages/elements-core/src/components/TryIt/build-request.spec.ts b/packages/elements-core/src/components/TryIt/build-request.spec.ts index d8a52ee26..6753a6ffa 100644 --- a/packages/elements-core/src/components/TryIt/build-request.spec.ts +++ b/packages/elements-core/src/components/TryIt/build-request.spec.ts @@ -210,4 +210,52 @@ describe('Build Request', () => { ]); }); }); + + describe('Build Request', () => { + describe('shouldIncludeBody for DELETE', () => { + it('Includes body for DELETE requests when bodyInput is provided', () => { + const httpOperation = { + method: 'DELETE', + path: '/delete/path', + request: { + body: { + contents: [ + { + mediaType: 'application/json', + }, + ], + }, + }, + }; + + const bodyInput = '{"key":"value"}'; + const shouldIncludeBody = + ['PUT', 'POST', 'PATCH', 'DELETE'].includes(httpOperation.method.toUpperCase()) && bodyInput !== undefined; + + expect(shouldIncludeBody).toBe(true); + }); + + it('Does not include body for DELETE requests when bodyInput is undefined', () => { + const httpOperation = { + method: 'DELETE', + path: '/delete/path', + request: { + body: { + contents: [ + { + mediaType: 'application/json', + }, + ], + }, + }, + }; + + const bodyInput = undefined; + const shouldIncludeBody = + ['PUT', 'POST', 'PATCH', 'DELETE'].includes(httpOperation.method.toUpperCase()) && bodyInput !== undefined; + + expect(shouldIncludeBody).toBe(false); + }); + }); + }); }); diff --git a/packages/elements-core/src/components/TryIt/build-request.ts b/packages/elements-core/src/components/TryIt/build-request.ts index 84ce2dd39..79b7922db 100644 --- a/packages/elements-core/src/components/TryIt/build-request.ts +++ b/packages/elements-core/src/components/TryIt/build-request.ts @@ -147,7 +147,7 @@ export async function buildFetchRequest({ const serverUrl = getServerUrl({ httpOperation, mockData, chosenServer, corsProxy, serverVariableValues }); const shouldIncludeBody = - ['PUT', 'POST', 'PATCH'].includes(httpOperation.method.toUpperCase()) && bodyInput !== undefined; + ['PUT', 'POST', 'PATCH', 'DELETE'].includes(httpOperation.method.toUpperCase()) && bodyInput !== undefined; const queryParams = getQueryParams({ httpOperation, parameterValues }); @@ -264,7 +264,7 @@ export async function buildHarRequest({ const mimeType = mediaTypeContent?.mediaType ?? 'application/json'; const shouldIncludeBody = - ['PUT', 'POST', 'PATCH'].includes(httpOperation.method.toUpperCase()) && bodyInput !== undefined; + ['PUT', 'POST', 'PATCH', 'DELETE'].includes(httpOperation.method.toUpperCase()) && bodyInput !== undefined; const queryParams = getQueryParams({ httpOperation, parameterValues });