Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: not allowing empty string or null values for mandatory fields in zoho #3800

Merged
merged 1 commit into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
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 @@
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]),
) || [];

Check warning on line 38 in src/cdk/v2/destinations/zoho/utils.js

View check run for this annotation

Codecov / codecov/patch

src/cdk/v2/destinations/zoho/utils.js#L38

Added line #L38 was not covered by tests
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
Loading