diff --git a/bin/beau b/bin/beau index 65fc1aa..19cae10 100755 --- a/bin/beau +++ b/bin/beau @@ -103,19 +103,19 @@ program .column('Endpoint', 20, [clc.cyan]) .output(); - beau.requests.list.forEach(({ VERB, ALIAS, ENDPOINT }) => + beau.requests.list.forEach(({ VERB, ALIAS, ENDPOINT, PATH }) => new Line() .padding(2) .column(VERB, 20, [clc.yellow]) .column(ALIAS, 30, [clc.yellow]) - .column(ENDPOINT) + .column(ENDPOINT.replace(/\/$/, '') + '/' + PATH.replace(/^\//, '')) .output() ); new Line().output(); } else { - beau.requests.list.forEach(({ VERB, ALIAS, ENDPOINT }) => { - console.log(`${VERB}\t${ALIAS}\t${ENDPOINT}`); + beau.requests.list.forEach(({ VERB, ALIAS, ENDPOINT, PATH }) => { + console.log(`${VERB}\t${ALIAS}\t${ENDPOINT.replace(/\/$/, '')}/${PATH.replace(/^\//, '')}`); }); } }); diff --git a/package-lock.json b/package-lock.json index 6360c81..80589f4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -5689,7 +5689,7 @@ "safe-buffer": { "version": "5.1.1", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz", - "integrity": "sha1-iTMSr2myEj3vcfV4iQAWce6yyFM=" + "integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg==" }, "safe-regex": { "version": "1.1.0", diff --git a/src/__mocks__/request-promise-native.js b/src/__mocks__/request-promise-native.js index 50c7dd5..520b6ce 100644 --- a/src/__mocks__/request-promise-native.js +++ b/src/__mocks__/request-promise-native.js @@ -8,7 +8,7 @@ function Request(request) { headers: request.headers, body: request.body, uri: { - href: request.url + href: `${request.baseUrl}${request.uri}` } }, statusCode: 200, diff --git a/src/__tests__/__snapshots__/beau.spec.js.snap b/src/__tests__/__snapshots__/beau.spec.js.snap index 24aeb3d..16e3093 100644 --- a/src/__tests__/__snapshots__/beau.spec.js.snap +++ b/src/__tests__/__snapshots__/beau.spec.js.snap @@ -177,11 +177,13 @@ Beau { Request { "ALIAS": "get-post", "DEPENDENCIES": Set {}, - "ENDPOINT": "http://jsonplaceholder.typicode.com/posts/1", + "ENDPOINT": "http://jsonplaceholder.typicode.com", + "FORM": undefined, "HEADERS": Object { "authentication": "hello", }, "PARAMS": undefined, + "PATH": "/posts/1", "PAYLOAD": undefined, "VERB": "GET", "originalRequest": Object { @@ -204,12 +206,14 @@ Beau { Request { "ALIAS": "user", "DEPENDENCIES": Set {}, - "ENDPOINT": "http://jsonplaceholder.typicode.com/user", + "ENDPOINT": "http://jsonplaceholder.typicode.com", + "FORM": undefined, "HEADERS": Object { "authentication": "hello", "hello": "world", }, "PARAMS": undefined, + "PATH": "/user", "PAYLOAD": undefined, "VERB": "GET", "originalRequest": Object { diff --git a/src/__tests__/request.spec.js b/src/__tests__/request.spec.js index c361869..652b54c 100644 --- a/src/__tests__/request.spec.js +++ b/src/__tests__/request.spec.js @@ -47,7 +47,7 @@ describe('Request', () => { it('should load up the given request', () => { expect(request.VERB).toBe('POST'); - expect(request.ENDPOINT).toBe(validRequestConfig.endpoint + '/user'); + expect(request.ENDPOINT).toBe(validRequestConfig.endpoint); expect(request.HEADERS).toBeDefined(); expect(request.PAYLOAD).toBeDefined(); expect(request.PARAMS).toBeDefined(); diff --git a/src/request.js b/src/request.js index ec4a485..abfc10d 100644 --- a/src/request.js +++ b/src/request.js @@ -22,7 +22,8 @@ class Request { PAYLOAD, ENDPOINT, PARAMS, - HEADERS + HEADERS, + FORM } = UpperCaseKeys(req); if (!ALIAS) { @@ -32,11 +33,13 @@ class Request { const { verb, path } = this.parseRequest(REQUEST); this.VERB = verb; - this.ENDPOINT = ENDPOINT + path; + this.ENDPOINT = ENDPOINT; + this.PATH = path; this.HEADERS = HEADERS; this.PAYLOAD = PAYLOAD; this.PARAMS = PARAMS; + this.FORM = FORM; this.ALIAS = ALIAS; @@ -77,19 +80,26 @@ class Request { async exec(cache = new RequestCache()) { let settings = cache.parse({ - url: this.ENDPOINT, + baseUrl: this.ENDPOINT, + uri: this.PATH, method: this.VERB, headers: this.HEADERS, qs: this.PARAMS, body: this.PAYLOAD, + form: this.FORM, json: true, simple: false, resolveWithFullResponse: true }); - settings = removeOptionalKeys(settings, ['headers', 'qs', 'body']); + settings = removeOptionalKeys(settings, [ + 'headers', + 'qs', + 'body', + 'form' + ]); settings = this.plugins.replaceDynamicValues(settings);