Skip to main content

Fixtures / Utils / Mocking

Fixtures

  • You'll often find yourself requiring the same sets of data when working within a context area. If you feel it could be used elsewhere, please feel free to add to our fixtures within e2e/fixtures to make it accessible for others as necessary.
  • More specifically, if you are using data that remains CONSTANT, and you wish to make it globally available, it can be added to e2e/fixtures/constants/initialise-output-constants.js. This file is run on onFlowStart within e2e/flows/launch.yaml. Please refer to that file for more info.

Users

Please see Test Users for more information on how to use test users within oue e2e suite.

Utils

Please see our utilities folder for scripts to use througout your tests. Some of these are detailed in Common Maestro Scripts to Use.

Mocking API Calls

info

TODO: update this section below in respect of Maestro.

Our tool of choice for this task is MSW, a mocking library built specifically for node projects.

MSW works by intercepting requests on the network level, allowing us to listen and manipulate any incoming / outgoing HTTP calls.

With that said, figuring out which API calls are made where can be quite difficult, so feel free to question anyone from the RN team if you need a hand with a specific mock.

We have created a number of helper functions to make mocking API requests easy. The /e2e/fixtures/mocks folder contains:

  1. /rest/config/rest-mocks.ts which exports a function for mocking all or one POST or GET request to a URL which can be passed as either a string or RegExp. This function also receives the data to be returned from the intercepted request.
  2. /gql/config/graphql-mocks.ts which exports a function for mocking all queries which is passed as either a string (e.g. PromotionsList) or a RegExp. This function also receives the data to be returned from the intercepted query.

For example, your test setup may call mockRequest('api/v2/get-sports', [{sport1}, {sport2}]) which would then intercept any GET request to api/v2/get-sports and return [{sport1}, {sport2}].

All mock data should be created within the respective e2e/fixtures/mocks/<rest|gql>/payloads folder, inside an appropriately named file for its context area.

Any mocks that you deem as reusable on a regular basis can be added to an appropriately named file within e2e/fixtures/mocks/<rest|gql>/handlers