Skip to content

Commit

Permalink
fix: 🐛 all transformers are working
Browse files Browse the repository at this point in the history
  • Loading branch information
touv committed Feb 25, 2020
1 parent 40cb42e commit 0a47731
Show file tree
Hide file tree
Showing 37 changed files with 1,113 additions and 129 deletions.
40 changes: 40 additions & 0 deletions packages/transformers/src/dollar-array.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import from from 'from';
import ezs from '../../core/src';
import statements from '.';

ezs.use(statements);

describe('$ARRAY', () => {
test('with valid parameter', (done) => {
const script = `
[$ARRAY]
field = b
[exchange]
value = omit('$origin')
`;
const input = [
{ a: 1, b: 'un deux', c: true },
{ a: 2, b: 'un trois', c: true },
{ a: 3, b: 'un quatre', c: false },
{ a: 4, b: 'un cinq', c: true },
];
const output = [];
from(input)
.pipe(ezs('delegate', { script }))
.pipe(ezs.catch())
.on('error', done)
.on('data', (chunk) => {
expect(chunk).toEqual(expect.any(Object));
output.push(chunk);
})
.on('end', () => {
expect(output.length).toBe(4);
expect(output[0].b[0]).toEqual('un deux');
expect(output[1].b[0]).toEqual('un trois');
expect(output[2].b[0]).toEqual('un quatre');
expect(output[3].b[0]).toEqual('un cinq');
done();
});
});
});
2 changes: 1 addition & 1 deletion packages/transformers/src/dollar-autogenerate-uri.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ import dollar from './dollar';
* @returns {Object}
*/
export default function $AUTOGENERATE_URI(data, feed) {
return dollar(this, data, feed, transformer);
return dollar(this, data, feed, transformer, data);
}
43 changes: 43 additions & 0 deletions packages/transformers/src/dollar-autogenerate-uri.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import from from 'from';
import ezs from '../../core/src';
import statements from '.';

ezs.use(statements);

describe('$AUTOGENERATE_URI', () => {
test('with valid parameter', (done) => {
const script = `
[$AUTOGENERATE_URI]
field = d
naan = 12345
subpublisher = WXZ
uriSize = 8
[exchange]
value = omit('$origin')
`;
const input = [
{ a: '1', b: 'un', c: true },
{ a: '2', b: 'deux', c: true },
{ a: '3', b: 'trois', c: false },
{ a: '4', b: 'quatre', c: true },
];
const output = [];
from(input)
.pipe(ezs('delegate', { script }))
.pipe(ezs.catch())
.on('error', done)
.on('data', (chunk) => {
expect(chunk).toEqual(expect.any(Object));
output.push(chunk);
})
.on('end', () => {
expect(output.length).toBe(4);
expect(output[0].d).not.toBeNull();
expect(output[1].d).not.toEqual();
expect(output[2].d).not.toEqual();
expect(output[3].d).not.toEqual();
done();
});
});
});
40 changes: 40 additions & 0 deletions packages/transformers/src/dollar-boolean.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import from from 'from';
import ezs from '../../core/src';
import statements from '.';

ezs.use(statements);

describe('$BOOLEAN', () => {
test('with valid parameter', (done) => {
const script = `
[$BOOLEAN]
field = c
[exchange]
value = omit('$origin')
`;
const input = [
{ a: 1, b: 'un deux', c: 'true' },
{ a: 2, b: 'un trois', c: true },
{ a: 3, b: 'un quatre', c: 1 },
{ a: 4, b: 'un cinq', c: 'OK' },
];
const output = [];
from(input)
.pipe(ezs('delegate', { script }))
.pipe(ezs.catch())
.on('error', done)
.on('data', (chunk) => {
expect(chunk).toEqual(expect.any(Object));
output.push(chunk);
})
.on('end', () => {
expect(output.length).toBe(4);
expect(output[0].c).toEqual(true);
expect(output[1].c).toEqual(true);
expect(output[2].c).toEqual(true);
expect(output[3].c).toEqual(true);
done();
});
});
});
40 changes: 40 additions & 0 deletions packages/transformers/src/dollar-capitalize.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
import from from 'from';
import ezs from '../../core/src';
import statements from '.';

ezs.use(statements);

describe('$CAPITALIZE', () => {
test('with valid parameter', (done) => {
const script = `
[$CAPITALIZE]
field= b
[exchange]
value = omit('$origin')
`;
const input = [
{ a: 1, b: 'un deux', c: true },
{ a: 2, b: 'un trois', c: true },
{ a: 3, b: 'un quatre', c: false },
{ a: 4, b: 'un cinq', c: true },
];
const output = [];
from(input)
.pipe(ezs('delegate', { script }))
.pipe(ezs.catch())
.on('error', done)
.on('data', (chunk) => {
expect(chunk).toEqual(expect.any(Object));
output.push(chunk);
})
.on('end', () => {
expect(output.length).toBe(4);
expect(output[0].b).toEqual('Un deux');
expect(output[1].b).toEqual('Un trois');
expect(output[2].b).toEqual('Un quatre');
expect(output[3].b).toEqual('Un cinq');
done();
});
});
});
2 changes: 1 addition & 1 deletion packages/transformers/src/dollar-column.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ import dollar from './dollar';
* @returns {Object}
*/
export default function $COLUMN(data, feed) {
return dollar(this, data, feed, transformer);
return dollar(this, data, feed, transformer, data);
}
41 changes: 41 additions & 0 deletions packages/transformers/src/dollar-column.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import from from 'from';
import ezs from '../../core/src';
import statements from '.';

