diff --git a/src/consumer/index.ts b/src/consumer/index.ts index 6a1722db..973b4133 100644 --- a/src/consumer/index.ts +++ b/src/consumer/index.ts @@ -527,7 +527,7 @@ export const makeConsumerPact = ( return ( ffi.pactffiWithMultipartFile( interactionPtr, - INTERACTION_PART_REQUEST, + INTERACTION_PART_RESPONSE, contentType, filename, mimePartName, @@ -537,7 +537,7 @@ export const makeConsumerPact = ( return ( ffi.pactffiWithMultipartFile( interactionPtr, - INTERACTION_PART_REQUEST, + INTERACTION_PART_RESPONSE, contentType, filename, mimePartName, diff --git a/test/consumer.integration.spec.ts b/test/consumer.integration.spec.ts index e4c06dab..501b0bc8 100644 --- a/test/consumer.integration.spec.ts +++ b/test/consumer.integration.spec.ts @@ -762,4 +762,46 @@ describe('FFI integration test for the HTTP Consumer API', () => { pact.cleanupMockServer(port); })); }); + + describe('with a multipart response body', () => { + const f: string = path.resolve(__dirname, './monkeypatch.rb'); + const boundary = 'pact-response-boundary'; + + beforeEach(() => { + pact = makeConsumerPact( + 'multipart-response-consumer', + 'multipart-response-provider', + FfiSpecificationVersion.SPECIFICATION_VERSION_V3, + ); + + const interaction = pact.newInteraction('multipart response'); + interaction.uponReceiving('a request for a dog photo'); + interaction.withRequest('GET', '/dogs/1234/photo'); + interaction.withResponseMultipartBody('text/plain', f, 'photo', boundary); + interaction.withStatus(200); + + port = pact.createMockServer(HOST); + }); + + afterEach(() => { + pact.cleanupMockServer(port); + }); + + it('sets the multipart body on the response, not the request', () => + axios + .request({ + baseURL: `http://${HOST}:${port}`, + method: 'GET', + url: '/dogs/1234/photo', + responseType: 'text', + }) + .then((res) => { + expect(res.headers['content-type']).toContain( + `multipart/form-data; boundary=${boundary}`, + ); + expect(res.data).toContain('name="photo"'); + expect(res.data).toContain(fs.readFileSync(f, 'utf8')); + expect(pact.mockServerMatchedSuccessfully(port)).toBe(true); + })); + }); });