npm package: @mimik/test-helper
Description: Used for encapsulating user, token and fixture creation process while testing mimik microservices
Author: mimik technology inc
Latest version: 3.1.0

## Modules

<dl>
<dt><a href="#module_test-helper">test-helper</a></dt>
<dd></dd>
</dl>

## Functions

<dl>
<dt><a href="#prepTokens">prepTokens(tokenRequests, isFresh)</a> ⇒ <code>Promise.&lt;object&gt;</code></dt>
<dd><p>Create and prepare tokens to be used later on depending on request objects</p>
</dd>
<dt><a href="#getFixture">getFixture(key)</a> ⇒ <code>any</code></dt>
<dd><p>Get fixtures to be saved earlier</p>
</dd>
<dt><a href="#setFixture">setFixture(key, value)</a> ⇒ <code>void</code></dt>
<dd><p>Set fixtures to be used later</p>
</dd>
<dt><a href="#getToken">getToken(tokenRequest)</a> ⇒ <code>string</code></dt>
<dd><p>Fetch the prepared tokens, prepared using prepTokens</p>
</dd>
<dt><a href="#findUser">findUser(userKey)</a> ⇒ <code>object</code></dt>
<dd><p>Fetch pre-created user by uniqueName</p>
</dd>
</dl>

<a name="module_test-helper"></a>

## test-helper
**Example**  
```js
import testHelper from '@mimik/test-helper';
```

* [test-helper](#module_test-helper)
    * [~runTests(conf, tests)](#module_test-helper..runTests) ⇒ <code>void</code>
    * [~importTest(name, testFilePath, prepFilePath)](#module_test-helper..importTest) ⇒ <code>void</code>

<a name="module_test-helper..runTests"></a>

### test-helper~runTests(conf, tests) ⇒ <code>void</code>
Run all tests using test-helper

**Kind**: inner method of [<code>test-helper</code>](#module_test-helper)  
**Category**: async  

| Param | Type | Description |
| --- | --- | --- |
| conf | <code>object</code> | Config to setup test helper to run test |
| tests | <code>function</code> | Function containing mocha tests to run after and if test-helper is initialized successfully |

**Example**  
conf:
```javascript
{
 fixtures: {}, // All fixtures values
 serviceConfiguration: file, // ./configuration/config.js
 services: {
   MID: 'mID'
 },
 users: [{ // Array of users to be created for the test
   userKey, // This is going to be stored in the test to identify user in userHelper
   email, // Email of user
   password, // Password of user
 }]
}
```
<a name="module_test-helper..importTest"></a>

### test-helper~importTest(name, testFilePath, prepFilePath) ⇒ <code>void</code>
Import test scripts from other files to run using test-helper

**Kind**: inner method of [<code>test-helper</code>](#module_test-helper)  
**Category**: async  

| Param | Type | Description |
| --- | --- | --- |
| name | <code>string</code> | Name of the test to run |
| testFilePath | <code>string</code> | Absolute file path of test scripts to be run |
| prepFilePath | <code>string</code> | (optional) Absolute file path of prep scripts to be run before and after the test. This file can have loadReal, unloadReal, loadMock and unloadMock methods. 'load' and 'unload' methods run before and after the test respectively |

<a name="prepTokens"></a>

## prepTokens(tokenRequests, isFresh) ⇒ <code>Promise.&lt;object&gt;</code>
Create and prepare tokens to be used later on depending on request objects

**Kind**: global function  
**Returns**: <code>Promise.&lt;object&gt;</code> - Generated tokens object  
**Category**: async  

| Param | Type | Description |
| --- | --- | --- |
| tokenRequests | <code>Array.&lt;object&gt;</code> | Array of objects containing specifications of tokens to be requested such as role, type(service), userKey and correlationId |
| isFresh | <code>boolean</code> | (optional) To prepare new tokens and not use from cache |

**Example**  
```js
tokenRequests = [{ role: ROLES.USER, userKey: 'testUser', destType: SERVICES.H2BOXES }, { role: ROLES.ADMIN, destType: SERVICES.H2BOXES }]
```
<a name="getFixture"></a>

## getFixture(key) ⇒ <code>any</code>
Get fixtures to be saved earlier

**Kind**: global function  
**Returns**: <code>any</code> - Requested fixture or undefined if not found  
**Category**: sync  

| Param | Type | Description |
| --- | --- | --- |
| key | <code>string</code> | Key value which was used to store desired fixture |

<a name="setFixture"></a>

## setFixture(key, value) ⇒ <code>void</code>
Set fixtures to be used later

**Kind**: global function  
**Category**: sync  

| Param | Type | Description |
| --- | --- | --- |
| key | <code>string</code> | Unique key for fixture value to be saved |
| value | <code>any</code> | Value to be stored for the given key |

<a name="getToken"></a>

## getToken(tokenRequest) ⇒ <code>string</code>
Fetch the prepared tokens, prepared using prepTokens

**Kind**: global function  
**Returns**: <code>string</code> - Requested token value  
**Category**: sync  

| Param | Type | Description |
| --- | --- | --- |
| tokenRequest | <code>object</code> | Object containing specifications of token to be fetched such as role, destType(service), userKey and correlationId |

**Example**  
```js
tokenRequest = { role: ROLES.USER, userKey: 'testUser', destType: SERVICES.H2BOXES }
```
<a name="findUser"></a>

## findUser(userKey) ⇒ <code>object</code>
Fetch pre-created user by uniqueName

**Kind**: global function  
**Returns**: <code>object</code> - Value fetched will include user properties such as user_id, email and password  
**Category**: sync  

| Param | Type | Description |
| --- | --- | --- |
| userKey | <code>string</code> | Key value which was used to create user |