Skip to content

Commit

Permalink
feat: 🎸 fix exampn for empty arrayx
Browse files Browse the repository at this point in the history
  • Loading branch information
touv committed Jun 16, 2021
1 parent 9f39096 commit 8af4b92
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 2 deletions.
4 changes: 2 additions & 2 deletions packages/analytics/src/expand.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ async function mergeWith(data, feed) {
* @param {String} [script] the external pipeline is described in a string of characters
* @param {String} [commands] the external pipeline is described in a object
* @param {String} [command] the external pipeline is described in a URL-like command
* @param {String} [cache] Use a specific ezs statement to run commands (advanced)
* @param {String} [cache] Use a specific ezs statement to run commands (experimental)
* @returns {Object}
*/
export default async function expand(data, feed) {
Expand Down Expand Up @@ -124,7 +124,7 @@ export default async function expand(data, feed) {
}

const value = get(data, path);
if (value === undefined) {
if (!value || value.length === 0) {
return feed.send(data);
}
const id = this.getIndex().toString().padStart(20, '0');
Expand Down
37 changes: 37 additions & 0 deletions packages/analytics/test/expand.js
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,43 @@ test('with no path', (done) => {
done();
});
});
test.only('with no value #1', (done) => {
ezs.use(statements);
const input = [
{ a: 1, b: [] },
{ a: 2, b: 'b' },
{ a: 3, b: false },
{ a: 4, b: 0 },
{ a: 5, b: null },
{ a: 6, b: undefined },
];
const output = [];
const script = `
[use]
plugin = analytics
[assign]
path = value
value = get('value').toUpper()
`;
from(input)
.pipe(ezs('expand', { path: 'b', script }))
.pipe(ezs.catch())
.on('error', done)
.on('data', (chunk) => {
output.push(chunk);
})
.on('end', () => {
expect(output.length).toEqual(6);
expect(output[0].b).toEqual([]);
expect(output[1].b).toEqual('B');
expect(output[2].b).toEqual(false);
expect(output[3].b).toEqual(0);
expect(output[4].b).toEqual(null);
expect(output[5].b).toEqual(undefined);
done();
});
});
test('with bad path', (done) => {
ezs.use(statements);
const input = [
Expand Down

0 comments on commit 8af4b92

Please sign in to comment.