From 98caf81c1140ca79b7c96c9b69c919effb598a78 Mon Sep 17 00:00:00 2001 From: Taniya Amidon Date: Mon, 8 Jun 2020 13:15:26 +0100 Subject: [PATCH 1/3] return collection instead of undefined --- lib/removeEmptyObjects.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/removeEmptyObjects.js b/lib/removeEmptyObjects.js index e0f1086..0aabae6 100644 --- a/lib/removeEmptyObjects.js +++ b/lib/removeEmptyObjects.js @@ -48,7 +48,7 @@ const removeEmptyObjects = collection => { // this will remove empty objects if the child element was populated on first iteration and is now empty. return _.isEmpty(clean_object) ? null : clean_object; } - return undefined; + return collection; }; module.exports = removeEmptyObjects; From a05da627a30d8ab2271d11ab78171ccf4953403e Mon Sep 17 00:00:00 2001 From: Taniya Amidon Date: Mon, 8 Jun 2020 13:20:23 +0100 Subject: [PATCH 2/3] update exsiting test to check for arrays with sting type values --- package-lock.json | 2 +- tests/methods/removeEmptyObjects.test.js | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/package-lock.json b/package-lock.json index bd0f4f5..491093c 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "@trayio/connector-utils", - "version": "0.2.2", + "version": "0.3.0", "lockfileVersion": 1, "requires": true, "dependencies": { diff --git a/tests/methods/removeEmptyObjects.test.js b/tests/methods/removeEmptyObjects.test.js index a55d659..f8c6b46 100644 --- a/tests/methods/removeEmptyObjects.test.js +++ b/tests/methods/removeEmptyObjects.test.js @@ -8,10 +8,12 @@ describe('Helper should remove all empty objects from the payload', () => { key2: 'someval', key3: {}, key4: 'other value', + key5: ['foo', 'bar'], }), ).toEqual({ key2: 'someval', key4: 'other value', + key5: ['foo', 'bar'], }); }); From 78d18b48275b54db868dba7d2d57549fadfd35be Mon Sep 17 00:00:00 2001 From: Taniya Amidon Date: Mon, 8 Jun 2020 13:33:53 +0100 Subject: [PATCH 3/3] created new test to check bug fix --- package.json | 98 ++++++++++++------------ tests/methods/removeEmptyObjects.test.js | 12 +++ 2 files changed, 61 insertions(+), 49 deletions(-) diff --git a/package.json b/package.json index 8dc25da..7a7f48e 100644 --- a/package.json +++ b/package.json @@ -1,50 +1,50 @@ { - "name": "@trayio/connector-utils", - "version": "0.3.0", - "description": "Common utility functions used in connectors.", - "main": "lib/index.js", - "scripts": { - "coverage": "npm run test -- --coverage", - "lint": "./node_modules/.bin/eslint . --fix", - "test": "jest tests", - "test:watch": "jest tests --watch --notify" - }, - "repository": { - "type": "git", - "url": "git+https://github.com/trayio/falafel-utils.git" - }, - "keywords": [ - "falafel", - "connectors" - ], - "files": [ - "index.js", - "/lib" - ], - "author": "tray.io", - "license": "ISC", - "bugs": { - "url": "https://github.com/trayio/connector-utils/issues" - }, - "homepage": "https://github.com/trayio/connector-utils#readme", - "devDependencies": { - "@trayio/connector-test-runner": "^0.5.0", - "@trayio/falafel": "^1.26.0", - "eslint": "^6.8.0", - "eslint-config-airbnb-base": "^14.1.0", - "eslint-config-prettier": "^6.10.0", - "eslint-plugin-import": "^2.20.1", - "eslint-plugin-jest": "^23.8.2", - "eslint-plugin-jsx-a11y": "^6.2.3", - "eslint-plugin-prettier": "^3.1.2", - "eslint-plugin-promise": "^4.2.1", - "jest": "^25.1.0", - "jest-json-schema": "^2.1.0", - "jsdoc-to-markdown": "^5.0.3", - "prettier": "^1.19.1" - }, - "dependencies": { - "lodash": "~4.17.15", - "mustache": "^4.0.1" - } -} + "name": "@trayio/connector-utils", + "version": "0.3.1", + "description": "Common utility functions used in connectors.", + "main": "lib/index.js", + "scripts": { + "coverage": "npm run test -- --coverage", + "lint": "./node_modules/.bin/eslint . --fix", + "test": "jest tests", + "test:watch": "jest tests --watch --notify" + }, + "repository": { + "type": "git", + "url": "git+https://github.com/trayio/falafel-utils.git" + }, + "keywords": [ + "falafel", + "connectors" + ], + "files": [ + "index.js", + "/lib" + ], + "author": "tray.io", + "license": "ISC", + "bugs": { + "url": "https://github.com/trayio/connector-utils/issues" + }, + "homepage": "https://github.com/trayio/connector-utils#readme", + "devDependencies": { + "@trayio/connector-test-runner": "^0.5.0", + "@trayio/falafel": "^1.26.0", + "eslint": "^6.8.0", + "eslint-config-airbnb-base": "^14.1.0", + "eslint-config-prettier": "^6.10.0", + "eslint-plugin-import": "^2.20.1", + "eslint-plugin-jest": "^23.8.2", + "eslint-plugin-jsx-a11y": "^6.2.3", + "eslint-plugin-prettier": "^3.1.2", + "eslint-plugin-promise": "^4.2.1", + "jest": "^25.1.0", + "jest-json-schema": "^2.1.0", + "jsdoc-to-markdown": "^5.0.3", + "prettier": "^1.19.1" + }, + "dependencies": { + "lodash": "~4.17.15", + "mustache": "^4.0.1" + } +} \ No newline at end of file diff --git a/tests/methods/removeEmptyObjects.test.js b/tests/methods/removeEmptyObjects.test.js index f8c6b46..17814a1 100644 --- a/tests/methods/removeEmptyObjects.test.js +++ b/tests/methods/removeEmptyObjects.test.js @@ -142,4 +142,16 @@ describe('Helper should remove all empty objects from the payload', () => { }, }); }); + test('It does not remove string type values from arrays', () => { + expect( + removeEmptyObjects({ + key: ['foo', 'bar'], + key1: [], + key2: [{ foo: 'bar' }], + }), + ).toEqual({ + key: ['foo', 'bar'], + key2: [{ foo: 'bar' }], + }); + }); });