From 23064040df55f3b40f14132992f44d76bd18fee9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sergio=20D=C3=ADaz?= Date: Tue, 22 May 2018 12:55:58 -0600 Subject: [PATCH] Stopped iterating over keys and started assigning instead. (#27) I don't actually remember why I did it this way. I probably wanted to be a lot more strict with the keys originally which seems silly in retrospective. --- src/__tests__/__snapshots__/beau.spec.js.snap | 8 ------- src/config.js | 4 +--- src/request.js | 23 ++----------------- 3 files changed, 3 insertions(+), 32 deletions(-) diff --git a/src/__tests__/__snapshots__/beau.spec.js.snap b/src/__tests__/__snapshots__/beau.spec.js.snap index 4132a10..7e07613 100644 --- a/src/__tests__/__snapshots__/beau.spec.js.snap +++ b/src/__tests__/__snapshots__/beau.spec.js.snap @@ -185,14 +185,10 @@ Beau { "COOKIEJAR": false, "DEPENDENCIES": Set {}, "ENDPOINT": "http://jsonplaceholder.typicode.com", - "FORM": undefined, - "FORMDATA": undefined, "HEADERS": Object { "authentication": "hello", }, - "PARAMS": undefined, "PATH": "/posts/1", - "PAYLOAD": undefined, "REQUEST": "GET /posts/1", "VERB": "GET", "originalRequest": Object { @@ -218,15 +214,11 @@ Beau { "COOKIEJAR": false, "DEPENDENCIES": Set {}, "ENDPOINT": "http://jsonplaceholder.typicode.com", - "FORM": undefined, - "FORMDATA": undefined, "HEADERS": Object { "authentication": "hello", "hello": "world", }, - "PARAMS": undefined, "PATH": "/user", - "PAYLOAD": undefined, "REQUEST": "GET /user", "VERB": "GET", "originalRequest": Object { diff --git a/src/config.js b/src/config.js index 4fda987..9beaaa5 100644 --- a/src/config.js +++ b/src/config.js @@ -18,9 +18,7 @@ class Config { this.doc = doc; let config = this.loadConfig(doc); - this.configKeys.forEach(k => { - this[k] = config[k] || this.defaultConfigValues[k]; - }); + Object.assign(this, this.defaultConfigValues, config); this.ENVIRONMENT = deepMerge(this.ENVIRONMENT, env); diff --git a/src/request.js b/src/request.js index 0c455da..6d531ae 100644 --- a/src/request.js +++ b/src/request.js @@ -14,20 +14,8 @@ class Request { this.originalRequest = req; this.plugins = plugins; - this.loadCofiguration( - [ - 'REQUEST', - 'ENDPOINT', - 'HEADERS', - 'PAYLOAD', - 'PARAMS', - 'FORM', - 'ALIAS', - 'COOKIEJAR', - 'FORMDATA' - ], - req - ); + req = UpperCaseKeys(req); + Object.assign(this, req); if (!this.ALIAS) { throw new Error(`${this.REQUEST} is missing an alias.`); @@ -41,13 +29,6 @@ class Request { this.DEPENDENCIES = this.findDependencies(req); } - loadCofiguration(keys, obj) { - obj = UpperCaseKeys(obj); - keys.forEach(k => { - this[k] = obj[k]; - }); - } - parseRequest(request) { const parts = request.match(requestRegex);