Merge pull request #11 from Seich/next-cookies

Added basic cookies support.
This commit is contained in:
Sergio Díaz 2018-04-26 17:53:55 -06:00 committed by GitHub
commit 17971a3cca
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 38 additions and 3 deletions

View File

@ -4,6 +4,7 @@ exports[`Beau's config Loader. should create a request list 1`] = `
Beau { Beau {
"config": Config { "config": Config {
"CACHE": false, "CACHE": false,
"COOKIEJAR": false,
"DEFAULTS": Object { "DEFAULTS": Object {
"headers": Object { "headers": Object {
"authentication": "hello", "authentication": "hello",
@ -23,6 +24,7 @@ Beau {
"REQUESTS": Array [ "REQUESTS": Array [
Object { Object {
"ALIAS": "get-post", "ALIAS": "get-post",
"COOKIEJAR": false,
"ENDPOINT": "http://jsonplaceholder.typicode.com", "ENDPOINT": "http://jsonplaceholder.typicode.com",
"HEADERS": Object { "HEADERS": Object {
"authentication": "hello", "authentication": "hello",
@ -31,6 +33,7 @@ Beau {
}, },
Object { Object {
"ALIAS": "user", "ALIAS": "user",
"COOKIEJAR": false,
"ENDPOINT": "http://jsonplaceholder.typicode.com", "ENDPOINT": "http://jsonplaceholder.typicode.com",
"HEADERS": Object { "HEADERS": Object {
"authentication": "hello", "authentication": "hello",
@ -48,9 +51,11 @@ Beau {
"DEFAULTS", "DEFAULTS",
"ENVIRONMENT", "ENVIRONMENT",
"HOSTS", "HOSTS",
"COOKIEJAR",
], ],
"defaultConfigValues": Object { "defaultConfigValues": Object {
"CACHE": false, "CACHE": false,
"COOKIEJAR": false,
"DEFAULTS": Object {}, "DEFAULTS": Object {},
"ENDPOINT": "", "ENDPOINT": "",
"ENVIRONMENT": Object {}, "ENVIRONMENT": Object {},
@ -79,6 +84,7 @@ Beau {
"REQUESTS": Array [ "REQUESTS": Array [
Object { Object {
"ALIAS": "get-post", "ALIAS": "get-post",
"COOKIEJAR": false,
"ENDPOINT": "http://jsonplaceholder.typicode.com", "ENDPOINT": "http://jsonplaceholder.typicode.com",
"HEADERS": Object { "HEADERS": Object {
"authentication": "hello", "authentication": "hello",
@ -87,6 +93,7 @@ Beau {
}, },
Object { Object {
"ALIAS": "user", "ALIAS": "user",
"COOKIEJAR": false,
"ENDPOINT": "http://jsonplaceholder.typicode.com", "ENDPOINT": "http://jsonplaceholder.typicode.com",
"HEADERS": Object { "HEADERS": Object {
"authentication": "hello", "authentication": "hello",
@ -102,6 +109,7 @@ Beau {
}, },
"config": Config { "config": Config {
"CACHE": false, "CACHE": false,
"COOKIEJAR": false,
"DEFAULTS": Object { "DEFAULTS": Object {
"headers": Object { "headers": Object {
"authentication": "hello", "authentication": "hello",
@ -121,6 +129,7 @@ Beau {
"REQUESTS": Array [ "REQUESTS": Array [
Object { Object {
"ALIAS": "get-post", "ALIAS": "get-post",
"COOKIEJAR": false,
"ENDPOINT": "http://jsonplaceholder.typicode.com", "ENDPOINT": "http://jsonplaceholder.typicode.com",
"HEADERS": Object { "HEADERS": Object {
"authentication": "hello", "authentication": "hello",
@ -129,6 +138,7 @@ Beau {
}, },
Object { Object {
"ALIAS": "user", "ALIAS": "user",
"COOKIEJAR": false,
"ENDPOINT": "http://jsonplaceholder.typicode.com", "ENDPOINT": "http://jsonplaceholder.typicode.com",
"HEADERS": Object { "HEADERS": Object {
"authentication": "hello", "authentication": "hello",
@ -146,9 +156,11 @@ Beau {
"DEFAULTS", "DEFAULTS",
"ENVIRONMENT", "ENVIRONMENT",
"HOSTS", "HOSTS",
"COOKIEJAR",
], ],
"defaultConfigValues": Object { "defaultConfigValues": Object {
"CACHE": false, "CACHE": false,
"COOKIEJAR": false,
"DEFAULTS": Object {}, "DEFAULTS": Object {},
"ENDPOINT": "", "ENDPOINT": "",
"ENVIRONMENT": Object {}, "ENVIRONMENT": Object {},
@ -176,6 +188,7 @@ Beau {
"list": Array [ "list": Array [
Request { Request {
"ALIAS": "get-post", "ALIAS": "get-post",
"COOKIEJAR": false,
"DEPENDENCIES": Set {}, "DEPENDENCIES": Set {},
"ENDPOINT": "http://jsonplaceholder.typicode.com", "ENDPOINT": "http://jsonplaceholder.typicode.com",
"FORM": undefined, "FORM": undefined,
@ -188,6 +201,7 @@ Beau {
"VERB": "GET", "VERB": "GET",
"originalRequest": Object { "originalRequest": Object {
"ALIAS": "get-post", "ALIAS": "get-post",
"COOKIEJAR": false,
"ENDPOINT": "http://jsonplaceholder.typicode.com", "ENDPOINT": "http://jsonplaceholder.typicode.com",
"HEADERS": Object { "HEADERS": Object {
"authentication": "hello", "authentication": "hello",
@ -205,6 +219,7 @@ Beau {
}, },
Request { Request {
"ALIAS": "user", "ALIAS": "user",
"COOKIEJAR": false,
"DEPENDENCIES": Set {}, "DEPENDENCIES": Set {},
"ENDPOINT": "http://jsonplaceholder.typicode.com", "ENDPOINT": "http://jsonplaceholder.typicode.com",
"FORM": undefined, "FORM": undefined,
@ -218,6 +233,7 @@ Beau {
"VERB": "GET", "VERB": "GET",
"originalRequest": Object { "originalRequest": Object {
"ALIAS": "user", "ALIAS": "user",
"COOKIEJAR": false,
"ENDPOINT": "http://jsonplaceholder.typicode.com", "ENDPOINT": "http://jsonplaceholder.typicode.com",
"HEADERS": Object { "HEADERS": Object {
"authentication": "hello", "authentication": "hello",

View File

@ -3,6 +3,7 @@
exports[`Config should load multiple hosts 1`] = ` exports[`Config should load multiple hosts 1`] = `
Config { Config {
"CACHE": false, "CACHE": false,
"COOKIEJAR": false,
"DEFAULTS": Object { "DEFAULTS": Object {
"HEADERS": Object { "HEADERS": Object {
"hello": "mars", "hello": "mars",
@ -52,6 +53,7 @@ Config {
"REQUESTS": Array [ "REQUESTS": Array [
Object { Object {
"ALIAS": "e1", "ALIAS": "e1",
"COOKIEJAR": false,
"ENDPOINT": "http://example.org", "ENDPOINT": "http://example.org",
"HEADERS": Object { "HEADERS": Object {
"hello": "mars", "hello": "mars",
@ -60,6 +62,7 @@ Config {
}, },
Object { Object {
"ALIAS": "com:e2", "ALIAS": "com:e2",
"COOKIEJAR": false,
"ENDPOINT": "http://example.com", "ENDPOINT": "http://example.com",
"HEADERS": Object { "HEADERS": Object {
"hello": "world", "hello": "world",
@ -69,6 +72,7 @@ Config {
}, },
Object { Object {
"ALIAS": "com:posts", "ALIAS": "com:posts",
"COOKIEJAR": false,
"ENDPOINT": "http://example.com", "ENDPOINT": "http://example.com",
"HEADERS": Object { "HEADERS": Object {
"hello": "world", "hello": "world",
@ -78,6 +82,7 @@ Config {
}, },
Object { Object {
"ALIAS": "net:e3", "ALIAS": "net:e3",
"COOKIEJAR": false,
"ENDPOINT": "http://example.net", "ENDPOINT": "http://example.net",
"HEADERS": Object { "HEADERS": Object {
"hello": "world", "hello": "world",
@ -87,6 +92,7 @@ Config {
}, },
Object { Object {
"ALIAS": "net:posts", "ALIAS": "net:posts",
"COOKIEJAR": false,
"ENDPOINT": "http://example.net", "ENDPOINT": "http://example.net",
"HEADERS": Object { "HEADERS": Object {
"hello": "world", "hello": "world",
@ -96,6 +102,7 @@ Config {
}, },
Object { Object {
"ALIAS": "info:posts", "ALIAS": "info:posts",
"COOKIEJAR": false,
"ENDPOINT": "http://example.info", "ENDPOINT": "http://example.info",
"HEADERS": Object { "HEADERS": Object {
"hello": "mars", "hello": "mars",
@ -112,9 +119,11 @@ Config {
"DEFAULTS", "DEFAULTS",
"ENVIRONMENT", "ENVIRONMENT",
"HOSTS", "HOSTS",
"COOKIEJAR",
], ],
"defaultConfigValues": Object { "defaultConfigValues": Object {
"CACHE": false, "CACHE": false,
"COOKIEJAR": false,
"DEFAULTS": Object {}, "DEFAULTS": Object {},
"ENDPOINT": "", "ENDPOINT": "",
"ENVIRONMENT": Object {}, "ENVIRONMENT": Object {},
@ -168,6 +177,7 @@ Config {
exports[`Config should set up defaults for all requests 1`] = ` exports[`Config should set up defaults for all requests 1`] = `
Config { Config {
"CACHE": false, "CACHE": false,
"COOKIEJAR": false,
"DEFAULTS": Object { "DEFAULTS": Object {
"HEADERS": Object { "HEADERS": Object {
"authentication": "hello", "authentication": "hello",
@ -187,6 +197,7 @@ Config {
"REQUESTS": Array [ "REQUESTS": Array [
Object { Object {
"ALIAS": "get-post", "ALIAS": "get-post",
"COOKIEJAR": false,
"ENDPOINT": "http://jsonplaceholder.typicode.com", "ENDPOINT": "http://jsonplaceholder.typicode.com",
"HEADERS": Object { "HEADERS": Object {
"authentication": "hello", "authentication": "hello",
@ -195,6 +206,7 @@ Config {
}, },
Object { Object {
"ALIAS": "user", "ALIAS": "user",
"COOKIEJAR": false,
"ENDPOINT": "http://jsonplaceholder.typicode.com", "ENDPOINT": "http://jsonplaceholder.typicode.com",
"HEADERS": Object { "HEADERS": Object {
"authentication": "hello", "authentication": "hello",
@ -212,9 +224,11 @@ Config {
"DEFAULTS", "DEFAULTS",
"ENVIRONMENT", "ENVIRONMENT",
"HOSTS", "HOSTS",
"COOKIEJAR",
], ],
"defaultConfigValues": Object { "defaultConfigValues": Object {
"CACHE": false, "CACHE": false,
"COOKIEJAR": false,
"DEFAULTS": Object {}, "DEFAULTS": Object {},
"ENDPOINT": "", "ENDPOINT": "",
"ENVIRONMENT": Object {}, "ENVIRONMENT": Object {},

View File

@ -11,7 +11,8 @@ class Config {
PLUGINS: [], PLUGINS: [],
DEFAULTS: {}, DEFAULTS: {},
ENVIRONMENT: {}, ENVIRONMENT: {},
HOSTS: [] HOSTS: [],
COOKIEJAR: false
}; };
this.configKeys = Object.keys(this.defaultConfigValues); this.configKeys = Object.keys(this.defaultConfigValues);
@ -73,6 +74,7 @@ class Config {
} }
request.REQUEST = key; request.REQUEST = key;
request.COOKIEJAR = this.COOKIEJAR;
request.ENDPOINT = settings.ENDPOINT; request.ENDPOINT = settings.ENDPOINT;
let defaults = UpperCaseKeys(settings.DEFAULTS); let defaults = UpperCaseKeys(settings.DEFAULTS);

View File

@ -23,7 +23,8 @@ class Request {
ENDPOINT, ENDPOINT,
PARAMS, PARAMS,
HEADERS, HEADERS,
FORM FORM,
COOKIEJAR
} = UpperCaseKeys(req); } = UpperCaseKeys(req);
if (!ALIAS) { if (!ALIAS) {
@ -42,6 +43,7 @@ class Request {
this.FORM = FORM; this.FORM = FORM;
this.ALIAS = ALIAS; this.ALIAS = ALIAS;
this.COOKIEJAR = COOKIEJAR;
this.DEPENDENCIES = this.findDependencies(req); this.DEPENDENCIES = this.findDependencies(req);
} }
@ -70,6 +72,7 @@ class Request {
replacementRegex, replacementRegex,
(match, g1) => !match.startsWith('\\') && matches.push(g1) (match, g1) => !match.startsWith('\\') && matches.push(g1)
); );
const deps = matches.map(m => m.split('.')[0]); const deps = matches.map(m => m.split('.')[0]);
return new Set([...set, ...deps]); return new Set([...set, ...deps]);
@ -83,6 +86,7 @@ class Request {
baseUrl: this.ENDPOINT, baseUrl: this.ENDPOINT,
uri: this.PATH, uri: this.PATH,
method: this.VERB, method: this.VERB,
jar: this.COOKIEJAR,
headers: this.HEADERS, headers: this.HEADERS,
qs: this.PARAMS, qs: this.PARAMS,

View File

@ -69,7 +69,6 @@ const replaceInObject = function(obj, fn) {
}; };
module.exports = { module.exports = {
httpVerbs,
requestRegex, requestRegex,
replacementRegex, replacementRegex,
dynamicValueRegex, dynamicValueRegex,