Hi, Should `fromProviderState` be flexible about ...
# pact-js
t
Hi, Should
fromProviderState
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:
Copy code
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.
t
I’m not sure what you’re trying to do here?
t
currently matcher
type
is hard coded https://github.com/pact-foundation/pact-js/blob/master/src/v3/matchers.ts. if I use it like this:
Copy code
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}$'
t
This is a development question, I guess?
Copy code
'pact:matcher:type': 'regex',
        'pact:generator:type': 'ProviderState',
Is this valid?
I don’t actually know.
t
yes it's valid. I tried it in my personal project
t
Doesn’t the mock server match
'/api/users/14s....'
etc?
not any string
I thought it was either the string you provide, or the example from the provider state
t
I tried on my project, it match any
string
. For example
GET /any
it still match
t
That sounds like a bug to me
The lack of composability in the matchers is one of the things that make me kick off the ContractCase project - where the matchers are fully composable
If you can indeed add a generator like in your example, then I think yes, it’s worth exposing that in the DSL somehow
t
Let me create a demo project for this bug and then report it
t
Great example
t
Here is the ticket https://github.com/pact-foundation/pact-js/issues/1088 I created it as if I am a user, not contributor, so it's easier to read (I think)
t
Thanks!