Skip to content

Postman based acceptance tests for the Charging Module API service

License

Notifications You must be signed in to change notification settings

DEFRA/sroc-cha-acceptance-tests

Repository files navigation

SROC Charging Module API Acceptance tests

Build Status Licence

The Charging Module API provides an interface for calculating charges, creating and queuing transactions, and generating transaction and customer files used to produce Environment Agency invoices.

This project contains acceptance tests for the service. It is built using Newman and the Postman App.

Pre-requisites

You just need Node.js installed, ideally an LTS version.

You'll also need the Postman App installed. It's used to create maintain the collection of requests and associated tests we use. See cha.postman_collection.json.

Installation

First clone the repository and then drop into your new local repo

git clone https://github.com/DEFRA/sroc-cha-acceptance-tests.git && cd sroc-cha-acceptance-tests

Next download and install the dependencies

npm install

Configuration

Important! Do not add environment files to source control

We have 6 environments where the CHA could be running; local, development, test, integration, pre-production, and production.

For each environment you wish to test you'll need to create an environment file in environments/. An example with dummy data is provided as a reference.

For example, if you wanted to start testing the development environment the steps would be

  • duplicate example.postman_environment.json
  • rename to something meaningful; dev.postman_environment.json
  • update the name attribute to something meaningful: "name": "CHA DEV acceptance tests",
  • update the value attribute for each of the properties (baseUrl, tokenUrl, adminUser etc) to match the environment

You'll need to contact an existing team member to obtain the proper credentials.

Git is setup to ignore everything bar the example environment file. Even so, double check your environment file has not been comitted before pushing it to GitHub.

Execution

Running the tests involves firing all the requests in the cha.postman_collection.json combined with the values taken from the selected environment file. For example, if you wanted to test the development environment and had created the environment file dev.postman_environment.json you would call

npm start -- -e dev

The app will automatically look for a *.postman_environment.json with the matching prefix.

Folders

The primary means of grouping requests into a 'test' in Postman is using folders in your collection. We can tell Newman to only run the requests in a folder through the command line.

npm start -- -e dev -f bill-run-test

You can even specify multiple folders

npm start -- -e dev -f bill-run-test endpoints-check

If you have setup your collection so each folder represents a 'test', using the -f folders option allows you to select which 'tests' to run.

Naming folders

In the Postman app it makes perfect sense to name folders with spaces and capitals, for example, Bill run test. It looks more readable in the UI! But as the intention is to make them available on the command line to Newman, spaces and mixed cases in names can prove problematic.

If you can, stick to all lowercase and go with either snake_case or kebab-case rather than using spaces.

Reporters

Newman comes with some built-in reporters the default being the CLI reporter.

When you run the tests you can specify which of these reporters to use

npm start -- -e dev -r json

You can even specify multiple reporters

npm start -- -e dev -r cli json

If you don't set a reporter the tests will use cli as the default.

Html

We have also included support for the newman-reporter-htmlextra as well. Newman no longer has a built-in one and of the options this is our preferred. To use it just add html to your list of reporters

npm start -- -e dev -r cli html

CI

To check we haven't broken anything we have a separate Postman collection we use just when running our CI checks. If you call npm start example it will run the CI request and test rather than the main charging module ones.

Contributing to this project

If you have an idea you'd like to contribute please log an issue.

All contributions should be submitted via a pull request.

Licence

THIS INFORMATION IS LICENSED UNDER THE CONDITIONS OF THE OPEN GOVERNMENT LICENCE found at:

http://www.nationalarchives.gov.uk/doc/open-government-licence/version/3

The following attribution statement MUST be cited in your products and applications when using this information.

Contains public sector information licensed under the Open Government licence v3

About the licence

The Open Government Licence (OGL) was developed by the Controller of Her Majesty's Stationery Office (HMSO) to enable information providers in the public sector to license the use and re-use of their information under a common open licence.

It is designed to encourage use and re-use of information freely and flexibly, with only a few conditions.

About

Postman based acceptance tests for the Charging Module API service

Resources

License

Stars

Watchers

Forks