Tien Vo
05/02/2023, 5:02 AMfromProviderState be flexible about matcher's type?
Currently if I want to use regex matcher with ProviderState generator, I have to define a custom method like this:
export function regexFromProviderState(
expression: string,
regex: string,
exampleValue: string
) {
return {
'pact:matcher:type': 'regex',
'pact:generator:type': 'ProviderState',
expression,
value: exampleValue,
regex
};
}
I think it will be the same with other matchers.Timothy Jones
05/02/2023, 5:12 AMTien Vo
05/02/2023, 5:48 AMtype is hard coded https://github.com/pact-foundation/pact-js/blob/master/src/v3/matchers.ts. if I use it like this:
pact.addInteraction({
states: [{ description: 'A user' }],
uponReceiving: 'get one user',
withRequest: {
method: 'GET',
path: fromProviderState('${iri}', '/api/users/14f6626f-c51e-4311-ac52-182c8f2a7634')
},
willRespondWith: {
status: 200,
body: {
id: '14f6626f-c51e-4311-ac52-182c8f2a7634'
},
},
});
mock server will match with any GET request, not with only request with regex that I want '^\/api\/users\/[0-9a-f]{8}(-[0-9a-f]{4}){3}-[0-9a-f]{12}$'Timothy Jones
05/02/2023, 5:50 AMTimothy Jones
05/02/2023, 5:50 AM'pact:matcher:type': 'regex',
'pact:generator:type': 'ProviderState',
Is this valid?Timothy Jones
05/02/2023, 5:50 AMTien Vo
05/02/2023, 5:51 AMTimothy Jones
05/02/2023, 5:51 AM'/api/users/14s....' etc?Timothy Jones
05/02/2023, 5:51 AMTimothy Jones
05/02/2023, 5:52 AMTien Vo
05/02/2023, 5:52 AMstring . For example GET /any it still matchTimothy Jones
05/02/2023, 5:52 AMTimothy Jones
05/02/2023, 5:53 AMTimothy Jones
05/02/2023, 5:54 AMTien Vo
05/02/2023, 5:54 AMTien Vo
05/02/2023, 6:16 AMTimothy Jones
05/02/2023, 6:18 AMTien Vo
05/02/2023, 6:43 AMTimothy Jones
05/02/2023, 6:44 AM