Skip to content

Commit

Permalink
fix: not allowing empty string or null values for mandatory fields in…
Browse files Browse the repository at this point in the history
… zoho (#3800)
  • Loading branch information
shrouti1507 authored Oct 18, 2024
1 parent d730daf commit fcd8d99
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/cdk/v2/destinations/zoho/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const {
getHashFromArray,
isDefinedAndNotNull,
ConfigurationError,
isDefinedAndNotNullAndNotEmpty,
} = require('@rudderstack/integrations-lib');
const get = require('get-value');
const { getDestinationExternalIDInfoForRetl, isHttpStatusSuccess } = require('../../../../v0/util');
Expand Down Expand Up @@ -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
Expand Down
18 changes: 18 additions & 0 deletions src/cdk/v2/destinations/zoho/utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' };
Expand Down

0 comments on commit fcd8d99

Please sign in to comment.