GitHub
10/04/2024, 3:16 PMmatchingRules?
I'm trying to develop mock network request functionality for playwright tests based on existing generated pact contracts.
Building the routes from the pact JSON files is straightforward, but there is a problem when I have the same path and the same method but different responses.
For example, my contact is UsersConsumer - UsersProvider. The interactions are
GET /users -> response 200 with body { users: [] }
GET /users?limit=10 -> response 200 with body { users: [] }
GET /users -> response 401 with body { users: [] }
GET /users -> response 500 with body { users: [] }
So, to generically decide what my result is based on the request from the playwright, I need to pass the request.body, request.headers, and request.query and matchingRules to a utility to decide if they are matching
isMatch(request, interactions.request.matchingRules) => boolean something like that.
Use case
This will help create generic mock servers with any framework or tool.
It can be reused for intercepting calls in Playwright or building custom routes in MSW.
pact-foundation/pact-js