new HandlerBarHelper()

Description

Defines and registers custom handlebar helpers now, randomValue, capture and num_between

Methods


nowHelper() → {void}

Description

Registers now helper

  • If now helper is called without a format, set a default format as YYYY-MM-DD hh:mm:ss else use the format provided
  • Set default offset to be used if offset is not specified. Default offset is 0s i.e. no offset
  • If offset is defined the value will be stored in context.hash.offset, eg X days.
  • Split value by a space, first element will be the amount of offset i.e. X, second element will be unit of offset, i.e. days
  • Return a value with specified format and added offset
Returns

randomValueHelper() → {void}

Description

Registers randomValue helper

  • If length of randomValue is not specified, set default length to 16
  • If type of randomValue is not specified, set default type to ALPHANUMERIC
  • If uppercase is specified, and is of ALPHABETICAL or ALPHANUMERIC type, add _UPPER to the type
  • If type is UUID, return UUID, else generate a random value with specified type and length
Returns

requestHelper() → {void}

Description

Registers capture helper

  • Get the request object passed in from the context by calling template({request: req})
  • Get the from value passed in while calling {{capture from=}}, accepted values query, headers, path, body
  • For query and headers, key is required, else if not found a null/undefined value will be automatically returned.
  • For path additional input regex is mandatory, if not passed return error
  • For body additional inputs using and selector are mandatory, if not passed return error
Returns

numBetweenHelper() → {void}

Description

Registers num_between helper

  • If lower or upper value is not passed, return 0
  • If lower value is greater than upper value, log error and return 0
Returns

fileHelper() → {void}

Description

Registers file helper

  • If file path is not included in the defined handlebar, log an error.
  • If file path is passed, check if file exists and send the return value to HttpParser to process
Returns

codeHelper() → {void}

Description

Registers code helper

  • Define request and logger in the scope of the code helper context, allowing user to use request, logger in their mock files
  • If file path is passed, check if file exists and send the return value to HttpParser to process
  • Evaluate the response of the function passed in and return the resulting response object to HttpParser
Returns

injectHelper() → {void}

Description

Registers inject helper

  • Define request and logger in the scope of the code helper context
  • Evaluate the response of the function passed in and return the resulting response object to HttpParser
Returns

randomString( length, chars ) → {string}

Description

Generates an random sequence of characters

Parameters
Name Type Description
length number

length of generated string

chars string

A sequence of valid characters for a specified type returned by genCharArray

Returns

A random sequence of characters of specified length


randomFixedInteger( length ) → {number}

Description

Generates an random number of given length

Parameters
Name Type Description
length number

length of number of be generated

Returns

A number of specified length. i.e. 10 digit number: 2341912498


genCharArray( type ) → {string}

Description

Generates an string of characters to be used by randomString function for randomizing.

Parameters
Name Type Description
type string

Type of random value to be generated

Returns

A string of squence of valid characters according to type