- Issue created by @murz
- Merge request !141Issue #3512468: Implement a context setting to mock different stored responses for same requests → (Merged) created by murz
The HttpClientFactoryStub service can store and mock the responses, emulating a fully working remote API without making any external calls. It captures the responses and stores them to files by hash, generated from the URL, method, and body of the request.
And it covers almost all cases, except a case when we need to receive from the remote API different responses for the same query.
For example, getting the e-commerce cart content, having the same cart_id, but before the products get added to it, and after this. In that case, the request hash is the same for both requests, so the module will return the same value.
We can workaround this by configuring different directories to store the asset files, but it looks too complicated.
So, the idea is to add a "context" value to the stub, that will be added to the asset hash generation function, using it we can separate the responses for the same requests, and store them in separate files.
Introduce a "context" setting for the HttpClientFactoryStub and use it to generate the hash of the stored asset file name.
Active
1.5
Code