-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
WireMock of Prodigi Print API needs improvement #64
Comments
I've simplified the Prodigi WireMock implementation by commenting out the request matching of the JSON body, which was way too specific and inflexible. That was done is this commit: 20ff4ea Now I'll have to venture into the rabbit hole that is JSONPath to add some level of request matching back in. In that previous commit I also made a start on some response templating, which involves extracting values from the request and inserting them into the response. That allows the integration tests to check that crucial values like the idempotency key, etc. are being handled as expected. |
This has turned out to be pretty tough going. There's been a lot of trial and error. I've now switched some of the response templating to use the .WithCallback function, which I can't find any reference to in the docs, but discovered after seeing a reply on StackOverflow from Stef Heyenrath (the creator and maintainer of WireMock.Net). It's marginally less ugly than the previous method I used, in that it doesn't have insane double or triple quotes in verbatim strings everywhere. It's visible in this commit: 7c7a3a0 |
I've also started to improve the request matching (mostly using JsonPartialWildcardMatcher). I've really just tried to check that certain properties exist in the JSON body that is supplied. After a lot of trial and error, I've settled on this method that I read about in the WireMock.Net Issues (again courtesy of Stef), which basically involves creating an array of matchers that get added via the .WithBody section. For now I've just changed the order created response (in this commit: 503a99c), but will obviously change the other responses as well as finding ways to move some of the more verbose code into extensions methods, etc. |
Over a series of updates, I've now massively improved the responses that are returned so that they reflect the request that was sent. Ultimately, I used the .WithCallback method to construct responses based on the incoming request object and removed all of the static methods containing triple-quoted verbatim strings. |
In the integration tests project, I've created a mock of the Prodigi Print API which is used via a WebApplicationFactory to provide fake responses to both the QuoteService and OrderService tests.
To put it mildly, it's pretty ugly. The request matching is far too specific at the moment and it's making the tests worringly brittle.
I need to go through the WireMock-Net docs again and try to find ways to add wildcards or ignore certain fields somehow.
The text was updated successfully, but these errors were encountered: