Added support for forms.

You can now pass a form key to the request and it'll set the header and
payload automatically.
This commit is contained in:
David Diaz 2018-04-26 11:59:35 -06:00
parent 3df90600ac
commit 9d10db3243
6 changed files with 27 additions and 13 deletions

View File

@ -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(/^\//, '')}`);
});
}
});

2
package-lock.json generated
View File

@ -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",

View File

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

View File

@ -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 {

View File

@ -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();

View File

@ -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);