Git Product home page Git Product logo

prepaidutility-test-server's Introduction

prepaidutility-test-server CircleCI

REST server for testing implementations of the prepaidutility-service-interface.

Testing a Client

To test a client implementation an instance of this test server is provided at https://ppu-test-server.herokuapp.com.

Or you can run a containerized version of this test server locally using Docker:

docker pull electrum/prepaidutility-test-server:3
# Run the test server listening on localhost:8080
docker run -d -p 8080:8080 electrum/prepaidutility-test-server:3

Messages sent to this server via the URLs described in the prepaidutility-service-interface will be validated and responded to with mock data.

Testing message correctness

Messages will be validated for correctness against the service interface and in the event that a field is missing something similar to the following can be expected:

{
  "errorType": "FORMAT_ERROR",
  "errorMessage": "Bad formatting",
  "detailMessage": {
    "formatErrors": [
      {
        "field": "product",
        "msg": "may not be null",
        "value": "null"
      }
    ]
  }
}

An errorType of FORMAT_ERROR is returned followed by an explanation of the format errors as follows:

  • The field attribute containing the field that has been formatted incorrectly
  • The msg field contains information on what violation has occurred
  • The value field contains the incorrectly formatted value that was used

Testing a Server

Testing a server implementation can be done using this Postman (Collection v2) REST test pack. These tests consist of correctly formatted JSON messages that validate server responses. Tests may also consist of a message flow in which multiple related messages are sent sequentially to the server to test handling of stateful interactions (such as requests and confirmations).

The test pack is comprised of JSON files: PrepaidUtilityTestPack.postman_collection.json, PPUherokutest.postman_environment.json and PPUlocalhosttest.postman_environment.json. The postman_collection files are a collection of JSON tests that will be run. They contain JSON request messages and response validation scripts. These tests are dependent on variables contained in the the associated postman_environment files.

Running tests

There are two possible ways to run this test pack: either via the Postman desktop client or via newman, the command line interface for Postman.

Postman desktop client

  1. Download Postman at: https://www.getpostman.com/apps
  2. Import the test collection and environments via the Import option
  3. Open the Collection Runner and select the Runs tab
  4. Select a sub-collection and hit run

NOTE: If you want to run the sub-collection named 'Lookup-purchase-confirm' you will need to import the data file: test_meterIds-purchases.csv

Tests may be run individually from the main Postman view where test conditions and structures may be modified.

Newman

  1. Install newman (make sure npm is installed first):
npm install newman -g
  1. Run the tests (from the root directory of this repo):
newman run test/postman/PrepaidUtilityTestPack.postman_collection.json -e test/postman/PPUlocalhosttest.postman_environment.json --folder <folder_name>

If you would like to run the 'Lookup-purchase-confirm' folder of tests you will need to append -d test/postman/test_meterIds-purchases.csv -n 10 to the above command.

This will run tests against a Prepaid Utility Service server implementation hosted on localhost:8080 and provide a basic breakdown of which tests passed and failed.

prepaidutility-test-server's People

Contributors

neilmackellar avatar richardfourie avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.