Skip to content

Latest commit

 

History

History
90 lines (71 loc) · 1.9 KB

readme.md

File metadata and controls

90 lines (71 loc) · 1.9 KB

Loopback 3 API Testing with 'realm' users

This package is a simplified replacement for loopback-testing, which is now considered deprecated. It generates Mocha tests for Loopback API routes and examines their response codes. Optimized for Loopback 3 with realm

The main difference between this package and loopback-testing is that loopback-api-testing does not require you to write any code. Tests are specified in json format and the tests are generated automatically.

This package is not supported by, endorsed by, or associated with Strongloop or the core Loopback team.

Installing

npm i https://github.com/Monstrik/loopback-api-testing.git
npm i mocha -g

Example Usage

cd api-test-example
npm i
npm test

Running the tests (for example):

mocha --reporter spec test

Making Authenticated Requests

You can specify a username and password in your tests to make the request as an authenticated user.

[
  {
    "method": "GET",
    "path": "Model",
    "email": "my@user.com",
    "password": "myPassword",
    "realm":"REALM1"
    "expect": 200
  }
]

Making Requests with Data

You can send json data with a request.

[
  {
    "method": "POST",
    "model": "Cars",
    "withData": {
      "color": "blue"
    },
    "expect": 200
  }
]

Making Requests with query param

You can add userId in query with a request.

api/customers/{currentUserId}?auth...

[
   {
        "method": "PATCH",
        "path": "api/customers/",
        "password": "TestUser@TestUser.com",
        "realm": "SUYC",
        "email": "TestUser@TestUser.com",
        "withPathValues": [
          "{currentUserId}"
        ],
        "withData": {
          "FirstName": "NewName2"
        },
        "expect": 200
      }
]