Hi there - does anyone know of a way to trigger ma...
# help
b
Hi there - does anyone know of a way to trigger mappings reset from JSON mappings as a post-response action? I found some documentation on using postServeActions. I tried:
Copy code
"postServeActions": {
    "reset-scenarios": {
      "parameters": {}
    }
  }
But this didn't work. Thanks in advance for any help
l
I haven't seen that before. Just out of interest, where did you find the documentation?
b
PostServeActions are called out as deprecated by https://wiremock.org/docs/extensibility/listening-for-serve-events/. However, it seems like you can't use listeners in config, so I was trying to use postServeActions
l
PostServeActions
are definitely deprecated and replaced with
ServeEventListener
. I had just never seen the
reset-scenarios
part before. Also, I am not sure what you mean when you say you can't use listeners in config. By config do you mean wiremock json? If so, you can definitely use ServeEventListeners in the json format. That is how webhooks are configured. See the json example here - https://wiremock.org/docs/webhooks-and-callbacks/#creating-a-simple-single-webhook
b
Oh awesome - I'm pretty new here. Haven't used Wiremock in years. Thank you for this link - taking a look 🙂
l
No problem. I am not sure if triggering a mappings reset from json is allowed but you can use the admin api if you are running WireMock standalone - https://wiremock.org/docs/standalone/admin-api-reference/
b
I'm building an asynchronous service in Lambda. EventBridge -> Lambda every N minutes. Wiremock is running in a container in ECS and has an internal load balancer. I'd like to basically have a mocked set of responses that happen as a series. The last one I of course need to reset the mock back to the beginning of the series
l
Scenarios might help you there - https://wiremock.org/docs/stateful-behaviour/
Is it the same endpoint that gets called everytime ?
b
Yeah, same endpoint. I'm mocking every network call I can't control or easily populate with data. There are really only two calls. I first inject the wiremock endpoint via the environment. Then the response from the first call, which of course is going to WM, should point it to another location over the network. In the test I just point it right back to wiremock and it gives the next step in the series. It all works well except the reset portion. Indexing on lightweight solutions here and plan to formalize long term
l
I see. Maybe the admin api or scenarios might be the way to go then.