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
7 changes: 5 additions & 2 deletions native/consumer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -949,9 +949,12 @@ Napi::Value PactffiWithRequest(const Napi::CallbackInfo& info) {
* * `value` - the query parameter value.
* * `index` - the index of the value (starts at 0). You can use this to create a query parameter with multiple values
*
* The value may be a JSON matcher definition (e.g. from eachLike), which the v2 call
* parses. The deprecated v1 call stored it as a literal string (pact-js#1063).
*
* C interface:
*
* bool pactffi_with_query_parameter(InteractionHandle interaction, const char *name, size_t index, const char *value);
* bool pactffi_with_query_parameter_v2(InteractionHandle interaction, const char *name, size_t index, const char *value);
*/
Napi::Value PactffiWithQueryParameter(const Napi::CallbackInfo& info) {
Napi::Env env = info.Env();
Expand Down Expand Up @@ -981,7 +984,7 @@ Napi::Value PactffiWithQueryParameter(const Napi::CallbackInfo& info) {
size_t index = info[2].As<Napi::Number>().Uint32Value();
std::string value = info[3].As<Napi::String>().Utf8Value();

bool res = pactffi_with_query_parameter(interaction, name.c_str(), index, value.c_str());
bool res = pactffi_with_query_parameter_v2(interaction, name.c_str(), index, value.c_str());

return Napi::Boolean::New(env, res);
}
Expand Down
36 changes: 36 additions & 0 deletions test/consumer.integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,42 @@ describe('FFI integration test for the HTTP Consumer API', () => {
}));
});

// pact-js#1063: a matcher on a query parameter must be parsed, not stored as a literal
describe('with a matcher on a repeated query parameter', () => {
beforeEach(() => {
pact = makeConsumerPact(
'foo-consumer',
'bar-provider',
FfiSpecificationVersion.SPECIFICATION_VERSION_V4,
);

const interaction = pact.newInteraction('some description');

interaction.uponReceiving('a request with repeated query values');
interaction.withRequest('GET', '/items');
interaction.withQuery(
'ids',
0,
JSON.stringify({ 'pact:matcher:type': 'type', min: 1, value: ['id'] }),
);
interaction.withStatus(200);

port = pact.createMockServer(HOST);
});

it('matches any number of values', () =>
axios
.get(`http://${HOST}:${port}/items?ids=a&ids=b`)
.then((res) => {
expect(res.status).toEqual(200);
expect(pact.mockServerMismatches(port)).toHaveLength(0);
expect(pact.mockServerMatchedSuccessfully(port)).toBe(true);
})
.finally(() => {
pact.cleanupMockServer(port);
}));
});

describe('with JSON data', () => {
beforeEach(() => {
pact = makeConsumerPact(
Expand Down
Loading