@mimik/test-helper
v3.1.0
Published
Used for encapsulating user, token and fixture creation process while testing mimik microservices
Readme
Modules
Functions
test-helper
Example
import testHelper from '@mimik/test-helper';test-helper~runTests(conf, tests) ⇒ void
Run all tests using test-helper
Kind: inner method of test-helper
Category: async
| Param | Type | Description | | --- | --- | --- | | conf | object | Config to setup test helper to run test | | tests | function | Function containing mocha tests to run after and if test-helper is initialized successfully |
Example
conf:
{
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
}]
}test-helper~importTest(name, testFilePath, prepFilePath) ⇒ void
Import test scripts from other files to run using test-helper
Kind: inner method of test-helper
Category: async
| Param | Type | Description | | --- | --- | --- | | name | string | Name of the test to run | | testFilePath | string | Absolute file path of test scripts to be run | | prepFilePath | string | (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 |
prepTokens(tokenRequests, isFresh) ⇒ Promise.<object>
Create and prepare tokens to be used later on depending on request objects
Kind: global function
Returns: Promise.<object> - Generated tokens object
Category: async
| Param | Type | Description | | --- | --- | --- | | tokenRequests | Array.<object> | Array of objects containing specifications of tokens to be requested such as role, type(service), userKey and correlationId | | isFresh | boolean | (optional) To prepare new tokens and not use from cache |
Example
tokenRequests = [{ role: ROLES.USER, userKey: 'testUser', destType: SERVICES.H2BOXES }, { role: ROLES.ADMIN, destType: SERVICES.H2BOXES }]getFixture(key) ⇒ any
Get fixtures to be saved earlier
Kind: global function
Returns: any - Requested fixture or undefined if not found
Category: sync
| Param | Type | Description | | --- | --- | --- | | key | string | Key value which was used to store desired fixture |
setFixture(key, value) ⇒ void
Set fixtures to be used later
Kind: global function
Category: sync
| Param | Type | Description | | --- | --- | --- | | key | string | Unique key for fixture value to be saved | | value | any | Value to be stored for the given key |
getToken(tokenRequest) ⇒ string
Fetch the prepared tokens, prepared using prepTokens
Kind: global function
Returns: string - Requested token value
Category: sync
| Param | Type | Description | | --- | --- | --- | | tokenRequest | object | Object containing specifications of token to be fetched such as role, destType(service), userKey and correlationId |
Example
tokenRequest = { role: ROLES.USER, userKey: 'testUser', destType: SERVICES.H2BOXES }findUser(userKey) ⇒ object
Fetch pre-created user by uniqueName
Kind: global function
Returns: object - Value fetched will include user properties such as user_id, email and password
Category: sync
| Param | Type | Description | | --- | --- | --- | | userKey | string | Key value which was used to create user |
