Skip to content
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

Closed
DavidAJohn opened this issue Oct 20, 2023 · 4 comments
Closed

WireMock of Prodigi Print API needs improvement #64

DavidAJohn opened this issue Oct 20, 2023 · 4 comments
Assignees
Labels
enhancement New feature or request

Comments

@DavidAJohn
Copy link
Owner

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.

@DavidAJohn DavidAJohn added the enhancement New feature or request label Oct 20, 2023
@DavidAJohn DavidAJohn self-assigned this Oct 20, 2023
@DavidAJohn DavidAJohn pinned this issue Oct 20, 2023
@DavidAJohn
Copy link
Owner Author

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.

@DavidAJohn DavidAJohn unpinned this issue Oct 27, 2023
@DavidAJohn
Copy link
Owner Author

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

@DavidAJohn
Copy link
Owner Author

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.

@DavidAJohn
Copy link
Owner Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant