Testing booking
A guide for setting up the OpenActive Test Suite for the Open Booking API.

Overview

The OpenActive Test Suite consists of two key components:

Step 1: Install the test suite

Clone the test suite repository locally, and install its dependencies.
Node.js version 14 or above is required (which version am I using?).
1
git clone [email protected]:openactive/openactive-test-suite.git
2
cd openactive-test-suite
3
npm install
Copied!
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:
1
npm start -- core
Copied!
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.

Step 2: Create a local configuration file

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
1
export NODE_ENV=dev
2
npm start -- core
Copied!
1
set NODE_ENV=dev
2
npm start -- core
Copied!
Adding other ./config/{NODE_ENV}.json files allows you to override the default configuration. For more information see this documentation.

Step 3: Configure flows

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)
1
"integrationTests": {
2
...
3
"bookingFlowsInScope": {
4
"OpenBookingSimpleFlow": true,
5
"OpenBookingApprovalFlow": true
6
},
7
...
8
}
Copied!

Step 4: Configure features

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.
Configure the test suite accordingly, as detailed in the reference documentation, for example:
./config/dev.json (extract)
1
"integrationTests": {
2
...
3
"implementedFeatures": {
4
"opportunity-feed": true,
5
"dataset-site": true,
6
"availability-check": true,
7
...
8
}
9
...
10
}
Copied!
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.

Step 5: Configure Opportunity Types

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)
1
"integrationTests": {
2
...
3
"bookableOpportunityTypesInScope": {
4
"ScheduledSession": true,
5
"FacilityUseSlot": false,
6
"IndividualFacilityUseSlot": false,
7
"CourseInstance": false,
8
"CourseInstanceSubEvent": false,
9
"HeadlineEvent": false,
10
"HeadlineEventSubEvent": false,
11
"Event": false,
12
"OnDemandEvent": false
13
},
14
...
15
}
Copied!

Step 6: Choose Controlled vs Random testing mode

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.

Random mode

./config/dev.json (extract)
1
"integrationTests": {
2
...
3
"useRandomOpportunities": true
4
...
5
}
Copied!
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.

Controlled mode

./config/dev.json (extract)
1
"integrationTests": {
2
...
3
"useRandomOpportunities": false
4
...
5
}
Copied!
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.

Step 7: Configure Sellers and Booking Authentication

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.
See the reference documentation for more information.
./config/dev.json (extract)
1
"sellers": {
2
"primary": {
3
"@type": "Organization",
4
"@id": "https://localhost:5001/api/identifiers/sellers/1",
5
"authentication": {
6
"loginCredentials": null,
7
"requestHeaders": {
8
"X-OpenActive-Test-Client-Id": "test",
9
"X-OpenActive-Test-Seller-Id": "https://localhost:5001/api/identifiers/sellers/1"
10
}
11
}
12
},
13
"secondary": {
14
"@type": "Organization",
15
"@id": "https://localhost:5001/api/identifiers/sellers/2",
16
"authentication": {
17
"loginCredentials": null,
18
"requestHeaders": {
19
"X-OpenActive-Test-Client-Id": "test",
20
"X-OpenActive-Test-Seller-Id": "https://localhost:5001/api/identifiers/sellers/2"
21
}
22
}
23
}
24
}
Copied!

Step 8: Configure Orders Feed Authentication

Configure the broker microservice with the authentication headers required for the Orders Feed.
./config/dev.json (extract)
1
"broker": {
2
...
3
"bookingPartners": {
4
"primary": {
5
"authentication": {
6
"initialAccessToken": null,
7
"ordersFeedRequestHeaders": {
8
"X-OpenActive-Test-Client-Id": "test"
9
}
10
}
11
},
12
"secondary": null
13
}
14
...
15
}
Copied!

Step 9: Configure Dataset Site

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)
1
"broker": {
2
...
3
"datasetSiteUrl": "https://reference-implementation.openactive.io/openactive"
4
...
5
}
Copied!

Step 10: Run the test suite

Option 1: Single console window

With your booking system running, execute the following command in the rootopenactive-test-suite directory:
1
npm start
Copied!
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:
1
npm start -- --runInBand test/features/core/test-interface/
Copied!
1
npm start -- test/features/core/test-interface/implemented/create-opportunity-test.js
Copied!
The following shorthand may also be used, as these strings are unique within the path:
1
npm start test-interface
Copied!
1
npm start create-opportunity-test
Copied!
--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.

Option 2: Two separate console windows

Start the Microservice

With your booking system running, execute the following command:
1
npm run start-broker
Copied!
This will start to harvest the feeds from your running application.

Run the Integration Tests

With both your booking system and openactive-broker-microservice running, execute the following command, to execute all configured tests:
1
npm run start-tests
Copied!
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:
1
npm run start-tests -- --runInBand test/features/core/test-interface/
Copied!
1
npm run start-tests -- --runInBand test/features/core/test-interface/implemented/create-opportunity-test.js
Copied!

Reading the test results and debugging

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:

Continuous Integration

For continuous integration environments 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.
A sample CI script is available, and more details can be found here.
You can see CI in action within the test suite itself, which runs CI against the reference implementation.
Last modified 2mo ago