diff --git a/src/handlers/fix-request-body.ts b/src/handlers/fix-request-body.ts index e8e1373d..371355e9 100644 --- a/src/handlers/fix-request-body.ts +++ b/src/handlers/fix-request-body.ts @@ -40,6 +40,8 @@ export function fixRequestBody { expect(proxyRequest.write).toHaveBeenCalled(); }); + it('should write when body is not empty and Content-Type is text/plain', () => { + const proxyRequest = fakeProxyRequest(); + proxyRequest.setHeader('content-type', 'text/plain; charset=utf-8'); + + jest.spyOn(proxyRequest, 'setHeader'); + jest.spyOn(proxyRequest, 'write'); + + fixRequestBody(proxyRequest, createRequestWithBody('some string')); + + const expectedBody = 'some string'; + expect(proxyRequest.setHeader).toHaveBeenCalledWith('Content-Length', expectedBody.length); + expect(proxyRequest.write).toHaveBeenCalledWith(expectedBody); + }); + it('should write when body is not empty and Content-Type is application/json', () => { const proxyRequest = fakeProxyRequest(); proxyRequest.setHeader('content-type', 'application/json; charset=utf-8');