@mimik/test-helper
v3.2.1
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
- ~CORRELATION_ID : string
- ~GENERIC_HEADER : object
- ~ROLES : object
- ~SERVICES : object
- async
test-helper~CORRELATION_ID : string
Unique correlation id generated for the test run, prefixed with ---test---. Used in the x-correlation-id header of requests.
Kind: inner property of test-helper
test-helper~GENERIC_HEADER : object
Generic request header including Accept: application/json and the test x-correlation-id.
Kind: inner property of test-helper
test-helper~ROLES : object
Supported token roles: SYSTEM, ADMIN and USER.
Kind: inner property of test-helper
test-helper~SERVICES : object
Known services map (default MID/MPO); call SERVICES.set(services) to merge in custom services.
Kind: inner property of test-helper
test-helper~runTests(testHelperConf, tests) ⇒ void
Run all tests using test-helper
Kind: inner method of test-helper
Category: async
| Param | Type | Description | | --- | --- | --- | | testHelperConf | 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
testHelperConf:
{
fixtures: {}, // All fixtures values (must include a boolean USE_MOCK_PROFILES)
serviceConfiguration: file, // ./configuration/config.js (serverSettings.customerCode is required)
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
roles, // (optional) Array of role names to assign to the user, consumed by createUser
}]
}The optional --cycle npm flag (FULL, GENERATION or CLEANUP) controls which load/unload prep hooks run; it defaults to FULL.
test-helper~importTest(name, path, prepPath) ⇒ 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 |
| path | string | Absolute file path of test scripts to be run |
| prepPath | string | (optional) Absolute file path of prep scripts to be run before and after the test. The module may export an initialize(testStore) hook (called once with the suite's store before the test) and a default export with loadMock/loadReal/unloadMock/unloadReal methods. The load methods run before the test in the GENERATION and FULL cycles; the unload methods run after the test in the CLEANUP and FULL cycles. Mock vs real variants are selected by the USE_MOCK_PROFILES fixture. |
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, destType(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(prop) ⇒ any
Get a previously-saved fixture
Kind: global function
Returns: any - Requested fixture or undefined if not found
Category: sync
| Param | Type | Description | | --- | --- | --- | | prop | string | Key value which was used to store desired fixture |
setFixture(prop, value) ⇒ void
Set fixtures to be used later
Kind: global function
Category: sync
| Param | Type | Description | | --- | --- | --- | | prop | 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 userKey
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 |