ezs.use(statements);

describe('$COLUMN', () => {
test('with valid parameter', (done) => {
const script = `
[$COLUMN]
field = d
column = b
[exchange]
value = omit('$origin')
`;
const input = [
{ a: '1', b: 'un', c: true },
{ a: '2', b: 'deux', c: true },
{ a: '3', b: 'trois', c: false },
{ a: '4', b: 'quatre', c: true },
];
const output = [];
from(input)
.pipe(ezs('delegate', { script }))
.pipe(ezs.catch())
.on('error', done)
.on('data', (chunk) => {
expect(chunk).toEqual(expect.any(Object));
output.push(chunk);
})
.on('end', () => {
expect(output.length).toBe(4);
expect(output[0].d).toEqual('un');
expect(output[1].d).toEqual('deux');
expect(output[2].d).toEqual('trois');
expect(output[3].d).toEqual('quatre');
done();
});
});
});
2 changes: 1 addition & 1 deletion packages/transformers/src/dollar-concat-uri.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ import dollar from './dollar';
* @returns {Object}
*/
export default function $CONCAT_URI(data, feed) {
return dollar(this, data, feed, transformer);
return dollar(this, data, feed, transformer, data);
}
43 changes: 43 additions & 0 deletions packages/transformers/src/dollar-concat-uri.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import from from 'from';
import ezs from '../../core/src';
import statements from '.';

ezs.use(statements);

describe('$CONCAT_URI', () => {
test('with valid parameter', (done) => {
const script = `
[$CONCAT_URI]
field = d
column = a
column = b
separator = %
[exchange]
value = omit('$origin')
`;
const input = [
{ a: '1', b: 'un', c: true },
{ a: '2', b: 'deux', c: true },
{ a: '3', b: 'trois', c: false },
{ a: '4', b: 'quatre', c: true },
];
const output = [];
from(input)
.pipe(ezs('delegate', { script }))
.pipe(ezs.catch())
.on('error', done)
.on('data', (chunk) => {
expect(chunk).toEqual(expect.any(Object));
output.push(chunk);
})
.on('end', () => {
expect(output.length).toBe(4);
expect(output[0].d).toEqual('1%un');
expect(output[1].d).toEqual('2%deux');
expect(output[2].d).toEqual('3%trois');
expect(output[3].d).toEqual('4%quatre');
done();
});
});
});
2 changes: 1 addition & 1 deletion packages/transformers/src/dollar-concat.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ import dollar from './dollar';
* @returns {Object}
*/
export default function $CONCAT(data, feed) {
return dollar(this, data, feed, transformer);
return dollar(this, data, feed, transformer, data);
}
46 changes: 46 additions & 0 deletions packages/transformers/src/dollar-concat.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import from from 'from';
import ezs from '../../core/src';
import statements from '.';

ezs.use(statements);

describe('$CONCAT', () => {
test('with valid parameter', (done) => {
const script = `
[$CONCAT]
field = d
columns = a
columns = b
[exchange]
value = omit('$origin')
`;
const input = [
{ a: '1', b: 'un', c: true },
{ a: '2', b: 'deux', c: true },
{ a: '3', b: 'trois', c: false },
{ a: '4', b: 'quatre', c: true },
];
const output = [];
from(input)
.pipe(ezs('delegate', { script }))
.pipe(ezs.catch())
.on('error', done)
.on('data', (chunk) => {
expect(chunk).toEqual(expect.any(Object));
output.push(chunk);
})
.on('end', () => {
expect(output.length).toBe(4);
expect(output[0].d[0]).toEqual('1');
expect(output[0].d[1]).toEqual('un');
expect(output[1].d[0]).toEqual('2');
expect(output[1].d[1]).toEqual('deux');
expect(output[2].d[0]).toEqual('3');
expect(output[2].d[1]).toEqual('trois');
expect(output[3].d[0]).toEqual('4');
expect(output[3].d[1]).toEqual('quatre');
done();
});
});
});
41 changes: 41 additions & 0 deletions packages/transformers/src/dollar-default.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import from from 'from';
import ezs from '../../core/src';
import statements from '.';

ezs.use(statements);

describe('$DEFAULT', () => {
test('with valid parameter', (done) => {
const script = `
[$DEFAULT]
field = b
alternative = un quatre
[exchange]
value = omit('$origin')
`;
const input = [
{ a: 1, b: 'un deux', c: true },
{ a: 2, b: 'un trois', c: true },
{ a: 3, b: null, c: false },
{ a: 4, b: 'un cinq', c: true },
];
const output = [];
from(input)
.pipe(ezs('delegate', { script }))
.pipe(ezs.catch())
.on('error', done)
.on('data', (chunk) => {
expect(chunk).toEqual(expect.any(Object));
output.push(chunk);
})
.on('end', () => {
expect(output.length).toBe(4);
expect(output[0].b).toEqual('un deux');
expect(output[1].b).toEqual('un trois');
expect(output[2].b).toEqual('un quatre');
expect(output[3].b).toEqual('un cinq');
done();
});
});
});
Loading

0 comments on commit 0a47731

Please sign in to comment.