mdasberg / ng-apimock

Node plugin that provides the ability to use scenario based api mocking: for local development for protractor testing
MIT License
99 stars 26 forks source link

Use value from expression to match specific data #50

Open bhoppeadoy opened 6 years ago

bhoppeadoy commented 6 years ago

Is it possible to capture a value from the expression and use that to return specific data? Like a regex capture?

For example, I have this simple mock that returns an array of data that's contained in a file "expression": "api\/solutions" "response": { "file": "data/solutions-list.json" }

Each item in the array has a GUID associated with it. This GUID is used in other API calls, for example this returns an svg for that specific GUID: api\/solutions\/([0-9A-Fa-f]{8}[-][0-9A-Fa-f]{4}[-][0-9A-Fa-f]{4}[-][0-9A-Fa-f]{4}[-][0-9A-Fa-f]{12})\/svg

I'd like to be able to mock it so that the correct svg file is returned based on the GUID in the expression. For example, I could have the response for a file: "expression": "api\/solutions\/([0-9A-Fa-f]{8}[-][0-9A-Fa-f]{4}[-][0-9A-Fa-f]{4}[-][0-9A-Fa-f]{4}[-][0-9A-Fa-f]{12})\/svg" "response":{ "file": "data/%GUID%.svg" }

Where %GUID% is the captured GUID from the expression.

Is this possible or is there another way I missed that I can do this?