diff --git a/native/consumer.cc b/native/consumer.cc index c413a99b..720126ec 100644 --- a/native/consumer.cc +++ b/native/consumer.cc @@ -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(); @@ -981,7 +984,7 @@ Napi::Value PactffiWithQueryParameter(const Napi::CallbackInfo& info) { size_t index = info[2].As().Uint32Value(); std::string value = info[3].As().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); } diff --git a/test/consumer.integration.spec.ts b/test/consumer.integration.spec.ts index e4c06dab..94fc0e12 100644 --- a/test/consumer.integration.spec.ts +++ b/test/consumer.integration.spec.ts @@ -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(