mirror of https://github.com/Seich/Beau.git
Removed redundant fields from the config class.
This commit is contained in:
parent
2560403dff
commit
7aed5f0085
|
|
@ -45,25 +45,6 @@ Config {
|
|||
"HOSTS",
|
||||
"COOKIEJAR",
|
||||
],
|
||||
"defaultConfigValues": Object {
|
||||
"COOKIEJAR": false,
|
||||
"DEFAULTS": Object {},
|
||||
"ENDPOINT": "",
|
||||
"ENVIRONMENT": Object {},
|
||||
"HOSTS": Array [],
|
||||
"PLUGINS": Array [],
|
||||
"VERSION": 1,
|
||||
},
|
||||
"doc": Object {
|
||||
"GET /anything": Object {
|
||||
"alias": "anything",
|
||||
"payload": Object {
|
||||
"name": "$env.params.name",
|
||||
},
|
||||
},
|
||||
"endpoint": "https://example.org/",
|
||||
"version": 1,
|
||||
},
|
||||
}
|
||||
`;
|
||||
|
||||
|
|
|
|||
|
|
@ -51,31 +51,6 @@ Beau {
|
|||
"HOSTS",
|
||||
"COOKIEJAR",
|
||||
],
|
||||
"defaultConfigValues": Object {
|
||||
"COOKIEJAR": false,
|
||||
"DEFAULTS": Object {},
|
||||
"ENDPOINT": "",
|
||||
"ENVIRONMENT": Object {},
|
||||
"HOSTS": Array [],
|
||||
"PLUGINS": Array [],
|
||||
"VERSION": 1,
|
||||
},
|
||||
"doc": Object {
|
||||
"GET /posts/1": "get-post",
|
||||
"GET /user": Object {
|
||||
"alias": "user",
|
||||
"headers": Object {
|
||||
"hello": "world",
|
||||
},
|
||||
},
|
||||
"defaults": Object {
|
||||
"headers": Object {
|
||||
"authentication": "hello",
|
||||
},
|
||||
},
|
||||
"endpoint": "http://jsonplaceholder.typicode.com",
|
||||
"version": 1,
|
||||
},
|
||||
},
|
||||
"requests": RequestList {
|
||||
"REQUESTS": Array [
|
||||
|
|
@ -153,31 +128,6 @@ Beau {
|
|||
"HOSTS",
|
||||
"COOKIEJAR",
|
||||
],
|
||||
"defaultConfigValues": Object {
|
||||
"COOKIEJAR": false,
|
||||
"DEFAULTS": Object {},
|
||||
"ENDPOINT": "",
|
||||
"ENVIRONMENT": Object {},
|
||||
"HOSTS": Array [],
|
||||
"PLUGINS": Array [],
|
||||
"VERSION": 1,
|
||||
},
|
||||
"doc": Object {
|
||||
"GET /posts/1": "get-post",
|
||||
"GET /user": Object {
|
||||
"alias": "user",
|
||||
"headers": Object {
|
||||
"hello": "world",
|
||||
},
|
||||
},
|
||||
"defaults": Object {
|
||||
"headers": Object {
|
||||
"authentication": "hello",
|
||||
},
|
||||
},
|
||||
"endpoint": "http://jsonplaceholder.typicode.com",
|
||||
"version": 1,
|
||||
},
|
||||
},
|
||||
"list": Array [
|
||||
Request {
|
||||
|
|
|
|||
|
|
@ -119,55 +119,6 @@ Config {
|
|||
"HOSTS",
|
||||
"COOKIEJAR",
|
||||
],
|
||||
"defaultConfigValues": Object {
|
||||
"COOKIEJAR": false,
|
||||
"DEFAULTS": Object {},
|
||||
"ENDPOINT": "",
|
||||
"ENVIRONMENT": Object {},
|
||||
"HOSTS": Array [],
|
||||
"PLUGINS": Array [],
|
||||
"VERSION": 1,
|
||||
},
|
||||
"doc": Object {
|
||||
"GET /e1": "e1",
|
||||
"defaults": Object {
|
||||
"HEADERS": Object {
|
||||
"hello": "mars",
|
||||
},
|
||||
},
|
||||
"endpoint": "http://example.org",
|
||||
"hosts": Array [
|
||||
Object {
|
||||
"GET /e2": "e2",
|
||||
"GET /posts": "posts",
|
||||
"defaults": Object {
|
||||
"HEADERS": Object {
|
||||
"hello": "world",
|
||||
"world": "hello",
|
||||
},
|
||||
},
|
||||
"endpoint": "http://example.com",
|
||||
"host": "com",
|
||||
},
|
||||
Object {
|
||||
"GET /e3": "e3",
|
||||
"GET /posts": "posts",
|
||||
"defaults": Object {
|
||||
"HEADERS": Object {
|
||||
"hello": "world",
|
||||
"world": "bye",
|
||||
},
|
||||
},
|
||||
"endpoint": "http://example.net",
|
||||
"host": "net",
|
||||
},
|
||||
Object {
|
||||
"GET /posts": "posts",
|
||||
"endpoint": "http://example.info",
|
||||
"host": "info",
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
`;
|
||||
|
||||
|
|
@ -221,30 +172,5 @@ Config {
|
|||
"HOSTS",
|
||||
"COOKIEJAR",
|
||||
],
|
||||
"defaultConfigValues": Object {
|
||||
"COOKIEJAR": false,
|
||||
"DEFAULTS": Object {},
|
||||
"ENDPOINT": "",
|
||||
"ENVIRONMENT": Object {},
|
||||
"HOSTS": Array [],
|
||||
"PLUGINS": Array [],
|
||||
"VERSION": 1,
|
||||
},
|
||||
"doc": Object {
|
||||
"GET /posts/1": "get-post",
|
||||
"GET /user": Object {
|
||||
"alias": "user",
|
||||
"headers": Object {
|
||||
"hello": "world",
|
||||
},
|
||||
},
|
||||
"defaults": Object {
|
||||
"HEADERS": Object {
|
||||
"authentication": "hello",
|
||||
},
|
||||
},
|
||||
"endpoint": "http://jsonplaceholder.typicode.com",
|
||||
"version": 1,
|
||||
},
|
||||
}
|
||||
`;
|
||||
|
|
|
|||
|
|
@ -61,6 +61,7 @@ describe('Config', () => {
|
|||
|
||||
it('should load multiple hosts', () => {
|
||||
const doc = yaml.safeLoad(`
|
||||
version: 1
|
||||
endpoint: http://example.org
|
||||
|
||||
defaults:
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
const deepMerge = require('deepmerge');
|
||||
const { requestRegex, UpperCaseKeys } = require('./shared');
|
||||
const Plugins = require('./plugins');
|
||||
const version = parseInt(require('../package.json').version, 10);
|
||||
|
||||
class Config {
|
||||
constructor(doc, env = {}) {
|
||||
this.defaultConfigValues = {
|
||||
VERSION: 1,
|
||||
const defaultConfigValues = {
|
||||
VERSION: version,
|
||||
ENDPOINT: '',
|
||||
PLUGINS: [],
|
||||
DEFAULTS: {},
|
||||
|
|
@ -14,11 +15,10 @@ class Config {
|
|||
COOKIEJAR: false
|
||||
};
|
||||
|
||||
this.configKeys = Object.keys(this.defaultConfigValues);
|
||||
this.doc = doc;
|
||||
this.configKeys = Object.keys(defaultConfigValues);
|
||||
|
||||
let config = this.loadConfig(doc);
|
||||
Object.assign(this, this.defaultConfigValues, config);
|
||||
Object.assign(this, defaultConfigValues, config);
|
||||
|
||||
this.ENVIRONMENT = deepMerge(this.ENVIRONMENT, env);
|
||||
|
||||
|
|
@ -29,21 +29,18 @@ class Config {
|
|||
ENDPOINT: this.ENDPOINT
|
||||
});
|
||||
|
||||
this.loadHosts(this.HOSTS, config);
|
||||
this.loadHosts(this.HOSTS, config, defaultConfigValues);
|
||||
|
||||
this.PLUGINS = new Plugins(this.PLUGINS);
|
||||
}
|
||||
|
||||
loadHosts(hosts, rootConfig) {
|
||||
loadHosts(hosts, rootConfig, defaultConfigValues) {
|
||||
hosts.forEach(host => {
|
||||
if (typeof host.host === 'undefined') {
|
||||
throw new Error(`Host doesn't indicate it's host name.`);
|
||||
}
|
||||
|
||||
let config = deepMerge(
|
||||
this.defaultConfigValues,
|
||||
this.loadConfig(host)
|
||||
);
|
||||
let config = deepMerge(defaultConfigValues, this.loadConfig(host));
|
||||
|
||||
config.DEFAULTS = deepMerge(rootConfig.DEFAULTS, config.DEFAULTS);
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue