Merge pull request #10 from Seich/next-forms

Added support for forms.
This commit is contained in:
Sergio Díaz 2018-04-26 15:00:22 -06:00 committed by GitHub
commit 979f93ddbb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 27 additions and 13 deletions

View File

@ -103,19 +103,19 @@ program
.column('Endpoint', 20, [clc.cyan]) .column('Endpoint', 20, [clc.cyan])
.output(); .output();
beau.requests.list.forEach(({ VERB, ALIAS, ENDPOINT }) => beau.requests.list.forEach(({ VERB, ALIAS, ENDPOINT, PATH }) =>
new Line() new Line()
.padding(2) .padding(2)
.column(VERB, 20, [clc.yellow]) .column(VERB, 20, [clc.yellow])
.column(ALIAS, 30, [clc.yellow]) .column(ALIAS, 30, [clc.yellow])
.column(ENDPOINT) .column(ENDPOINT.replace(/\/$/, '') + '/' + PATH.replace(/^\//, ''))
.output() .output()
); );
new Line().output(); new Line().output();
} else { } else {
beau.requests.list.forEach(({ VERB, ALIAS, ENDPOINT }) => { beau.requests.list.forEach(({ VERB, ALIAS, ENDPOINT, PATH }) => {
console.log(`${VERB}\t${ALIAS}\t${ENDPOINT}`); console.log(`${VERB}\t${ALIAS}\t${ENDPOINT.replace(/\/$/, '')}/${PATH.replace(/^\//, '')}`);
}); });
} }
}); });

2
package-lock.json generated
View File

@ -5689,7 +5689,7 @@
"safe-buffer": { "safe-buffer": {
"version": "5.1.1", "version": "5.1.1",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz", "resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.1.1.tgz",
"integrity": "sha1-iTMSr2myEj3vcfV4iQAWce6yyFM=" "integrity": "sha512-kKvNJn6Mm93gAczWVJg7wH+wGYWNrDHdWvpUmHyEsgCtIwwo3bqPtV4tR5tuPaUhTOo/kvhVwd8XwwOllGYkbg=="
}, },
"safe-regex": { "safe-regex": {
"version": "1.1.0", "version": "1.1.0",

View File

@ -8,7 +8,7 @@ function Request(request) {
headers: request.headers, headers: request.headers,
body: request.body, body: request.body,
uri: { uri: {
href: request.url href: `${request.baseUrl}${request.uri}`
} }
}, },
statusCode: 200, statusCode: 200,

View File

@ -177,11 +177,13 @@ Beau {
Request { Request {
"ALIAS": "get-post", "ALIAS": "get-post",
"DEPENDENCIES": Set {}, "DEPENDENCIES": Set {},
"ENDPOINT": "http://jsonplaceholder.typicode.com/posts/1", "ENDPOINT": "http://jsonplaceholder.typicode.com",
"FORM": undefined,
"HEADERS": Object { "HEADERS": Object {
"authentication": "hello", "authentication": "hello",
}, },
"PARAMS": undefined, "PARAMS": undefined,
"PATH": "/posts/1",
"PAYLOAD": undefined, "PAYLOAD": undefined,
"VERB": "GET", "VERB": "GET",
"originalRequest": Object { "originalRequest": Object {
@ -204,12 +206,14 @@ Beau {
Request { Request {
"ALIAS": "user", "ALIAS": "user",
"DEPENDENCIES": Set {}, "DEPENDENCIES": Set {},
"ENDPOINT": "http://jsonplaceholder.typicode.com/user", "ENDPOINT": "http://jsonplaceholder.typicode.com",
"FORM": undefined,
"HEADERS": Object { "HEADERS": Object {
"authentication": "hello", "authentication": "hello",
"hello": "world", "hello": "world",
}, },
"PARAMS": undefined, "PARAMS": undefined,
"PATH": "/user",
"PAYLOAD": undefined, "PAYLOAD": undefined,
"VERB": "GET", "VERB": "GET",
"originalRequest": Object { "originalRequest": Object {

View File

@ -47,7 +47,7 @@ describe('Request', () => {
it('should load up the given request', () => { it('should load up the given request', () => {
expect(request.VERB).toBe('POST'); expect(request.VERB).toBe('POST');
expect(request.ENDPOINT).toBe(validRequestConfig.endpoint + '/user'); expect(request.ENDPOINT).toBe(validRequestConfig.endpoint);
expect(request.HEADERS).toBeDefined(); expect(request.HEADERS).toBeDefined();
expect(request.PAYLOAD).toBeDefined(); expect(request.PAYLOAD).toBeDefined();
expect(request.PARAMS).toBeDefined(); expect(request.PARAMS).toBeDefined();

View File

@ -22,7 +22,8 @@ class Request {
PAYLOAD, PAYLOAD,
ENDPOINT, ENDPOINT,
PARAMS, PARAMS,
HEADERS HEADERS,
FORM
} = UpperCaseKeys(req); } = UpperCaseKeys(req);
if (!ALIAS) { if (!ALIAS) {
@ -32,11 +33,13 @@ class Request {
const { verb, path } = this.parseRequest(REQUEST); const { verb, path } = this.parseRequest(REQUEST);
this.VERB = verb; this.VERB = verb;
this.ENDPOINT = ENDPOINT + path; this.ENDPOINT = ENDPOINT;
this.PATH = path;
this.HEADERS = HEADERS; this.HEADERS = HEADERS;
this.PAYLOAD = PAYLOAD; this.PAYLOAD = PAYLOAD;
this.PARAMS = PARAMS; this.PARAMS = PARAMS;
this.FORM = FORM;
this.ALIAS = ALIAS; this.ALIAS = ALIAS;
@ -77,19 +80,26 @@ class Request {
async exec(cache = new RequestCache()) { async exec(cache = new RequestCache()) {
let settings = cache.parse({ let settings = cache.parse({
url: this.ENDPOINT, baseUrl: this.ENDPOINT,
uri: this.PATH,
method: this.VERB, method: this.VERB,
headers: this.HEADERS, headers: this.HEADERS,
qs: this.PARAMS, qs: this.PARAMS,
body: this.PAYLOAD, body: this.PAYLOAD,
form: this.FORM,
json: true, json: true,
simple: false, simple: false,
resolveWithFullResponse: true resolveWithFullResponse: true
}); });
settings = removeOptionalKeys(settings, ['headers', 'qs', 'body']); settings = removeOptionalKeys(settings, [
'headers',
'qs',
'body',
'form'
]);
settings = this.plugins.replaceDynamicValues(settings); settings = this.plugins.replaceDynamicValues(settings);