Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/consumer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -527,7 +527,7 @@ export const makeConsumerPact = (
return (
ffi.pactffiWithMultipartFile(
interactionPtr,
INTERACTION_PART_REQUEST,
INTERACTION_PART_RESPONSE,
contentType,
filename,
mimePartName,
Expand All @@ -537,7 +537,7 @@ export const makeConsumerPact = (
return (
ffi.pactffiWithMultipartFile(
interactionPtr,
INTERACTION_PART_REQUEST,
INTERACTION_PART_RESPONSE,
contentType,
filename,
mimePartName,
Expand Down
42 changes: 42 additions & 0 deletions test/consumer.integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}));
});
});
Loading