From fdc67759e2a6e81300c6a5a5e21339440cb7c3af Mon Sep 17 00:00:00 2001 From: shrouti1507 <60211312+shrouti1507@users.noreply.github.com> Date: Fri, 18 Oct 2024 18:29:52 +0530 Subject: [PATCH] fix: not allowing empty string or null values for mandatory fields in zoho (#3800) --- src/cdk/v2/destinations/zoho/utils.js | 6 +++++- src/cdk/v2/destinations/zoho/utils.test.js | 18 ++++++++++++++++++ 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/cdk/v2/destinations/zoho/utils.js b/src/cdk/v2/destinations/zoho/utils.js index 8b170d2b82..4f5c4e8620 100644 --- a/src/cdk/v2/destinations/zoho/utils.js +++ b/src/cdk/v2/destinations/zoho/utils.js @@ -3,6 +3,7 @@ const { getHashFromArray, isDefinedAndNotNull, ConfigurationError, + isDefinedAndNotNullAndNotEmpty, } = require('@rudderstack/integrations-lib'); const get = require('get-value'); const { getDestinationExternalIDInfoForRetl, isHttpStatusSuccess } = require('../../../../v0/util'); @@ -31,7 +32,10 @@ const deduceModuleInfo = (inputs, Config) => { function validatePresenceOfMandatoryProperties(objectName, object) { if (zohoConfig.MODULE_MANDATORY_FIELD_CONFIG.hasOwnProperty(objectName)) { const requiredFields = zohoConfig.MODULE_MANDATORY_FIELD_CONFIG[objectName]; - const missingFields = requiredFields.filter((field) => !object.hasOwnProperty(field)) || []; + const missingFields = + requiredFields.filter( + (field) => !object.hasOwnProperty(field) || !isDefinedAndNotNullAndNotEmpty(object[field]), + ) || []; return { status: missingFields.length > 0, missingField: missingFields }; } // No mandatory check performed for custom objects diff --git a/src/cdk/v2/destinations/zoho/utils.test.js b/src/cdk/v2/destinations/zoho/utils.test.js index 332a408695..5a11794ef5 100644 --- a/src/cdk/v2/destinations/zoho/utils.test.js +++ b/src/cdk/v2/destinations/zoho/utils.test.js @@ -130,6 +130,24 @@ describe('validatePresenceOfMandatoryProperties', () => { expect(() => validatePresenceOfMandatoryProperties(objectName, object)).not.toThrow(); }); + it('should return missing field if mandatory field contains empty string', () => { + const objectName = 'Leads'; + const object = { Last_Name: '' }; + + const result = validatePresenceOfMandatoryProperties(objectName, object); + + expect(result).toEqual({ missingField: ['Last_Name'], status: true }); + }); + + it('should return missing field if mandatory field contains empty null', () => { + const objectName = 'Leads'; + const object = { Last_Name: null }; + + const result = validatePresenceOfMandatoryProperties(objectName, object); + + expect(result).toEqual({ missingField: ['Last_Name'], status: true }); + }); + it('should not throw an error if the objectName is not in MODULE_MANDATORY_FIELD_CONFIG', () => { const objectName = 'CustomObject'; const object = { Some_Field: 'Some Value' };