removed post transformation - completed unit tests

This commit is contained in:
Camel Aissani 2016-07-14 23:05:11 +02:00
parent 15637d53bd
commit ad83bfb020
4 changed files with 43 additions and 57 deletions

View File

@ -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;
}, '');
}
}
};

View File

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

View File

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