You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
So as a developer I would like to have the mock API respond with different sets of data automatically, based on what happens in the application I'm developing.
I was thinking it would be great if for each mock file I could configure certain "triggers" with the following setup:
The field triggers is a new field in the mock configuration file. Each separate trigger has its own name and contains two fields: when and then.
The when part is an array of objects (or simply 1 object if not an array).
It it's an array then it's always an AND type of selection:
The key "url" or "cookie" or "data" with its name as a value;
And a key "value" with its value being whatever it needs to match.
Examples:
"when": { "cookie": "userId", value: "ab123" }
"when": { "url": "userId", value: "ab123" }
"when": { "data": "data.userId", value: "ab123" }
And the then part is basically the result of when this match is found:
The then field is an array of consequences with two fields:
mock (optional, defaults to self) - what mock file are we changing the scenario in?
scenario - to what scenario are we changing when the when criteria are met?
So that would allow any type of API call to automatically change selected scenario's in this same mock but also all other mocks.
In the example above the API would see that if there's a POST to /api/select-product/123, there are a few changes in the ng-apimock scenario selections:
The current mock will from now on respond with the wrongAccount scenario
The customer-details mock will from now on respond with the bannedAccount scenario
The customer-products mock will from now on respond with the noProducts scenario
And if it receives the product with ID 888 if would switch to different scenarios again.
Would love to hear your thoughts, @mdasberg – we're currently thinking of taking this sort of feature into sprint if at all possible.
Cheers,
Your FrontMen colleague
The text was updated successfully, but these errors were encountered:
So as a developer I would like to have the mock API respond with different sets of data automatically, based on what happens in the application I'm developing.
I was thinking it would be great if for each mock file I could configure certain "triggers" with the following setup:
The field
triggers
is a new field in the mock configuration file. Each separate trigger has its own name and contains two fields:when
andthen
.The
when
part is an array of objects (or simply 1 object if not an array).It it's an array then it's always an AND type of selection:
Examples:
"when": { "cookie": "userId", value: "ab123" }
"when": { "url": "userId", value: "ab123" }
"when": { "data": "data.userId", value: "ab123" }
And the
then
part is basically the result of when this match is found:The
then
field is an array of consequences with two fields:mock
(optional, defaults to self) - what mock file are we changing the scenario in?scenario
- to what scenario are we changing when thewhen
criteria are met?So that would allow any type of API call to automatically change selected scenario's in this same mock but also all other mocks.
Configuration idea
In the example above the API would see that if there's a POST to
/api/select-product/123
, there are a few changes in the ng-apimock scenario selections:wrongAccount
scenariocustomer-details
mock will from now on respond with thebannedAccount
scenariocustomer-products
mock will from now on respond with thenoProducts
scenarioAnd if it receives the product with ID
888
if would switch to different scenarios again.Would love to hear your thoughts, @mdasberg – we're currently thinking of taking this sort of feature into sprint if at all possible.
Cheers,
Your FrontMen colleague
The text was updated successfully, but these errors were encountered: