Provide an optional per-request active scenario override using a cookie #276
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Change to parrot-core and parrot-middleware.
When resolving a request, use an optional method which will look for a parrot scenario name in the request cookie and use this to determine which set of mocks to use instead of using the active scenario.
Description
Parrot.js
(parrot-core) that calls a newgetActiveScenarioOverride
method on the Parrot instance that will retrieve the active scenario override, or undefined. If this exists this is then used to select the set of mocks to match against, rather than theactiveScenario
instance variable.getActiveScenarioOverride
method in the ParrotMiddleware implementation of Parrot (parrot-middleware). This looks for a cookie with the nameparrotScenarioOverride
and returns this value, or undefined.jest-when
package as a dev dependency (parrot-core). This allowed for the thorough testing of theparrotTest.resolve
method but in a concise way.jest-when
allows you to set return values for specific function call parameters - thereby effectively asserting on the the inputs values at the same time as providing mocked responses.Motivation and Context
We have recently undertaken some work to allow Browser Tests (webdriver.io / selenium) to run in parallel. But these tests were limited by the fact that the mocking framework that they used (parrot) did not support more than one active scenario at a time. This enhancement will allow for tests to set the parrot scenario that they need per-test using a cookie set on the browser session - thereby enabling these tests to safely run in parallel with different mocking requirements.
How Has This Been Tested?
In addition to the new unit test coverage added to both parrot-core and parrot-middleware, this was also manually tested from a browser & by running a browser-test suite (webdriver), both locally and on CI. It was tested that the active scenario functioned as before, via a post to the server. It tested that it was now possible to select the active scenario for a request via the cookie. It was tested that two separate browser sessions could set different active scenario overrides at the same time.
Types of Changes
Checklist:
What is the Impact to Developers Using parrot?
There should be no impact as this is an optional feature. But the benefit will be that they are now able to set the active scenario per-request if required.