Testing booking
A guide for setting up the OpenActive Test Suite for the Open Booking API.
- openactive-broker-microservice - harvests feeds and provides an interface to extract specific items from the feeds.
- openactive-integration-tests - a suite of Jest integration tests that exercise an Open Booking API implementation.
Clone the test suite repository locally, and install its dependencies.
You can check that the test suite works in your local environment by running it against the hosted OpenActive Reference Implementation, simply by using the default configuration:
npm start -- core
Note that the above command only runs the "core" tests within the test suite, which should take around 60 seconds to complete.
The hosted OpenActive Reference Implementation is running on a basic developer tier Azure instance with a burst quota, so if the application shuts down, simply wait 5 minutes and try again.
The quota is sufficient for the most common use cases: running a small subset of tests or individual tests against the reference implementation.
This quota is insufficient for running all tests in the test suite at once. If you are interested in viewing the results of all tests passing against the reference implementation, the results are published for both random and controlled mode.
Copy the file
./config/default.json
to ./config/dev.json
and configure it to point to the local development environment of your own booking system using the steps on the rest of this page.Set the environment variable
NODE_ENV
to dev
to instruct the test suite to use dev.json
file to override each of the values in default.json
:Bash
Windows Command Line
export NODE_ENV=dev
npm start -- core
set NODE_ENV=dev
npm start -- core
Adding other
./config/{NODE_ENV}.json
files allows you to override the default configuration. For more information see this documentation.The Open Booking API includes two flows:
Assess whether or not your implementation will include either or both of these flows, and configure the test suite accordingly, as detailed in the reference documentation, for example:
./config/dev.json (extract)
"integrationTests": {
...
"bookingFlowsInScope": {
"OpenBookingSimpleFlow": true,
"OpenBookingApprovalFlow": true
},
...
}
Before you start your implementation, it is good to configure your config file to match your aspirations. You can then use different test suite commands to run only a subset of the tests during development, and then run
npm start
to run all tests.The list of Open Booking API features supported by the test suite can be found in the Test Suite Feature Coverage page.
For each optional feature, assess whether or not your implementation will include this.
./config/dev.json (extract)
"integrationTests": {
...
"implementedFeatures": {
"opportunity-feed": true,
"dataset-site": true,
"availability-check": true,
...
}
...
}
Note that not all Open Booking API features are currently supported by the test suite. For a list of supported features, please see the Test Suite Feature Coverage page.
Set up the Opportunity Types that your booking system will support, as detailed in the reference documentation. The test suite will only attempt to book opportunity types that are configured here, for example:
./config/dev.json (extract)
"integrationTests": {
...
"bookableOpportunityTypesInScope": {
"ScheduledSession": true,
"FacilityUseSlot": false,
"IndividualFacilityUseSlot": false,
"CourseInstance": false,
"CourseInstanceSubEvent": false,
"HeadlineEvent": false,
"HeadlineEventSubEvent": false,
"Event": false,
"OnDemandEvent": false
},
...
}
Choose which testing strategy to use. You can always start with one and switch to the other later.
When using OpenActive Test Suite during development, it is far more efficient to run test suite with a small number of items in your opportunity feeds and using "controlled mode". Although implementing the OpenActive Test Interface to support controlled mode might seem like extra work, it will result in a much more efficient development, testing and debugging cycle, that will allow your implementation of the Open Booking API to be built much more quickly overall.
./config/dev.json (extract)
"integrationTests": {
...
"useRandomOpportunities": true
...
}
Selects random opportunities from the feeds that match the prerequisite criteria for each test, to book opportunities that already exist in the booking system
If using random mode, you must ensure that enough opportunities exist that cover the required criteria for all features that you are implementing. See the features list for a summary of how many opportunities are required for each criteria to test a specific feature. Please note that opportunities are not reused between tests within the same run of the test suite.
As you implement the Open Booking API features, more test data will need to be added, and the OpenActive Test Suite will need to download all of this data each time it is started, before it is able to run tests. For this reason, controlled mode offers a much more efficient developer experience: it auto-populates test data, and only creates the test data that is required for a particular test run when it is needed.
./config/dev.json (extract)
"integrationTests": {
...
"useRandomOpportunities": false
...
}
Automatically creates new opportunities in the booking system before each test run.
In order to enable controlled testing, you must implement the OpenActive Test Interface within your booking system. This interface allows the test suite to create opportunities that conform to specific criteria.
Your implementation of the OpenActive Test Interface itself can be tested using the test-interface feature.
The
testDatasetIdentifier
setting is used in all calls in the test interface. It allows any test data that was created with this identifier to be cleared before a new test run begins.The test suite will making all bookings under a specific
primary
Seller provided in the configuration, using the authentication request headers provided for that Seller.If your booking system only supports a single seller, only the “
primary
” seller is required. If your booking system supports multiple sellers, the “secondary
” seller must also be set to support the “multiple-sellers” tests. ./config/dev.json (extract)
"sellers": {
"primary": {
"@type": "Organization",
"@id": "https://localhost:5001/api/identifiers/sellers/1",
"authentication": {
"loginCredentials": null,
"requestHeaders": {
"X-OpenActive-Test-Client-Id": "test",
"X-OpenActive-Test-Seller-Id": "https://localhost:5001/api/identifiers/sellers/1"
}
}
},
"secondary": {
"@type": "Organization",
"@id": "https://localhost:5001/api/identifiers/sellers/2",
"authentication": {
"loginCredentials": null,
"requestHeaders": {
"X-OpenActive-Test-Client-Id": "test",
"X-OpenActive-Test-Seller-Id": "https://localhost:5001/api/identifiers/sellers/2"
}
}
}
}
Configure the broker microservice with the authentication headers required for the Orders Feed.
./config/dev.json (extract)
"broker": {
...
"bookingPartners": {
"primary": {
"authentication": {
"initialAccessToken": null,
"ordersFeedRequestHeaders": {
"X-OpenActive-Test-Client-Id": "test"
}
}
},
"secondary": null
}
...
}
The
datasetSiteUrl
must be set to the local dataset site URL of your booking system. If you have not yet implemented a dataset site, details for creating it can be found here.In addition to the standard dataset site, the JSON-LD of the page must include the
accessService
property, as specified in the reference documentation. Note that the endpointURL
within the accessService
is most important, and must refer to your local Open Booking API Base URI../config/dev.json (extract)
"broker": {
...
"datasetSiteUrl": "https://reference-implementation.openactive.io/openactive"
...
}
With your booking system running, execute the following command in the root
openactive-test-suite
directory:npm start
This will automatically start the microservice, run the integration tests, then kill the microservice. The output from the microservice and integration tests will be combined in the console.
This mode also offers the ability to rerun the tests interactively, for specific flows, which can be useful for debugging. When running in this mode, press "esc" at any time to cancel the currently running test and return to the interactive prompt.
Individual features or tests can be run in isolation using the following commands, for example:
npm start -- --runInBand test/features/core/test-interface/
npm start -- test/features/core/test-interface/implemented/create-opportunity-test.js
The following shorthand may also be used, as these strings are unique within the path:
npm start test-interface
npm start create-opportunity-test
--runInBand
limits the test suite to running all tests in series. This ensures that each test is executed one at a time, which slows down the test suite, and can be helpful when debugging issues relating to faulty transactions.With your booking system running, execute the following command:
npm run start-broker
This will start to harvest the feeds from your running application.
With both your booking system and
openactive-broker-microservice
running, execute the following command, to execute all configured tests:npm run start-tests
This will execute tests against your booking system, using the
openactive-broker-microservice
as an intermediary.Individual features or tests can be run in isolation using the following commands, for example:
npm run start-tests -- --runInBand test/features/core/test-interface/
npm run start-tests -- --runInBand test/features/core/test-interface/implemented/create-opportunity-test.js
The
openactive-integration-tests
writes log files into the ./output/
directory for each test in Markdown format, so you can see the endpoints that have been called, with both the requests sent and responses received.To understand the requests and responses, please see the explanation in the Open Booking API specification, along with the more detailed sequence diagram and example requests and responses.
If you don't have an IDE that supports Markdown natively, use a Google Chrome extension to read the output Markdown files, as described here.
A reference version of passing test results is also available for comparison, complete with full model requests and responses for each test:
For continuous integration environments,
"ci": true
must be included in the supplied config JSON to ensure correct console logging output. Then simply run npm start
in the rootopenactive-test-suite
directory. This will automatically start the microservice, run the integration tests, then kill the microservice.This always overrides the configuration option
"waitForHarvestCompletion": true
, to ensure the harvester is up-to-date with the feeds before the tests begin.You can see CI in action within the test suite itself, which runs CI against the reference implementation.
The conformance certificate generated from test suite running in CI should be deployed to the relevant location (e.g. via GitHub CI) and referenced from the production Dataset Site. See here for more information.
Last modified 6mo ago