Module: models/behaviors

The functionality behind the _behaviors field in the API, supporting post-processing responses

Source:

Methods

(inner) copy(originalRequest, responsePromise, copyArray, logger) → {Object}

Copies a value from the request and replaces response tokens with that value

Parameters:
Name Type Description
originalRequest Object

The request object, in case post-processing depends on it

responsePromise Object

The promise returning the response

copyArray function

The list of values to copy

logger Object

The mountebank logger, useful in debugging

Source:
Returns:
Type
Object

(inner) decorate(originalRequest, responsePromise, fn, logger) → {Object}

Runs the response through a post-processing function provided by the user

Parameters:
Name Type Description
originalRequest Object

The request object, in case post-processing depends on it

responsePromise Object

The promise returning the response

fn function

The function that performs the post-processing

logger Object

The mountebank logger, useful in debugging

Source:
Returns:
Type
Object

(inner) execute(request, response, behaviors, logger) → {Object}

The entry point to execute all behaviors provided in the API

Parameters:
Name Type Description
request Object

The request object

response Object

The response generated from the stubs

behaviors Object

The behaviors specified in the API

logger Object

The mountebank logger, useful for debugging

Source:
Returns:
Type
Object

(inner) lookup(originalRequest, responsePromise, lookupArray, logger) → {Object}

Looks up request values from a data source and replaces response tokens with the resulting data

Parameters:
Name Type Description
originalRequest Object

The request object

responsePromise Object

The promise returning the response

lookupArray function

The list of lookup configurations

logger Object

The mountebank logger, useful in debugging

Source:
Returns:
Type
Object

(inner) shellTransform(request, responsePromise, commandArray, logger) → {Object}

Runs the response through a shell function, passing the JSON in as stdin and using
stdout as the new response

Parameters:
Name Type Description
request Object

Will be the first arg to the command

responsePromise Object

The promise chain for building the response, which will be the second arg

commandArray string

The list of shell commands to execute, in order

logger Object

The mountebank logger, useful in debugging

Source:
Returns:
Type
Object

(inner) validate(config) → {Object}

Validates the behavior configuration and returns all errors

Parameters:
Name Type Description
config Object

The behavior configuration

Source:
Returns:

The array of errors

Type
Object

(inner) wait(request, responsePromise, millisecondsOrFn, logger) → {Object}

Waits a specified number of milliseconds before sending the response. Due to the approximate
nature of the timer, there is no guarantee that it will wait the given amount, but it will be close.

Parameters:
Name Type Description
request Object

The request object

responsePromise Object

kThe promise returning the response

millisecondsOrFn number

The number of milliseconds to wait before returning, or a function returning milliseconds

logger Object

The mountebank logger, useful for debugging

Source:
Returns:

A promise resolving to the response

Type
Object