mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
Inline documentation for kbn_server test utility
This commit is contained in:
parent
eccb3d6f97
commit
4b0ac79c6f
1 changed files with 20 additions and 0 deletions
|
@ -31,16 +31,36 @@ const SERVER_DEFAULTS = {
|
|||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates an instance of KbnServer with default configuration
|
||||
* tailored for unit tests
|
||||
*
|
||||
* @param {object} params Any config overrides for this instance
|
||||
*/
|
||||
export function createServer(params = {}) {
|
||||
params = defaultsDeep({}, params, SERVER_DEFAULTS);
|
||||
return new KbnServer(params);
|
||||
};
|
||||
|
||||
/**
|
||||
* Creates request configuration with a basic auth header
|
||||
*/
|
||||
export function authOptions() {
|
||||
const authHeader = basicAuthHeader('user', 'notsecure');
|
||||
return set({}, 'headers.Authorization', authHeader);
|
||||
};
|
||||
|
||||
/**
|
||||
* Makes a request with test headers via hapi server inject()
|
||||
*
|
||||
* The given options are decorated with default testing options, so it's
|
||||
* recommended to use this function instead of using inject() directly whenever
|
||||
* possible throughout the tests.
|
||||
*
|
||||
* @param {KbnServer} kbnServer
|
||||
* @param {object} options Any additional options or overrides for inject()
|
||||
* @param {Function} fn The callback to pass as the second arg to inject()
|
||||
*/
|
||||
export function makeRequest(kbnServer, options, fn) {
|
||||
options = defaultsDeep({}, authOptions(), options);
|
||||
return kbnServer.server.inject(options, fn);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue