mirror of
https://gitlab.silvrtree.co.uk/martind2000/frontexpress.git
synced 2025-01-25 18:46:17 +00:00
removed post transformation - completed unit tests
This commit is contained in:
parent
15637d53bd
commit
ad83bfb020
@ -35,32 +35,6 @@ export default class {
|
||||
data({uri, headers, data}) {
|
||||
return undefined;
|
||||
}
|
||||
},
|
||||
|
||||
'http POST transformer': {
|
||||
headers({uri, headers, data}) {
|
||||
const postHeaders = {};
|
||||
postHeaders['Content-type'] = 'application/x-www-form-urlencoded';
|
||||
if (headers) {
|
||||
Object.keys(headers).reduce((phds, headKey) => {
|
||||
phds[headKey] = headers[headKey];
|
||||
return phds;
|
||||
}, postHeaders);
|
||||
}
|
||||
return postHeaders;
|
||||
},
|
||||
data({uri, headers, data}) {
|
||||
if (!data) {
|
||||
return data;
|
||||
}
|
||||
return Object.keys(data).reduce((newData, d, index) => {
|
||||
if (index !== 0) {
|
||||
newData += '&';
|
||||
}
|
||||
newData += `${d}=${data[d]}`;
|
||||
return newData;
|
||||
}, '');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -1,31 +0,0 @@
|
||||
/*eslint-env mocha*/
|
||||
import {assert} from 'chai';
|
||||
import Settings from '../lib/settings';
|
||||
|
||||
describe('HTTP_METHODS', () => {
|
||||
const settings = new Settings();
|
||||
|
||||
it('GET method simple uri', () => {
|
||||
const uriFn = settings.get('http GET transformer').uri;
|
||||
const dataFn = settings.get('http GET transformer').data;
|
||||
|
||||
assert(uriFn({uri: '/route', data:{a:'b', c:'d'}}) === '/route?a=b&c=d');
|
||||
assert(dataFn({uri: '/route', data:{a:'b', c:'d'}}) === undefined);
|
||||
});
|
||||
|
||||
it('GET method uri with query string', () => {
|
||||
const uriFn = settings.get('http GET transformer').uri;
|
||||
const dataFn = settings.get('http GET transformer').data;
|
||||
|
||||
assert(uriFn({uri: '/route?x=y&z=a', data:{a:'b', c:'d'}}) === '/route?x=y&z=a&a=b&c=d');
|
||||
assert(dataFn({uri: '/route?x=y&z=a', data:{a:'b', c:'d'}}) === undefined);
|
||||
});
|
||||
|
||||
it('GET method uri with query string and anchor', () => {
|
||||
const uriFn = settings.get('http GET transformer').uri;
|
||||
const dataFn = settings.get('http GET transformer').data;
|
||||
|
||||
assert(uriFn({uri: '/route?x=y&z=a#anchor1', data:{a:'b', c:'d'}}) === '/route?x=y&z=a&a=b&c=d#anchor1');
|
||||
assert(dataFn({uri: '/route?x=y&z=a#anchor1', data:{a:'b', c:'d'}}) === undefined);
|
||||
});
|
||||
});
|
@ -17,6 +17,16 @@ describe('Router', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('use method', () => {
|
||||
const router = frontexpress.Router();
|
||||
chai.expect(() => {
|
||||
router.use();
|
||||
}).to.throw(TypeError);
|
||||
chai.expect(() => {
|
||||
router.use('dddd');
|
||||
}).to.throw(TypeError);
|
||||
});
|
||||
|
||||
describe('visited method', () => {
|
||||
it('get visited route', ()=> {
|
||||
const router = frontexpress.Router();
|
||||
|
33
test/settings-test.js
Normal file
33
test/settings-test.js
Normal file
@ -0,0 +1,33 @@
|
||||
/*eslint-env mocha*/
|
||||
import {assert} from 'chai';
|
||||
import Settings from '../lib/settings';
|
||||
|
||||
describe('Settings', () => {
|
||||
const settings = new Settings();
|
||||
|
||||
describe('http GET method transformer', () => {
|
||||
it('simple uri', () => {
|
||||
const uriFn = settings.get('http GET transformer').uri;
|
||||
const dataFn = settings.get('http GET transformer').data;
|
||||
|
||||
assert(uriFn({uri: '/route', data:{a:'b', c:'d'}}) === '/route?a=b&c=d');
|
||||
assert(dataFn({uri: '/route', data:{a:'b', c:'d'}}) === undefined);
|
||||
});
|
||||
|
||||
it('uri with query string', () => {
|
||||
const uriFn = settings.get('http GET transformer').uri;
|
||||
const dataFn = settings.get('http GET transformer').data;
|
||||
|
||||
assert(uriFn({uri: '/route?x=y&z=a', data:{a:'b', c:'d'}}) === '/route?x=y&z=a&a=b&c=d');
|
||||
assert(dataFn({uri: '/route?x=y&z=a', data:{a:'b', c:'d'}}) === undefined);
|
||||
});
|
||||
|
||||
it('uri with query string and anchor', () => {
|
||||
const uriFn = settings.get('http GET transformer').uri;
|
||||
const dataFn = settings.get('http GET transformer').data;
|
||||
|
||||
assert(uriFn({uri: '/route?x=y&z=a#anchor1', data:{a:'b', c:'d'}}) === '/route?x=y&z=a&a=b&c=d#anchor1');
|
||||
assert(dataFn({uri: '/route?x=y&z=a#anchor1', data:{a:'b', c:'d'}}) === undefined);
|
||||
});
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue
Block a user