1.0.7 • Published 5 years ago

@francomelandri/intesta v1.0.7

Weekly downloads
9
License
MIT
Repository
github
Last release
5 years ago

intesta


INTEgration teST Api

Build Status NPM version License: MIT

Input parameters

ParameterDescription
descriptorFilefile descriptor of the api resources schema
sessionFilefile containing the session of the test
onSuccesscallback function in case of assertions are right
onFailcallback function in case of failed assertion

How to

Example about using intesta

const intesta = require('@francomelandri/intesta'),
    path = require('path')

const onSuccess = operation => {
    console.log (operation.name + ' OK')
}

const onFail = (operation, assertion) => {
    console.log (operation.name + ' FAIL')
}

const descriptorFile = path.join(__dirname, './descriptor.json')
const sessionFile = path.join(__dirname, './session.json')

intesta(descriptorFile, sessionFile, onSuccess, onFail)

Example of API descriptor file. This file define the schema of the resource API intesta is able to know.

{
	"apis": [
        {
            "name": "keepAlive",
            "path": "/keepalive",
            "verb": "GET",
            "params": ["param1", "param2"],
            "headers": ["User-Agent", "Accept"]
        },
        {
            "name": "whoAmI",
            "path": "/whoami",
            "verb": "GET",
            "params": ["name", "surname"],
            "headers": ["User-Agent", "Accept", "X-Auth"]
        },
        {
            "name": "AreYou",
            "path": "/areyou",
            "verb": "POST",
            "params": ["name", "surname"],
            "headers": ["User-Agent", "Content-Type", "Accept", "X-Auth"]
        }
    ]
}
fielddescription
namea unique name of the api resource used by session operation
paththe relative path of the resource
verbthe HTTP verb for the resource; at the moment the allowable verbs are: GET, POST, PUT, DELETE in order to let you bale to test a CRUD api
paramslist of possible parameters for the resource; query string or body
headerslist of headers needed to use the resource

Example of API session file. This file contains the description of the flow for the test intesta should perform

{
	"settings":{
		"environment" : "PROD",
		"url": "http://q7vv6.mocklab.io",
		"userAgent": "Chrome"
	},
	"operations" : [
		{
			"name" : "keepAlive_1",
			"operation": "keepAlive",
			"params": {
                "param1": "value1",
                "param2": "value2"
			},
			"headers": {
				"User-Agent": "{{{settings.userAgent}}}",
				"Accept": "application/json"
			}
        },
		{
			"name" : "WhoAmI_1",
			"operation": "whoAmI",
			"params": {
				"name": "{{{keepAlive_1.name}}}",
                "surname": "Melandri"
			},
			"headers": {
                "User-Agent": "{{{settings.userAgent}}}",
				"Accept": "application/json",
				"X-Auth": "{{{keepAlive_1.Auth}}}"
			},
			"assertions":[
				{
					"field": "{{{WhoAmI_1.message}}}",
					"comparison": "eq",
					"value": "Hello World"
				}
			]
        },
		{
			"name" : "AreYou_1",
			"operation": "AreYou",
			"params": {
				"name": "{{{keepAlive_1.name}}}",
                "surname": "Melandri"
			},
			"headers": {
                "User-Agent": "{{{settings.userAgent}}}",
				"Content-Type": "application/json",
				"Accept": "application/json",
				"X-Auth": "{{{keepAlive_1.Auth}}}"
			},
			"assertions":[
				{
					"field": "{{{AreYou_1.message}}}",
					"comparison": "eq",
					"value": "Yes you are"
				}
			]
        }
    ]
}
fielddescription
namea unique name for the operation. It can be used by other operation to retrieve field value using the mustache notation
operationlink to api resource description to validate the operation itself
paramslist of parameters values; you can use mustache notation for dynamic values
headerslist of headers values; you can use mustache notation for dynamic values
assertionslist of assertions description in order to check if the api resource response is valid or not.
field: the response field value to check
comparison: could be eq or neq
value: the expected value

Mustache

You can refer to operation output in each session field value using the mustache annotation

In the previous session example you can see

...
		"assertions":[
				{
					"field": "{{{AreYou_1.message}}}",
					"comparison": "eq",
					"value": "Yes you are"
				}
			]
...

that means the field is the evaluation of the response field message of the AreYou_1 operation.

In this way you can link output values of some operations to input value of another; it is very useful to concatenate a list of operations creating a flow.

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago